@@ -6,6 +6,7 @@ var glob = require('glob');
66var madge = require ( 'madge' ) ;
77var readLastLines = require ( 'read-last-lines' ) ;
88var eslint = require ( 'eslint' ) ;
9+ var trueCasePath = require ( 'true-case-path' ) ;
910
1011var constants = require ( './util/constants' ) ;
1112var srcGlob = path . join ( constants . pathToSrc , '**/*.js' ) ;
@@ -55,6 +56,8 @@ function assertJasmineSuites() {
5556 * - check for header comment
5657 * - check that we don't have any features that break in IE
5758 * - check that we don't use getComputedStyle unexpectedly
59+ * - check that require statements use lowercase (to match assertFileNames)
60+ * or match the case of the source file
5861 */
5962function assertSrcContents ( ) {
6063 var licenseSrc = constants . licenseSrc ;
@@ -70,6 +73,9 @@ function assertSrcContents() {
7073 // Forbidden in IE in any context
7174 var IE_BLACK_LIST = [ 'classList' ] ;
7275
76+ // require'd built-in modules
77+ var BUILTINS = [ 'events' ] ;
78+
7379 var getComputedStyleCnt = 0 ;
7480
7581 glob ( combineGlobs ( [ srcGlob , libGlob ] ) , function ( err , files ) {
@@ -100,7 +106,28 @@ function assertSrcContents() {
100106 }
101107 else if ( node . type === 'Identifier' && node . source ( ) === 'getComputedStyle' ) {
102108 if ( node . parent . source ( ) !== 'window.getComputedStyle' ) {
103- logs . push ( file + ': getComputedStyle must be called as a `window` property.' ) ;
109+ logs . push ( file + ' : getComputedStyle must be called as a `window` property.' ) ;
110+ }
111+ }
112+ else if ( node . type === 'CallExpression' && node . callee . name === 'require' ) {
113+ var pathNode = node . arguments [ 0 ] ;
114+ var pathStr = pathNode . value ;
115+ if ( pathNode . type !== 'Literal' ) {
116+ logs . push ( file + ' : You may only `require` literals.' ) ;
117+ }
118+ else if ( BUILTINS . indexOf ( pathStr ) === - 1 ) {
119+ // node version 8.9.0+ can use require.resolve(request, {paths: [...]})
120+ // and avoid this explicit conversion to the current location
121+ if ( pathStr . charAt ( 0 ) === '.' ) {
122+ pathStr = path . relative ( __dirname , path . join ( path . dirname ( file ) , pathStr ) ) ;
123+ }
124+ var fullPath = require . resolve ( pathStr ) ;
125+ var casedPath = trueCasePath ( fullPath ) ;
126+
127+ if ( fullPath !== trueCasePath ( fullPath ) ) {
128+ logs . push ( file + ' : `require` path is not case-correct:\n' +
129+ fullPath + ' -> ' + casedPath ) ;
130+ }
104131 }
105132 }
106133 } ) ;
0 commit comments