-
-
Notifications
You must be signed in to change notification settings - Fork 73
Description
Reproduction
Consider this test project: test.zip1
- Run
pnpm install(ornpm installif 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) { | |
| const cachedOptions = configFileMapping.get(configFile) | |
| if (cachedOptions) { | |
| log('using cached options for', configFile) | |
| return cachedOptions | |
| } | |
| } |
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-importis replaced witheslint-plugin-import-xand configuration is adjusted accordingly. ↩ -
The real-world version of this is our configuration for linting React Native code, where
.native.jsfiles want to include other.native.js. Having both.foo.jsand.bar.jsin the reproduction makes it always error on one file or the other. ↩