44 * @author René Fermann
55 */
66
7- import * as fsWalk from '@nodelib/fs.walk ' ;
7+ import * as fsWalk from '../core/fsWalk ' ;
88import { getFileExtensions } from 'eslint-module-utils/ignore' ;
99import resolve from 'eslint-module-utils/resolve' ;
1010import visit from 'eslint-module-utils/visit' ;
@@ -44,8 +44,8 @@ function listFilesWithModernApi(srcPaths, extensions, session) {
4444
4545 // Include the file if it's not marked as ignore by eslint and its extension is included in our list
4646 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 ) )
4949 ) ;
5050 } ,
5151 } ) ;
@@ -140,8 +140,10 @@ function listFilesWithLegacyFunctions(src, extensions) {
140140 listFilesToProcess : originalListFilesToProcess ,
141141 } = require ( 'eslint/lib/util/glob-util' ) ;
142142 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+ ) ,
145147 ) ,
146148 ) ;
147149
@@ -162,9 +164,9 @@ function listFilesToProcess(src, extensions, context) {
162164 // Otherwise, fallback to using the deprecated `FileEnumerator` for legacy support.
163165 // https://github.com/eslint/eslint/issues/18087
164166 if (
165- context . session
166- && context . session . isFileIgnored
167- && context . session . isDirectoryIgnored
167+ context . session &&
168+ context . session . isFileIgnored &&
169+ context . session . isDirectoryIgnored
168170 ) {
169171 return listFilesWithModernApi ( src , extensions , context . session ) ;
170172 } else {
@@ -175,7 +177,7 @@ function listFilesToProcess(src, extensions, context) {
175177 if ( FileEnumerator ) {
176178 return listFilesUsingFileEnumerator ( FileEnumerator , src , extensions ) ;
177179 } 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)
179181 return listFilesWithLegacyFunctions ( src , extensions ) ;
180182 }
181183 }
@@ -201,11 +203,11 @@ const DEFAULT = 'default';
201203function forEachDeclarationIdentifier ( declaration , cb ) {
202204 if ( declaration ) {
203205 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
209211 ) {
210212 cb ( declaration . id . name ) ;
211213 } else if ( declaration . type === VARIABLE_DECLARATION ) {
@@ -281,7 +283,7 @@ const visitorKeyMap = new Map();
281283const ignoredFiles = new Set ( ) ;
282284const filesOutsideSrc = new Set ( ) ;
283285
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 ) ;
285287
286288/**
287289 * read all files matching the patterns in src and ignoreExports
@@ -315,7 +317,8 @@ const resolveFiles = (src, ignoreExports, context) => {
315317 ) ;
316318 } else {
317319 resolvedFiles = new Set (
318- flatMap ( srcFileList , ( { filename } ) => isNodeModule ( filename ) ? [ ] : filename ,
320+ flatMap ( srcFileList , ( { filename } ) =>
321+ isNodeModule ( filename ) ? [ ] : filename ,
319322 ) ,
320323 ) ;
321324 }
@@ -485,9 +488,11 @@ const doPreparation = (src, ignoreExports, context) => {
485488 lastPrepareKey = prepareKey ;
486489} ;
487490
488- const newNamespaceImportExists = ( specifiers ) => specifiers . some ( ( { type } ) => type === IMPORT_NAMESPACE_SPECIFIER ) ;
491+ const newNamespaceImportExists = ( specifiers ) =>
492+ specifiers . some ( ( { type } ) => type === IMPORT_NAMESPACE_SPECIFIER ) ;
489493
490- const newDefaultImportExists = ( specifiers ) => specifiers . some ( ( { type } ) => type === IMPORT_DEFAULT_SPECIFIER ) ;
494+ const newDefaultImportExists = ( specifiers ) =>
495+ specifiers . some ( ( { type } ) => type === IMPORT_DEFAULT_SPECIFIER ) ;
491496
492497const fileIsInPkg = ( file ) => {
493498 const { path, pkg } = readPkgUp ( { cwd : file } ) ;
@@ -500,7 +505,8 @@ const fileIsInPkg = (file) => {
500505 } ;
501506
502507 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 ) ,
504510 ) ;
505511
506512 if ( includes ( pkgFieldFiles , file ) ) {
@@ -673,14 +679,16 @@ module.exports = {
673679 exports = exportList . get ( file ) ;
674680
675681 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+ ) ;
677685 }
678686
679687 // special case: export * from
680688 const exportAll = exports . get ( EXPORT_ALL_DECLARATION ) ;
681689 if (
682- typeof exportAll !== 'undefined'
683- && exportedValue !== IMPORT_DEFAULT_SPECIFIER
690+ typeof exportAll !== 'undefined' &&
691+ exportedValue !== IMPORT_DEFAULT_SPECIFIER
684692 ) {
685693 if ( exportAll . whereUsed . size > 0 ) {
686694 return ;
@@ -696,11 +704,13 @@ module.exports = {
696704 }
697705
698706 // 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 ;
700709
701710 const exportStatement = exports . get ( exportsKey ) ;
702711
703- const value = exportsKey === IMPORT_DEFAULT_SPECIFIER ? DEFAULT : exportsKey ;
712+ const value =
713+ exportsKey === IMPORT_DEFAULT_SPECIFIER ? DEFAULT : exportsKey ;
704714
705715 if ( typeof exportStatement !== 'undefined' ) {
706716 if ( exportStatement . whereUsed . size < 1 ) {
@@ -823,8 +833,8 @@ module.exports = {
823833 }
824834 value . forEach ( ( val ) => {
825835 if (
826- val !== IMPORT_NAMESPACE_SPECIFIER
827- && val !== IMPORT_DEFAULT_SPECIFIER
836+ val !== IMPORT_NAMESPACE_SPECIFIER &&
837+ val !== IMPORT_DEFAULT_SPECIFIER
828838 ) {
829839 oldImports . set ( val , key ) ;
830840 }
@@ -859,7 +869,10 @@ module.exports = {
859869 // support for export { value } from 'module'
860870 if ( astNode . type === EXPORT_NAMED_DECLARATION ) {
861871 if ( astNode . source ) {
862- resolvedPath = resolve ( astNode . source . raw . replace ( / ( ' | " ) / g, '' ) , context ) ;
872+ resolvedPath = resolve (
873+ astNode . source . raw . replace ( / ( ' | " ) / g, '' ) ,
874+ context ,
875+ ) ;
863876 astNode . specifiers . forEach ( ( specifier ) => {
864877 const name = specifier . local . name || specifier . local . value ;
865878 if ( name === DEFAULT ) {
@@ -872,12 +885,18 @@ module.exports = {
872885 }
873886
874887 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+ ) ;
876892 newExportAll . add ( resolvedPath ) ;
877893 }
878894
879895 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+ ) ;
881900 if ( ! resolvedPath ) {
882901 return ;
883902 }
@@ -895,9 +914,16 @@ module.exports = {
895914 }
896915
897916 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+ )
899922 . 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+ ) ;
901927 } ) ;
902928 }
903929 } ) ;
@@ -1086,7 +1112,10 @@ module.exports = {
10861112 } ,
10871113 ExportNamedDeclaration ( node ) {
10881114 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+ ) ;
10901119 } ) ;
10911120 forEachDeclarationIdentifier ( node . declaration , ( name ) => {
10921121 checkUsage ( node , name ) ;
0 commit comments