Skip to content

Caching results in wrong configuration being used #465

Open
@anomiex

Description

@anomiex

Reproduction

Consider this test project: test.zip1

  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

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

  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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions