Skip to content

Overrides of ignore patterns #15687

@mysticatea

Description

@mysticatea

From: eslint/eslintrc#20 (comment), #5410

The flat config should provide the way that end-users override the ignores setting of shareable configs and ESLint built-ins.


In .eslintignore, we can use negative patterns.

# .eslintignore
!/node_modules/my-package/
!.eslintrc.js

ESLint ignores /node_modules/* by default, but we can un-ignore it by such as the above setting.
Similarly, ESLint ignores dotfiles by default, but we can un-ignore it to lint .eslintrc.js-like config files.


In .eslintrc.*, the ignorePatterns setting is the same style as .eslintignore. Both end-user's configs and shareable configs can have the ignorePatterns setting. It let us override the settings of base configs.

# .eslintrc.yml
ignorePatterns:
  - "!/node_modules/my-package/"
  - "!.eslintrc.js"

I think we should consider it on the flat config system.

import baseConfig from "my-eslint-config"
export default [
  baseConfig, // when it has `ignores: ["/foo/*"]`
  {
    ignores: [
      "!/node_modules/my-package/", // un-ignore the built-in ignores
      "!/foo/bar"                   // un-ignore the base config's ignores
    ]
  }
]

Also, I think it's confusing with the following:

import baseConfig from "my-eslint-config"
export default [
  baseConfig, // when it has `ignores: ["/foo/*"]`
  {
    files: ["/**/*.js"],
    ignores: [
      "!/node_modules/my-package/", // 
      "!/foo/bar"                   // what happens?
    ]
  }
]

This is a topic that wasn't resolved in "Config File Simplification" RFC.

In eslint/rfcs#9 (comment) thread, I had tried to describe that the ignores setting has two meaning, then argued that it should be separated.

  • If the files field exists, the ignores field is used for the adoption of the config array element and isn't merged for the ignore check. It's glob patterns as the RFC says. It corresponds to the files and excludedFiles of legacy configs.
  • If the files field doesn't exist, the ignores field doesn't affect the adoption of the config array element and is merged for the ignore check. It's a list of gitignore-style patterns and supports negative patterns to override base configs. It corresponds to the ignorePatterns of legacy configs and .eslintignore.

Metadata

Metadata

Assignees

Labels

acceptedThere is consensus among the team that this change meets the criteria for inclusionarchived due to ageThis issue has been archived; please open a new issue for any further discussioncoreRelates to ESLint's core APIs and featuresenhancementThis change enhances an existing feature of ESLint

Type

No type

Projects

Status

Complete

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions