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: (apparently) not ignoring dotted directories by default #18236

Closed
1 task
alexrussell opened this issue Mar 28, 2024 · 2 comments
Closed
1 task

Bug: (apparently) not ignoring dotted directories by default #18236

alexrussell opened this issue Mar 28, 2024 · 2 comments
Labels
works as intended The behavior described in this issue is working correctly

Comments

@alexrussell
Copy link

alexrussell commented Mar 28, 2024

Environment

Node version: v21.2.0
npm version: 10.2.3
Local ESLint version: v8.57.0
Global ESLint version: not installed globally
Operating System: macOS 13.6.2

What parser are you using?

Default (Espree)

What did you do?

Configuration

Using the flat config style, file: eslint.config.js with "type": "module" in package.json.

import eslint from '@eslint/js'

export default [
  eslint.configs.recommended,
]
`bad.js` file contents
const a = 0

The contents of bad.js (see above) are to be placed in the following places, relative to the root of
the project:

  • lint/bad.js
  • lint/not-ignored/bad.js
  • lint/.ignored/bad.js

Then simply run npx eslint ..

What did you expect to happen?

I would expect that the only two files linted here would be the first two (i.e. lint/bad.js and lint/not-ignored/bad.js).

What actually happened?

All three files are being included (and linted), see command output below:

Command output
$ npx eslint .

{cwd}/lint/.ignored/bad.js
  1:5  error  'a' is assigned a value but never used  no-unused-vars

{cwd}/lint/bad.js
  1:7  error  'a' is assigned a value but never used  no-unused-vars

{cwd}/lint/not-ignored/bad.js
  1:5  error  'a' is assigned a value but never used  no-unused-vars

✖ 3 problems (3 errors, 0 warnings)

If I specify an ignore pattern that ignores "dotted directories" then it correctly ignore that file. But I didn't expect to have to specify this. See command output below:

Command output
$ npx eslint --ignore-pattern '**/.*' .

{cwd}/lint/bad.js
  1:7  error  'a' is assigned a value but never used  no-unused-vars

{cwd}/lint/no-ignore/bad.js
  1:5  error  'a' is assigned a value but never used  no-unused-vars

✖ 2 problems (2 errors, 0 warnings)

Note that attempting this "please do actually ignore dotted directories" configuration inside an .eslintignore file doesn't seem to work, but it may be that I don't have the syntax quite right there, or maybe they don't work with flat configs and I haven't seen it in the docs.

Link to Minimal Reproducible Example

https://github.com/alexrussell/eslint-ignore-demo

Participation

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

Additional comments

I can only assume I have done something wrong here, but I can't for the life of me see what it is! I do wonder if the semantics of eslint are quite different when using the new flat config, and maybe the docs aren't quite up-to-date with that?

@alexrussell alexrussell added bug ESLint is working incorrectly repro:needed labels Mar 28, 2024
@Tanujkanti4441
Copy link
Contributor

Hi @alexrussell, thanks for the issue,

This works as intended. New flat-config use minimatch syntax to match files for linting which by default ignores directory or files starts with dot in their name unless {dot:true} is set, here we can see

const MINIMATCH_OPTIONS = { dot: true };

@mdjermanovic, can you please confirm the behavior.

i think we should document it.

@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 28, 2024
@mdjermanovic
Copy link
Member

Hi @alexrussell, thanks for the issue!

This works as intended. In flat config, dotfiles and dotfolders are not ignored by default.

Note that attempting this "please do actually ignore dotted directories" configuration inside an .eslintignore file doesn't seem to work, but it may be that I don't have the syntax quite right there, or maybe they don't work with flat configs and I haven't seen it in the docs.

The pattern is good, but flat config doesn't support .eslintignore files. You can specify ignore patterns directly in eslint.config.js:

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

In your example, the configuration would be:

// eslint.config.js

import eslint from '@eslint/js'

export default [
  {
    ignores: ['**/.*']
  },
  eslint.configs.recommended,
]

@mdjermanovic mdjermanovic closed this as not planned Won't fix, can't repro, duplicate, stale Mar 28, 2024
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

3 participants