@@ -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 ) ? \/ \* C o p y r i g h t \d { 4 } M o z i l l a F o u n d a t i o n \n \* \n \* L i c e n s e d u n d e r t h e A p a c h e L i c e n s e , V e r s i o n 2 \. 0 \( t h e " L i c e n s e " \) ; / ;
2049+ const htmlRE = / ^ < ! d o c t y p e h t m l > \n < ! - - \n C o p y r i g h t \d { 4 } M o z i l l a F o u n d a t i o n \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+
20442120gulp . 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 } ) ;
0 commit comments