4
4
* @author René Fermann
5
5
*/
6
6
7
- import * as fsWalk from '@nodelib/fs.walk ' ;
7
+ import * as fsWalk from '../core/fsWalk ' ;
8
8
import { getFileExtensions } from 'eslint-module-utils/ignore' ;
9
9
import resolve from 'eslint-module-utils/resolve' ;
10
10
import visit from 'eslint-module-utils/visit' ;
@@ -44,8 +44,8 @@ function listFilesWithModernApi(srcPaths, extensions, session) {
44
44
45
45
// Include the file if it's not marked as ignore by eslint and its extension is included in our list
46
46
return (
47
- ! session . isFileIgnored ( fullEntryPath )
48
- && extensions . find ( ( extension ) => entry . path . endsWith ( extension ) )
47
+ ! session . isFileIgnored ( fullEntryPath ) &&
48
+ extensions . find ( ( extension ) => entry . path . endsWith ( extension ) )
49
49
) ;
50
50
} ,
51
51
} ) ;
@@ -140,8 +140,10 @@ function listFilesWithLegacyFunctions(src, extensions) {
140
140
listFilesToProcess : originalListFilesToProcess ,
141
141
} = require ( 'eslint/lib/util/glob-util' ) ;
142
142
const patterns = src . concat (
143
- flatMap ( src , ( pattern ) => extensions . map ( ( extension ) => ( / \* \* | \* \. / ) . test ( pattern ) ? pattern : `${ pattern } /**/*${ extension } ` ,
144
- ) ,
143
+ flatMap ( src , ( pattern ) =>
144
+ extensions . map ( ( extension ) =>
145
+ / \* \* | \* \. / . test ( pattern ) ? pattern : `${ pattern } /**/*${ extension } ` ,
146
+ ) ,
145
147
) ,
146
148
) ;
147
149
@@ -162,9 +164,9 @@ function listFilesToProcess(src, extensions, context) {
162
164
// Otherwise, fallback to using the deprecated `FileEnumerator` for legacy support.
163
165
// https://github.com/eslint/eslint/issues/18087
164
166
if (
165
- context . session
166
- && context . session . isFileIgnored
167
- && context . session . isDirectoryIgnored
167
+ context . session &&
168
+ context . session . isFileIgnored &&
169
+ context . session . isDirectoryIgnored
168
170
) {
169
171
return listFilesWithModernApi ( src , extensions , context . session ) ;
170
172
} else {
@@ -175,7 +177,7 @@ function listFilesToProcess(src, extensions, context) {
175
177
if ( FileEnumerator ) {
176
178
return listFilesUsingFileEnumerator ( FileEnumerator , src , extensions ) ;
177
179
} else {
178
- // If not, then we can try even older versions of this capability (listFilesToProcess)
180
+ // If not, then we can try even older versions of this capability (listFilesToProcess)
179
181
return listFilesWithLegacyFunctions ( src , extensions ) ;
180
182
}
181
183
}
@@ -201,11 +203,11 @@ const DEFAULT = 'default';
201
203
function forEachDeclarationIdentifier ( declaration , cb ) {
202
204
if ( declaration ) {
203
205
if (
204
- declaration . type === FUNCTION_DECLARATION
205
- || declaration . type === CLASS_DECLARATION
206
- || declaration . type === TS_INTERFACE_DECLARATION
207
- || declaration . type === TS_TYPE_ALIAS_DECLARATION
208
- || declaration . type === TS_ENUM_DECLARATION
206
+ declaration . type === FUNCTION_DECLARATION ||
207
+ declaration . type === CLASS_DECLARATION ||
208
+ declaration . type === TS_INTERFACE_DECLARATION ||
209
+ declaration . type === TS_TYPE_ALIAS_DECLARATION ||
210
+ declaration . type === TS_ENUM_DECLARATION
209
211
) {
210
212
cb ( declaration . id . name ) ;
211
213
} else if ( declaration . type === VARIABLE_DECLARATION ) {
@@ -281,7 +283,7 @@ const visitorKeyMap = new Map();
281
283
const ignoredFiles = new Set ( ) ;
282
284
const filesOutsideSrc = new Set ( ) ;
283
285
284
- const isNodeModule = ( path ) => ( / \/ ( n o d e _ m o d u l e s ) \/ / ) . test ( path ) ;
286
+ const isNodeModule = ( path ) => / \/ ( n o d e _ m o d u l e s ) \/ / . test ( path ) ;
285
287
286
288
/**
287
289
* read all files matching the patterns in src and ignoreExports
@@ -315,7 +317,8 @@ const resolveFiles = (src, ignoreExports, context) => {
315
317
) ;
316
318
} else {
317
319
resolvedFiles = new Set (
318
- flatMap ( srcFileList , ( { filename } ) => isNodeModule ( filename ) ? [ ] : filename ,
320
+ flatMap ( srcFileList , ( { filename } ) =>
321
+ isNodeModule ( filename ) ? [ ] : filename ,
319
322
) ,
320
323
) ;
321
324
}
@@ -485,9 +488,11 @@ const doPreparation = (src, ignoreExports, context) => {
485
488
lastPrepareKey = prepareKey ;
486
489
} ;
487
490
488
- const newNamespaceImportExists = ( specifiers ) => specifiers . some ( ( { type } ) => type === IMPORT_NAMESPACE_SPECIFIER ) ;
491
+ const newNamespaceImportExists = ( specifiers ) =>
492
+ specifiers . some ( ( { type } ) => type === IMPORT_NAMESPACE_SPECIFIER ) ;
489
493
490
- const newDefaultImportExists = ( specifiers ) => specifiers . some ( ( { type } ) => type === IMPORT_DEFAULT_SPECIFIER ) ;
494
+ const newDefaultImportExists = ( specifiers ) =>
495
+ specifiers . some ( ( { type } ) => type === IMPORT_DEFAULT_SPECIFIER ) ;
491
496
492
497
const fileIsInPkg = ( file ) => {
493
498
const { path, pkg } = readPkgUp ( { cwd : file } ) ;
@@ -500,7 +505,8 @@ const fileIsInPkg = (file) => {
500
505
} ;
501
506
502
507
const checkPkgFieldObject = ( pkgField ) => {
503
- const pkgFieldFiles = flatMap ( values ( pkgField ) , ( value ) => typeof value === 'boolean' ? [ ] : join ( basePath , value ) ,
508
+ const pkgFieldFiles = flatMap ( values ( pkgField ) , ( value ) =>
509
+ typeof value === 'boolean' ? [ ] : join ( basePath , value ) ,
504
510
) ;
505
511
506
512
if ( includes ( pkgFieldFiles , file ) ) {
@@ -673,14 +679,16 @@ module.exports = {
673
679
exports = exportList . get ( file ) ;
674
680
675
681
if ( ! exports ) {
676
- console . error ( `file \`${ file } \` has no exports. Please update to the latest, and if it still happens, report this on https://github.com/import-js/eslint-plugin-import/issues/2866!` ) ;
682
+ console . error (
683
+ `file \`${ file } \` has no exports. Please update to the latest, and if it still happens, report this on https://github.com/import-js/eslint-plugin-import/issues/2866!` ,
684
+ ) ;
677
685
}
678
686
679
687
// special case: export * from
680
688
const exportAll = exports . get ( EXPORT_ALL_DECLARATION ) ;
681
689
if (
682
- typeof exportAll !== 'undefined'
683
- && exportedValue !== IMPORT_DEFAULT_SPECIFIER
690
+ typeof exportAll !== 'undefined' &&
691
+ exportedValue !== IMPORT_DEFAULT_SPECIFIER
684
692
) {
685
693
if ( exportAll . whereUsed . size > 0 ) {
686
694
return ;
@@ -696,11 +704,13 @@ module.exports = {
696
704
}
697
705
698
706
// exportsList will always map any imported value of 'default' to 'ImportDefaultSpecifier'
699
- const exportsKey = exportedValue === DEFAULT ? IMPORT_DEFAULT_SPECIFIER : exportedValue ;
707
+ const exportsKey =
708
+ exportedValue === DEFAULT ? IMPORT_DEFAULT_SPECIFIER : exportedValue ;
700
709
701
710
const exportStatement = exports . get ( exportsKey ) ;
702
711
703
- const value = exportsKey === IMPORT_DEFAULT_SPECIFIER ? DEFAULT : exportsKey ;
712
+ const value =
713
+ exportsKey === IMPORT_DEFAULT_SPECIFIER ? DEFAULT : exportsKey ;
704
714
705
715
if ( typeof exportStatement !== 'undefined' ) {
706
716
if ( exportStatement . whereUsed . size < 1 ) {
@@ -823,8 +833,8 @@ module.exports = {
823
833
}
824
834
value . forEach ( ( val ) => {
825
835
if (
826
- val !== IMPORT_NAMESPACE_SPECIFIER
827
- && val !== IMPORT_DEFAULT_SPECIFIER
836
+ val !== IMPORT_NAMESPACE_SPECIFIER &&
837
+ val !== IMPORT_DEFAULT_SPECIFIER
828
838
) {
829
839
oldImports . set ( val , key ) ;
830
840
}
@@ -859,7 +869,10 @@ module.exports = {
859
869
// support for export { value } from 'module'
860
870
if ( astNode . type === EXPORT_NAMED_DECLARATION ) {
861
871
if ( astNode . source ) {
862
- resolvedPath = resolve ( astNode . source . raw . replace ( / ( ' | " ) / g, '' ) , context ) ;
872
+ resolvedPath = resolve (
873
+ astNode . source . raw . replace ( / ( ' | " ) / g, '' ) ,
874
+ context ,
875
+ ) ;
863
876
astNode . specifiers . forEach ( ( specifier ) => {
864
877
const name = specifier . local . name || specifier . local . value ;
865
878
if ( name === DEFAULT ) {
@@ -872,12 +885,18 @@ module.exports = {
872
885
}
873
886
874
887
if ( astNode . type === EXPORT_ALL_DECLARATION ) {
875
- resolvedPath = resolve ( astNode . source . raw . replace ( / ( ' | " ) / g, '' ) , context ) ;
888
+ resolvedPath = resolve (
889
+ astNode . source . raw . replace ( / ( ' | " ) / g, '' ) ,
890
+ context ,
891
+ ) ;
876
892
newExportAll . add ( resolvedPath ) ;
877
893
}
878
894
879
895
if ( astNode . type === IMPORT_DECLARATION ) {
880
- resolvedPath = resolve ( astNode . source . raw . replace ( / ( ' | " ) / g, '' ) , context ) ;
896
+ resolvedPath = resolve (
897
+ astNode . source . raw . replace ( / ( ' | " ) / g, '' ) ,
898
+ context ,
899
+ ) ;
881
900
if ( ! resolvedPath ) {
882
901
return ;
883
902
}
@@ -895,9 +914,16 @@ module.exports = {
895
914
}
896
915
897
916
astNode . specifiers
898
- . filter ( ( specifier ) => specifier . type !== IMPORT_DEFAULT_SPECIFIER && specifier . type !== IMPORT_NAMESPACE_SPECIFIER )
917
+ . filter (
918
+ ( specifier ) =>
919
+ specifier . type !== IMPORT_DEFAULT_SPECIFIER &&
920
+ specifier . type !== IMPORT_NAMESPACE_SPECIFIER ,
921
+ )
899
922
. forEach ( ( specifier ) => {
900
- newImports . set ( specifier . imported . name || specifier . imported . value , resolvedPath ) ;
923
+ newImports . set (
924
+ specifier . imported . name || specifier . imported . value ,
925
+ resolvedPath ,
926
+ ) ;
901
927
} ) ;
902
928
}
903
929
} ) ;
@@ -1086,7 +1112,10 @@ module.exports = {
1086
1112
} ,
1087
1113
ExportNamedDeclaration ( node ) {
1088
1114
node . specifiers . forEach ( ( specifier ) => {
1089
- checkUsage ( specifier , specifier . exported . name || specifier . exported . value ) ;
1115
+ checkUsage (
1116
+ specifier ,
1117
+ specifier . exported . name || specifier . exported . value ,
1118
+ ) ;
1090
1119
} ) ;
1091
1120
forEachDeclarationIdentifier ( node . declaration , ( name ) => {
1092
1121
checkUsage ( node , name ) ;
0 commit comments