Skip to content

Commit eca73ed

Browse files
authored
fix(no-unused-modules): default src to [process.cwd()] (#147)
1 parent d228129 commit eca73ed

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

.changeset/flat-doors-chew.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-import-x": patch
3+
---
4+
5+
Fix regression in rule `no-unused-modules` which would incorrectly initialize option `src` to `[]` instead of `[process.cwd()]`, breaking file discovery.

src/rules/no-unused-modules.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -291,13 +291,6 @@ const determineUsage = () => {
291291
}
292292
}
293293

294-
const getSrc = (src?: string[]) => {
295-
if (src) {
296-
return src
297-
}
298-
return [process.cwd()]
299-
}
300-
301294
/**
302295
* prepare the lists of existing imports and exports - should only be executed once at
303296
* the start of a new eslint run
@@ -306,7 +299,7 @@ let srcFiles: Set<string>
306299
let lastPrepareKey: string
307300

308301
const doPreparation = (
309-
src: string[] = [],
302+
src: string[],
310303
ignoreExports: string[],
311304
context: RuleContext,
312305
) => {
@@ -324,7 +317,7 @@ const doPreparation = (
324317
ignoredFiles.clear()
325318
filesOutsideSrc.clear()
326319

327-
srcFiles = resolveFiles(getSrc(src), ignoreExports, context)
320+
srcFiles = resolveFiles(src, ignoreExports, context)
328321
prepareImportsAndExports(srcFiles, context)
329322
determineUsage()
330323
lastPrepareKey = prepareKey
@@ -486,7 +479,7 @@ export = createRule<Options[], MessageId>({
486479
defaultOptions: [],
487480
create(context) {
488481
const {
489-
src,
482+
src = [process.cwd()],
490483
ignoreExports = [],
491484
missingExports,
492485
unusedExports,
@@ -559,7 +552,7 @@ export = createRule<Options[], MessageId>({
559552

560553
// make sure file to be linted is included in source files
561554
if (!srcFiles.has(filename)) {
562-
srcFiles = resolveFiles(getSrc(src), ignoreExports, context)
555+
srcFiles = resolveFiles(src, ignoreExports, context)
563556
if (!srcFiles.has(filename)) {
564557
filesOutsideSrc.add(filename)
565558
return

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy