ITADN

Caching results in wrong configuration being used

#465Closedanomiex 创建于 2025-06-24
A
anomiexcommented
## Reproduction Consider this test project: [test.zip](https://github.com/user-attachments/files/20887726/test.zip)[^1] 1. Run `pnpm install` (or `npm install` if you'd rather). 2. Run `pnpm exec eslint` (or `npm 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 https://github.com/import-js/eslint-import-resolver-typescript/blob/c06392fcb4c6445e720db326475e3fe0b0814229/src/normalize-options.ts#L79-L85 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. [^1]: Note the problem also happens if `eslint-plugin-import` is replaced with `eslint-plugin-import-x` and configuration is adjusted accordingly. [^2]: 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.
关闭于 2025-06-25 5 条评论