Skip to content

Commit ece03f9

Browse files
Merge pull request #20782 from nicolo-ribaudo/license-header-lint
Add script to check license headers
2 parents 68cca32 + 2f2d5c9 commit ece03f9

9 files changed

Lines changed: 100 additions & 16 deletions

File tree

gulpfile.mjs

Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2041,6 +2041,82 @@ gulp.task(
20412041
)
20422042
);
20432043

2044+
gulp.task("lint-licenses", function (done) {
2045+
console.log("\n### Checking license headers");
2046+
2047+
const jsRE =
2048+
/^(?:#[^\n]*\n)?\/\* Copyright \d{4} Mozilla Foundation\n \*\n \* Licensed under the Apache License, Version 2\.0 \(the "License"\);/;
2049+
const htmlRE = /^<!doctype html>\n<!--\nCopyright \d{4} Mozilla Foundation\n/;
2050+
2051+
// Files with non-standard license headers (different copyright holder,
2052+
// different license, or missing license).
2053+
const NON_STANDARD_HEADER_FILES = new Set([
2054+
"examples/learning/helloworld.html",
2055+
"examples/learning/helloworld64.html",
2056+
"examples/learning/prevnext.html",
2057+
"examples/node/getinfo.mjs",
2058+
"examples/text-only/index.html",
2059+
"examples/webpack/index.html",
2060+
"examples/webpack/main.mjs",
2061+
"examples/webpack/webpack.config.js",
2062+
"test/add_test.mjs",
2063+
"src/license_header_libre.js",
2064+
"src/shared/murmurhash3.js",
2065+
"test/font/font_core_spec.js",
2066+
"test/font/font_fpgm_spec.js",
2067+
"test/font/font_os2_spec.js",
2068+
"test/font/font_post_spec.js",
2069+
"test/reporter.js",
2070+
"test/resources/reftest-analyzer.css",
2071+
"test/resources/reftest-analyzer.js",
2072+
"test/stats/statcmp.js",
2073+
"web/grab_to_pan.js",
2074+
"web/toggle_button.css",
2075+
]);
2076+
2077+
const errors = [];
2078+
2079+
gulp
2080+
.src(
2081+
[
2082+
"{src,web,test,examples}/**/*.{js,mjs,css}",
2083+
"examples/**/*.html",
2084+
"!web/wasm/**/*",
2085+
],
2086+
{
2087+
base: ".",
2088+
}
2089+
)
2090+
.on("data", function (file) {
2091+
const relativePath = file.relative;
2092+
const content = file.contents.toString();
2093+
const re = relativePath.endsWith(".html") ? htmlRE : jsRE;
2094+
2095+
if (NON_STANDARD_HEADER_FILES.has(relativePath)) {
2096+
if (re.test(content)) {
2097+
console.warn(
2098+
` ${relativePath} has a standard license header, but is in the list of non-standard header files list.`
2099+
);
2100+
}
2101+
return;
2102+
}
2103+
if (!re.test(content)) {
2104+
errors.push(relativePath);
2105+
}
2106+
})
2107+
.on("end", function () {
2108+
if (errors.length > 0) {
2109+
for (const file of errors.sort()) {
2110+
console.log(` Invalid license header: ${file}`);
2111+
}
2112+
done(new Error("License header check failed."));
2113+
return;
2114+
}
2115+
console.log("files checked, no errors found");
2116+
done();
2117+
});
2118+
});
2119+
20442120
gulp.task("lint", function (done) {
20452121
console.log("\n### Linting JS/CSS/JSON/SVG/HTML files");
20462122

@@ -2111,8 +2187,7 @@ gulp.task("lint", function (done) {
21112187
return;
21122188
}
21132189

2114-
console.log("files checked, no errors found");
2115-
done();
2190+
gulp.task("lint-licenses")(done);
21162191
});
21172192
});
21182193
});

src/core/jpg.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/* Copyright 2014 Mozilla Foundation
22
*
3-
* Licensed under the Apache License, Version 2.0 (the 'License');
3+
* Licensed under the Apache License, Version 2.0 (the "License");
44
* you may not use this file except in compliance with the License.
55
* You may obtain a copy of the License at
66
*
77
* http://www.apache.org/licenses/LICENSE-2.0
88
*
99
* Unless required by applicable law or agreed to in writing, software
10-
* distributed under the License is distributed on an 'AS IS' BASIS,
10+
* distributed under the License is distributed on an "AS IS" BASIS,
1111
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
* See the License for the specific language governing permissions and
1313
* limitations under the License.

test/downloadutils.mjs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
/*
2-
* Copyright 2014 Mozilla Foundation
1+
/* Copyright 2014 Mozilla Foundation
32
*
43
* Licensed under the Apache License, Version 2.0 (the "License");
54
* you may not use this file except in compliance with the License.

test/font/fontutils.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
/*
2-
* Copyright 2013 Mozilla Foundation
1+
/* Copyright 2013 Mozilla Foundation
32
*
43
* Licensed under the Apache License, Version 2.0 (the "License");
54
* you may not use this file except in compliance with the License.

test/font/ttxdriver.mjs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
/*
2-
* Copyright 2014 Mozilla Foundation
1+
/* Copyright 2014 Mozilla Foundation
32
*
43
* Licensed under the Apache License, Version 2.0 (the "License");
54
* you may not use this file except in compliance with the License.

test/integration/thumbnail_view_spec.mjs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/* Copyright 2026 Mozilla Foundation
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
116
import {
217
awaitPromise,
318
closePages,

test/test.mjs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
/*
2-
* Copyright 2014 Mozilla Foundation
1+
/* Copyright 2014 Mozilla Foundation
32
*
43
* Licensed under the Apache License, Version 2.0 (the "License");
54
* you may not use this file except in compliance with the License.

test/testutils.mjs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
/*
2-
* Copyright 2014 Mozilla Foundation
1+
/* Copyright 2014 Mozilla Foundation
32
*
43
* Licensed under the Apache License, Version 2.0 (the "License");
54
* you may not use this file except in compliance with the License.

test/webserver.mjs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
/*
2-
* Copyright 2014 Mozilla Foundation
1+
/* Copyright 2014 Mozilla Foundation
32
*
43
* Licensed under the Apache License, Version 2.0 (the "License");
54
* you may not use this file except in compliance with the License.

0 commit comments

Comments
 (0)