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

Docs: (flat config) improve global ignores documentation #17822

Closed
1 task
bradzacher opened this issue Dec 6, 2023 · 6 comments · Fixed by #17997
Closed
1 task

Docs: (flat config) improve global ignores documentation #17822

bradzacher opened this issue Dec 6, 2023 · 6 comments · Fixed by #17997
Assignees
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion documentation Relates to ESLint's documentation

Comments

@bradzacher
Copy link
Contributor

Environment

Node version: v18.16.1
npm version: v9.5.0
Local ESLint version: v8.55.0 (Currently used)
Global ESLint version: Not found
Operating System: darwin 23.1.0

What parser are you using?

Default (Espree)

What did you do?

module.exports = [
  {
    ignores: ["dist"],
  },
  {
    files: ["src/**/*.js"],
    rules: {
      'no-console': 'error',
    }
  },
]

What did you expect to happen?

Given the folder structure:

eslint.config.js
src/not-ignored.js
src/dist/not-ignored.js

I would expect that running eslint src would lint src/not-ignored.js and would skip src/dist/not-ignored.js.

What actually happened?

Both files do get linted

$ ESLINT_USE_FLAT_CONFIG=true node_modules/.bin/eslint src

/Users/bjz/temp/eslint-flat-config-bugs/not-ignored-bug/src/dist/ignored.js
  1:1  error  Unexpected console statement  no-console

/Users/bjz/temp/eslint-flat-config-bugs/not-ignored-bug/src/not-ignored.js
  1:1  error  Unexpected console statement  no-console

✖ 2 problems (2 errors, 0 warnings)

Link to Minimal Reproducible Example

https://github.com/bradzacher/eslint-flat-config-bugs/tree/main/not-ignored-bug

Participation

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

Additional comments

probably relevant DEBUG=* output

  @hwc/config-array Anonymous universal config found for /Users/bjz/temp/eslint-flat-config-bugs/not-ignored-bug/src/not-ignored.js +0ms
  @hwc/config-array Skipped config found for /Users/bjz/temp/eslint-flat-config-bugs/not-ignored-bug/src/not-ignored.js (based on ignores: **/node_modules/,.git/) +0ms
  @hwc/config-array Matching config found for /Users/bjz/temp/eslint-flat-config-bugs/not-ignored-bug/src/not-ignored.js +0ms
  @hwc/config-array Skipped config found for /Users/bjz/temp/eslint-flat-config-bugs/not-ignored-bug/src/not-ignored.js (based on ignores: dist) +0ms
  @hwc/config-array Matching config found for /Users/bjz/temp/eslint-flat-config-bugs/not-ignored-bug/src/not-ignored.js +1ms
  @hwc/config-array Anonymous universal config found for /Users/bjz/temp/eslint-flat-config-bugs/not-ignored-bug/src/not-ignored.js +0ms
  eslint:rules Loading rule 'no-console' (remaining=290) +0ms
  @hwc/config-array Anonymous universal config found for /Users/bjz/temp/eslint-flat-config-bugs/not-ignored-bug/src/dist/ignored.js +5ms
  @hwc/config-array Skipped config found for /Users/bjz/temp/eslint-flat-config-bugs/not-ignored-bug/src/dist/ignored.js (based on ignores: **/node_modules/,.git/) +0ms
  @hwc/config-array Matching config found for /Users/bjz/temp/eslint-flat-config-bugs/not-ignored-bug/src/dist/ignored.js +0ms
  @hwc/config-array Skipped config found for /Users/bjz/temp/eslint-flat-config-bugs/not-ignored-bug/src/dist/ignored.js (based on ignores: dist) +0ms
  @hwc/config-array Matching config found for /Users/bjz/temp/eslint-flat-config-bugs/not-ignored-bug/src/dist/ignored.js +0ms
  @hwc/config-array Anonymous universal config found for /Users/bjz/temp/eslint-flat-config-bugs/not-ignored-bug/src/dist/ignored.js +0ms

It looks like the src/dist/ignored.js file gets ignored then unignored by the files glob.

This is contrary to what I'd expect based on the docs that state that

If ignores is used without any other keys in the configuration object, then the patterns act as global ignores.

I wouldn't expect that I can implicilty unignore a file by simply adding it to a files - I'd expect that I'd need to explicitly unignore it eg ignores: ['!src/dist/ignored.js']

@bradzacher bradzacher added bug ESLint is working incorrectly repro:needed labels Dec 6, 2023
@bradzacher bradzacher changed the title Bug: (fill in) Bug: (flat config) folder ignored with ignores is un-ignored by files Dec 6, 2023
@bradzacher
Copy link
Contributor Author

Hmmm. Re-reading the docs a bit more - it looks like the ignores array uses minimatch syntax - not .gitignore syntax like the .eslintignore that I was migrating from.

So the correct form of the ignore is instead **/dist/**.

So this isn't a bug - it's instead (imo) unclear documentation thing.
I was tricked because the example uses "!node_modules/" which looks like gitignore syntax.
It also lists "node_modules/*" with the comment "ignore its content" - but this wouldn't actually match the node module contents properly - it would only ignore any files within node_modules directly (i.e. node_modules/foo/bar.js would not be ignored).

This section probably needs another pass to help clarify the usage.
It would probably also be good to add an example of how one might migrate from a .eslintignore file.

@mdjermanovic
Copy link
Member

It also lists "node_modules/*" with the comment "ignore its content" - but this wouldn't actually match the node module contents properly - it would only ignore any files within node_modules directly (i.e. node_modules/foo/bar.js would not be ignored).

In global ignores, patterns match directories too, so node_modules/foo/bar.js is ignored because it's in ignored directory node_modules/foo (the directory is matched by "node_modules/*"). Global ignores work much like .gitignore (matching directories; unignoring) with enhanced syntax and in some cases indeed different semantics in patterns - a notable difference is the one you noticed, dist pattern matches only top-level dist file/directory.

@mdjermanovic
Copy link
Member

This section probably needs another pass to help clarify the usage.
It would probably also be good to add an example of how one might migrate from a .eslintignore file.

I also think it would be good to improve this section and migration guide.

@mdjermanovic mdjermanovic added documentation Relates to ESLint's documentation and removed bug ESLint is working incorrectly repro:needed labels Dec 6, 2023
@bradzacher bradzacher changed the title Bug: (flat config) folder ignored with ignores is un-ignored by files Docs: (flat config) improve global ignores documentation Dec 6, 2023
@bradzacher
Copy link
Contributor Author

@mdjermanovic i didn't know there was a migration guide - is it linked from the new config docs? I didn't see it when searching the page.

@nzakas
Copy link
Member

nzakas commented Dec 12, 2023

Let's hold off until we merge the new docs:

#17840

We already have too many big changes happening to docs and I don't want to have to update them all again.

@nzakas nzakas added the accepted There is consensus among the team that this change meets the criteria for inclusion label Dec 12, 2023
@nzakas nzakas self-assigned this Jan 16, 2024
@nzakas
Copy link
Member

nzakas commented Jan 16, 2024

Working on this.

nzakas added a commit that referenced this issue Jan 16, 2024
mdjermanovic pushed a commit that referenced this issue Jan 19, 2024
* docs: Improve flat config ignores docs

fixes #17822

* Fix links
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion documentation Relates to ESLint's documentation
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants