Add script to check license headers

This commit is contained in:
Nicolò Ribaudo 2026-03-03 11:21:29 +01:00
parent 68cca32e20
commit 2f2d5c9e27
No known key found for this signature in database
GPG Key ID: AAFDA9101C58F338
9 changed files with 100 additions and 16 deletions

View File

@ -2041,6 +2041,82 @@ gulp.task(
)
);
gulp.task("lint-licenses", function (done) {
console.log("\n### Checking license headers");
const jsRE =
/^(?:#[^\n]*\n)?\/\* Copyright \d{4} Mozilla Foundation\n \*\n \* Licensed under the Apache License, Version 2\.0 \(the "License"\);/;
const htmlRE = /^<!doctype html>\n<!--\nCopyright \d{4} Mozilla Foundation\n/;
// Files with non-standard license headers (different copyright holder,
// different license, or missing license).
const NON_STANDARD_HEADER_FILES = new Set([
"examples/learning/helloworld.html",
"examples/learning/helloworld64.html",
"examples/learning/prevnext.html",
"examples/node/getinfo.mjs",
"examples/text-only/index.html",
"examples/webpack/index.html",
"examples/webpack/main.mjs",
"examples/webpack/webpack.config.js",
"test/add_test.mjs",
"src/license_header_libre.js",
"src/shared/murmurhash3.js",
"test/font/font_core_spec.js",
"test/font/font_fpgm_spec.js",
"test/font/font_os2_spec.js",
"test/font/font_post_spec.js",
"test/reporter.js",
"test/resources/reftest-analyzer.css",
"test/resources/reftest-analyzer.js",
"test/stats/statcmp.js",
"web/grab_to_pan.js",
"web/toggle_button.css",
]);
const errors = [];
gulp
.src(
[
"{src,web,test,examples}/**/*.{js,mjs,css}",
"examples/**/*.html",
"!web/wasm/**/*",
],
{
base: ".",
}
)
.on("data", function (file) {
const relativePath = file.relative;
const content = file.contents.toString();
const re = relativePath.endsWith(".html") ? htmlRE : jsRE;
if (NON_STANDARD_HEADER_FILES.has(relativePath)) {
if (re.test(content)) {
console.warn(
` ${relativePath} has a standard license header, but is in the list of non-standard header files list.`
);
}
return;
}
if (!re.test(content)) {
errors.push(relativePath);
}
})
.on("end", function () {
if (errors.length > 0) {
for (const file of errors.sort()) {
console.log(` Invalid license header: ${file}`);
}
done(new Error("License header check failed."));
return;
}
console.log("files checked, no errors found");
done();
});
});
gulp.task("lint", function (done) {
console.log("\n### Linting JS/CSS/JSON/SVG/HTML files");
@ -2111,8 +2187,7 @@ gulp.task("lint", function (done) {
return;
}
console.log("files checked, no errors found");
done();
gulp.task("lint-licenses")(done);
});
});
});

View File

@ -1,13 +1,13 @@
/* Copyright 2014 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the 'License');
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.

View File

@ -1,5 +1,4 @@
/*
* Copyright 2014 Mozilla Foundation
/* Copyright 2014 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,4 @@
/*
* Copyright 2013 Mozilla Foundation
/* Copyright 2013 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,4 @@
/*
* Copyright 2014 Mozilla Foundation
/* Copyright 2014 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,3 +1,18 @@
/* Copyright 2026 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
awaitPromise,
closePages,

View File

@ -1,5 +1,4 @@
/*
* Copyright 2014 Mozilla Foundation
/* Copyright 2014 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,4 @@
/*
* Copyright 2014 Mozilla Foundation
/* Copyright 2014 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,4 @@
/*
* Copyright 2014 Mozilla Foundation
/* Copyright 2014 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.