From eca73edf9ce69ca2e07555a7f34702a5c1e2d75a Mon Sep 17 00:00:00 2001 From: Nick Chevsky Date: Wed, 4 Sep 2024 12:20:23 -0500 Subject: [PATCH] fix(`no-unused-modules`): default `src` to `[process.cwd()]` (#147) --- .changeset/flat-doors-chew.md | 5 +++++ src/rules/no-unused-modules.ts | 15 ++++----------- 2 files changed, 9 insertions(+), 11 deletions(-) create mode 100644 .changeset/flat-doors-chew.md diff --git a/.changeset/flat-doors-chew.md b/.changeset/flat-doors-chew.md new file mode 100644 index 000000000..a006e3927 --- /dev/null +++ b/.changeset/flat-doors-chew.md @@ -0,0 +1,5 @@ +--- +"eslint-plugin-import-x": patch +--- + +Fix regression in rule `no-unused-modules` which would incorrectly initialize option `src` to `[]` instead of `[process.cwd()]`, breaking file discovery. diff --git a/src/rules/no-unused-modules.ts b/src/rules/no-unused-modules.ts index 7c7597274..6a2f4b81e 100644 --- a/src/rules/no-unused-modules.ts +++ b/src/rules/no-unused-modules.ts @@ -291,13 +291,6 @@ const determineUsage = () => { } } -const getSrc = (src?: string[]) => { - if (src) { - return src - } - return [process.cwd()] -} - /** * prepare the lists of existing imports and exports - should only be executed once at * the start of a new eslint run @@ -306,7 +299,7 @@ let srcFiles: Set let lastPrepareKey: string const doPreparation = ( - src: string[] = [], + src: string[], ignoreExports: string[], context: RuleContext, ) => { @@ -324,7 +317,7 @@ const doPreparation = ( ignoredFiles.clear() filesOutsideSrc.clear() - srcFiles = resolveFiles(getSrc(src), ignoreExports, context) + srcFiles = resolveFiles(src, ignoreExports, context) prepareImportsAndExports(srcFiles, context) determineUsage() lastPrepareKey = prepareKey @@ -486,7 +479,7 @@ export = createRule({ defaultOptions: [], create(context) { const { - src, + src = [process.cwd()], ignoreExports = [], missingExports, unusedExports, @@ -559,7 +552,7 @@ export = createRule({ // make sure file to be linted is included in source files if (!srcFiles.has(filename)) { - srcFiles = resolveFiles(getSrc(src), ignoreExports, context) + srcFiles = resolveFiles(src, ignoreExports, context) if (!srcFiles.has(filename)) { filesOutsideSrc.add(filename) return