Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: (ignores not respected when using flat config). Expands and scans ignored files! #18234

Closed
1 task
mctrafik opened this issue Mar 27, 2024 · 2 comments
Closed
1 task
Labels
works as intended The behavior described in this issue is working correctly

Comments

@mctrafik
Copy link

mctrafik commented Mar 27, 2024

Environment

Node version: v20.11.1
npm version: v10.2.4
Local ESLint version: v8.57.0 (Currently used)
Global ESLint version: Not found
Operating System: darwin 23.3.0

What parser are you using?

@typescript-eslint/parser

What did you do?

Configuration
const scope = {
  files: ['ts', 'tsx', 'cts', 'ctsx', 'mts', 'mtsx', 'js', 'cjs', 'mjs'].map(
    (ext) => `src/**/*.${ext}`
  ),
  // See eslint/lib/eslint/eslint-helpers.js [findFiles] (line 471)
  ignores: ['**/dist', '**/dist/*', '**/dist/**/*'],
};

import tseslint from 'typescript-eslint';

/** @type {import('@typescript-eslint/utils').TSESLint.FlatConfig.ConfigArray} */
const configs = [
  {
    ...scope,
    plugins: {
      '@typescript-eslint': tseslint.plugin,
    },
    languageOptions: {
      globals: Object.fromEntries(
        ['jest', 'it', 'describe', 'test', 'expect'] // Jest
          .concat(['window', 'document', 'setTimeout', 'setInterval']) // DOM
          .map((key) => [key, true])
      ),
      ecmaVersion: 2022,

      parser: tseslint.parser,
      parserOptions: {
        project: ['./tsconfig.json'],
        sourceType: 'module',
        tsconfigRootDir: import.meta.dirname,
      },
    },
  },
];

export default configs;

dist/foo.js

//eslint-disable-next-line @typescript-eslint/no-explicit-any

What did you expect to happen?

I expected the linter to not look into the dist folderI have tried ignoring it using/dist, /dist/, **/dist/, dist//` and nothing works. It still scans that file, finds an offending inline comment and fails!

Please see the repro (run npm run lint).

What actually happened?

  160353:7   error  Definition for rule '@typescript-eslint/no-explicit-any' was not found          @typescript-eslint/no-explicit-any

But I don't have this rule enabled!! It's finding a string to disable this rule in a compiled backaged that bundles in a dependency that has this rule disabled inline somewhere

Link to Minimal Reproducible Example

https://stackblitz.com/edit/stackblitz-starters-jzanfz

Participation

  • I am willing to submit a pull request for this issue.

Additional comments

Just want to highlight that I can't affect the code that's in dist folder. It's bundling in dependencies, which have eslint comments! I ignore the directory so it's a bug that exceptions (about 100k of them) get thrown by the linter.

I placed some debug statements inside of the eslint lib, and I see that the ignores that I pass get discarded, and the list only contains [ '**/node_modules/', '.git/' ] which I think is due to a bug somewhere in eslint code.

@mctrafik mctrafik added bug ESLint is working incorrectly repro:needed labels Mar 27, 2024
@mdjermanovic mdjermanovic added works as intended The behavior described in this issue is working correctly and removed bug ESLint is working incorrectly repro:needed labels Mar 27, 2024
@mdjermanovic
Copy link
Member

Hi @mctrafik, thanks for the issue!

This works as intended. If the configuration object has other keys, ignores limits which files the configuration object applies to:

https://eslint.org/docs/latest/use/configure/configuration-files-new#excluding-files-with-ignores

To ignore files, ignores should be used without any other keys in the configuration object:

https://eslint.org/docs/latest/use/configure/configuration-files-new#globally-ignoring-files-with-ignores

In your example, the configuration would be:

import tseslint from 'typescript-eslint';

/** @type {import('@typescript-eslint/utils').TSESLint.FlatConfig.ConfigArray} */
const configs = [
  {
    ignores: ['**/dist'],
  },
  {
    files: ['ts', 'tsx', 'cts', 'ctsx', 'mts', 'mtsx', 'js', 'cjs', 'mjs'].map(
      (ext) => `src/**/*.${ext}`
    ),
    plugins: {
      '@typescript-eslint': tseslint.plugin,
    },
    languageOptions: {
      globals: Object.fromEntries(
        ['jest', 'it', 'describe', 'test', 'expect'] // Jest
          .concat(['window', 'document', 'setTimeout', 'setInterval']) // DOM
          .map((key) => [key, true])
      ),
      ecmaVersion: 2022,

      parser: tseslint.parser,
      parserOptions: {
        project: ['./tsconfig.json'],
        sourceType: 'module',
        tsconfigRootDir: import.meta.dirname,
      },
    },
  },
];

export default configs;

https://stackblitz.com/edit/stackblitz-starters-7dk5wd?file=eslint.config.mjs

@mdjermanovic mdjermanovic closed this as not planned Won't fix, can't repro, duplicate, stale Mar 27, 2024
@mctrafik
Copy link
Author

I see there's a way to exclude it, but the for record, the fact that the config file species no other ignores, and those ignores are ignored is extremely counter-intuitive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
works as intended The behavior described in this issue is working correctly
Projects
Archived in project
Development

No branches or pull requests

2 participants