@@ -6,6 +6,7 @@ var glob = require('glob');
6
6
var madge = require ( 'madge' ) ;
7
7
var readLastLines = require ( 'read-last-lines' ) ;
8
8
var eslint = require ( 'eslint' ) ;
9
+ var trueCasePath = require ( 'true-case-path' ) ;
9
10
10
11
var constants = require ( './util/constants' ) ;
11
12
var srcGlob = path . join ( constants . pathToSrc , '**/*.js' ) ;
@@ -55,6 +56,8 @@ function assertJasmineSuites() {
55
56
* - check for header comment
56
57
* - check that we don't have any features that break in IE
57
58
* - 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
58
61
*/
59
62
function assertSrcContents ( ) {
60
63
var licenseSrc = constants . licenseSrc ;
@@ -70,6 +73,9 @@ function assertSrcContents() {
70
73
// Forbidden in IE in any context
71
74
var IE_BLACK_LIST = [ 'classList' ] ;
72
75
76
+ // require'd built-in modules
77
+ var BUILTINS = [ 'events' ] ;
78
+
73
79
var getComputedStyleCnt = 0 ;
74
80
75
81
glob ( combineGlobs ( [ srcGlob , libGlob ] ) , function ( err , files ) {
@@ -100,7 +106,28 @@ function assertSrcContents() {
100
106
}
101
107
else if ( node . type === 'Identifier' && node . source ( ) === 'getComputedStyle' ) {
102
108
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
+ }
104
131
}
105
132
}
106
133
} ) ;
0 commit comments