@@ -14,52 +14,56 @@ import values from 'object.values';
14
14
import includes from 'array-includes' ;
15
15
import tryCatch from 'try-catch' ;
16
16
17
+ let listFilesToProcess ;
18
+
17
19
const [ , eslint8 ] = tryCatch ( require , 'eslint/use-at-your-own-risk' ) ;
20
+ // has been moved to eslint/lib/cli-engine/file-enumerator in version 6
18
21
const [ , eslint7 ] = tryCatch ( require , 'eslint/lib/cli-engine/file-enumerator' ) ;
22
+ // eslint/lib/util/glob-util has been moved to eslint/lib/util/glob-utils with version 5.3
19
23
const [ , eslint6 ] = tryCatch ( require , 'eslint/lib/util/glob-utils' ) ;
20
24
const [ , eslint5 ] = tryCatch ( require , 'eslint/lib/util/glob-util' ) ;
21
25
22
26
const modernESLint = eslint8 || eslint7 ;
23
27
24
28
if ( modernESLint ) {
25
- // eslint/lib/util/glob-util has been moved to eslint/lib/util/glob-utils with version 5.3
26
- // and has been moved to eslint/lib/cli-engine/file-enumerator in version 6
27
- const { FileEnumerator} = modernESLint ;
29
+ const { FileEnumerator } = modernESLint ;
28
30
29
- listFilesToProcess = function ( src , extensions ) {
30
- const e = new FileEnumerator ( {
31
- extensions : extensions ,
32
- } ) ;
31
+ listFilesToProcess = function ( src , extensions ) {
32
+ const e = new FileEnumerator ( {
33
+ extensions : extensions ,
34
+ } ) ;
33
35
34
- return Array . from ( e . iterateFiles ( src ) , ( { filePath, ignored } ) => ( {
35
- ignored,
36
- filename : filePath ,
37
- } ) ) ;
36
+ return Array . from ( e . iterateFiles ( src ) , ( { filePath, ignored } ) => ( {
37
+ ignored,
38
+ filename : filePath ,
39
+ } ) ) ;
40
+ } ;
41
+ }
42
+
43
+ // Prevent passing invalid options (extensions array) to old versions of the function.
44
+ // https://github.com/eslint/eslint/blob/v5.16.0/lib/util/glob-utils.js#L178-L280
45
+ // https://github.com/eslint/eslint/blob/v5.2.0/lib/util/glob-util.js#L174-L269
46
+ if ( eslint6 ) {
47
+ const originalListFilesToProcess = eslint6 . listFilesToProcess ;
48
+ listFilesToProcess = function ( src , extensions ) {
49
+ return originalListFilesToProcess ( src , {
50
+ extensions : extensions ,
51
+ } ) ;
38
52
} ;
39
53
}
40
-
41
- if ( eslin6 ) {
42
- originalListFilesToProcess = eslin6 . listFilesToProcess ;
43
- listFilesToProcess = function ( src , extensions ) {
44
- return originalListFilesToProcess ( src , {
45
- extensions : extensions ,
46
- } ) ;
47
- } ;
48
- }
49
-
50
- if ( eslin5 ) {
51
- originalListFilesToProcess = eslint5 . listFilesToProcess ;
52
54
53
- listFilesToProcess = function ( src , extensions ) {
54
- const patterns = src . reduce ( ( carry , pattern ) => {
55
- return carry . concat ( extensions . map ( ( extension ) => {
56
- return / \* \* | \* \. / . test ( pattern ) ? pattern : `${ pattern } /**/*${ extension } ` ;
57
- } ) ) ;
58
- } , src . slice ( ) ) ;
55
+ if ( eslint5 ) {
56
+ const originalListFilesToProcess = eslint5 . listFilesToProcess ;
59
57
60
- return originalListFilesToProcess ( patterns ) ;
61
- } ;
62
- }
58
+ listFilesToProcess = function ( src , extensions ) {
59
+ const patterns = src . reduce ( ( carry , pattern ) => {
60
+ return carry . concat ( extensions . map ( ( extension ) => {
61
+ return / \* \* | \* \. / . test ( pattern ) ? pattern : `${ pattern } /**/*${ extension } ` ;
62
+ } ) ) ;
63
+ } , src . slice ( ) ) ;
64
+
65
+ return originalListFilesToProcess ( patterns ) ;
66
+ } ;
63
67
}
64
68
65
69
const EXPORT_DEFAULT_DECLARATION = 'ExportDefaultDeclaration' ;
@@ -236,7 +240,7 @@ const prepareImportsAndExports = (srcFiles, context) => {
236
240
}
237
241
const localImport = imports . get ( key ) || new Set ( ) ;
238
242
value . declarations . forEach ( ( { importedSpecifiers } ) =>
239
- importedSpecifiers . forEach ( specifier => localImport . add ( specifier ) )
243
+ importedSpecifiers . forEach ( specifier => localImport . add ( specifier ) ) ,
240
244
) ;
241
245
imports . set ( key , localImport ) ;
242
246
} ) ;
@@ -552,13 +556,13 @@ module.exports = {
552
556
if ( exportStatement . whereUsed . size < 1 ) {
553
557
context . report (
554
558
node ,
555
- `exported declaration '${ value } ' not used within other modules`
559
+ `exported declaration '${ value } ' not used within other modules` ,
556
560
) ;
557
561
}
558
562
} else {
559
563
context . report (
560
564
node ,
561
- `exported declaration '${ value } ' not used within other modules`
565
+ `exported declaration '${ value } ' not used within other modules` ,
562
566
) ;
563
567
}
564
568
} ;
0 commit comments