Skip to content

Commit

Permalink
fix(no-unused-modules): default src to [process.cwd()] (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
nchevsky authored Sep 4, 2024
1 parent d228129 commit eca73ed
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/flat-doors-chew.md
Original file line number Diff line number Diff line change
@@ -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.
15 changes: 4 additions & 11 deletions src/rules/no-unused-modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -306,7 +299,7 @@ let srcFiles: Set<string>
let lastPrepareKey: string

const doPreparation = (
src: string[] = [],
src: string[],
ignoreExports: string[],
context: RuleContext,
) => {
Expand All @@ -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
Expand Down Expand Up @@ -486,7 +479,7 @@ export = createRule<Options[], MessageId>({
defaultOptions: [],
create(context) {
const {
src,
src = [process.cwd()],
ignoreExports = [],
missingExports,
unusedExports,
Expand Down Expand Up @@ -559,7 +552,7 @@ export = createRule<Options[], MessageId>({

// 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
Expand Down

0 comments on commit eca73ed

Please sign in to comment.