eslint / eslint

Find and fix problems in your JavaScript code.
https://eslint.org
MIT License
24.39k stars 4.4k forks source link

Bug: flat configs are processing ignored directories and applying rules that were scoped to other directories #18372

Closed runspired closed 1 week ago

runspired commented 4 weeks ago

Environment

Node version: v18.20.2 (N/A) npm version: v10.5.0 (N/A) Local ESLint version: v8.57.0 Global ESLint version: Not found Operating System: darwin 22.6.0

Bun: 1.1.2 Pnpm: 8.15.6

What parser are you using?

What did you do?

Note: I'm using flat config which can't be copy pasted due to their size

Configuration ```js import * as node from '@warp-drive/internal-config/eslint/node.js'; import * as typescript from '@warp-drive/internal-config/eslint/typescript.js'; import * as qunit from '@warp-drive/internal-config/eslint/qunit.js'; /** @type {import('eslint').Linter.FlatConfig[]} */ export default [ // all ================ globalIgnores(), typescript.browser({ srcDirs: ['src'], allowedImports: [ '@embroider/macros', '@ember/application/namespace', 'ember', 'ember-inflector', '@ember/debug', '@ember/array/proxy', '@ember/object/promise-proxy-mixin', '@ember/object/proxy', '@ember/application', ], }), // node (module) ================ node.esm(), // node (script) ================ node.cjs(), // Test Support qunit.ember({ files: ['src/test-support/**/*.{js,ts}'], allowedImports: ['@ember/debug', '@ember/owner'], }), ]; ```
bun run eslint . --report-unused-disable-directives

What did you expect to happen?

all lint rules pass as expected

What actually happened?

lint rules failed for files within ignore in a manner that suggests rules but not plugins were applied globally

/Users/cthoburn/github/data/packages/-ember-data/dist/test-support/index.js
  8:3  error  Definition for rule '@typescript-eslint/no-unsafe-member-access' was not found  @typescript-eslint/no-unsafe-member-access

Note: all files parsed by the typescript rules passed successfully. Those rules specify exactly which files to match in the config object under files which in this case is scoped to the directory ./src. So this suggests that rules were hoisted out of a config object and applied both to files that they were not intended to apply to and without the plugin they depend upon.

globalIgnores(), is a list of files and directories to always ignore using the global overrides pattern:

{
  ignores: ['dist', './dist', 'dist/*', './dist/*'],
}

Note: the actual list is much longer, but I've shortend it to just what we care about here. Also note how just in case I've tried every variant of directory glob just in case eslint shifted away from dist working as expected. No variation worked.

Debugging with bun run eslint --print-config ./dist/test-support/index.js leads to an interesting observation:

{
  "languageOptions": {
    "ecmaVersion": "latest",
    "sourceType": "module",
    "parser": "espree@9.6.1",
    "parserOptions": {},
    "globals": {}
  },
  "plugins": [
    "@"
  ],
  "rules": {}
}

Based on the ignores this file shouldn't be in the system, but what we see is that default language options have been applied. Note though, no rules ;)

Link to Minimal Reproducible Example

N/A

Participation

Additional comments

Note using the new rules debugger is not possible. eslint --inspect-config errors as --inspect-config is not valid. npx @eslint/config-inspector fails because it cannot find eslint since this is a project that enforces strict node_modules vs dangerously hoisting them like the tool depends upon.

mdjermanovic commented 3 weeks ago

Local ESLint version: v8.57.0

Can you try with the latest ESLint v9.1.0?

If it still doesn't work as expected, please provide a minimal reproducible example as there is not enough information for us to figure out what could be causing the problem.

eslint-github-bot[bot] commented 1 week ago

It looks like there wasn't enough information for us to know how to help you, so we're closing the issue.

Thanks for your understanding.