Description
Reproduction
Consider this test project: test.zip1
- Run
pnpm install
(ornpm install
if you'd rather). - Run
pnpm exec eslint
(ornpm exec eslint
).
Expected results
Linting runs with no issues reported.
Actual results
There will be an error. It's random whether it's
/tmp/test/src/a.foo.js
1:15 error Unable to resolve path to module './x' import/no-unresolved
or
/tmp/test/src/a.bar.js
1:15 error Unable to resolve path to module './y' import/no-unresolved
Analysis
The eslint configuration in that test project configures the extensions
for .foo.js
files to prefer including other .foo.js
files, and for .bar.js
files to prefer including other .bar.js
files.2
The problem appears to be in
eslint-import-resolver-typescript/src/normalize-options.ts
Lines 79 to 85 in c06392f
If
configFile
is set, it caches and reuses options with that filename as a key, without considering that the passed-in options
may be different. Therefore, the options for whichever of .foo.js
or .bar.js
happens to get there first are used for both types of files.
Footnotes
-
Note the problem also happens if
eslint-plugin-import
is replaced witheslint-plugin-import-x
and configuration is adjusted accordingly. ↩ -
The real-world version of this is our configuration for linting React Native code, where
.native.js
files want to include other.native.js
. Having both.foo.js
and.bar.js
in the reproduction makes it always error on one file or the other. ↩