- Start Date: 2019-05-12
- RFC PR: #20
- Authors: Toru Nagashima (@mysticatea)
This proposal adds the ability to specify additional target files into configuration files. This enhancement will solve the pain that people have to use the --ext
option with wanted file extensions even if they use plugins which support additional file types.
People have to use the --ext
option or glob patterns to check wanted files even if they use plugins which support additional file types.
plugins:
- markdown
- html
- "@typescript-eslint"
- react
- vue
# ESLint checks only `*.js`.
eslint src docs
# Needs `--ext` option
eslint src docs --ext .js,.md,.html,.ts,.jsx,.tsx,.vue
However, using plugins which support additional file types is the intention that wants to check those files. The requirement of redundant CLI options is not reasonable.
Per "Related Discussions" section, this is very regularly requested; I want to configure additional target files with .eslintrc
.
This proposal enhances overrides
property of the config file.
- If a config file in a directory has
overrides
property, ESLint checks the files which are matched by any of override entries (i.e.,files
/excludedFiles
criteria) additionally in the directory.- If any of
files
value of an override entry ended with*
, this enhancement doesn't use the entry in order to avoid checking too many kinds of files.
- If any of
- This enhancement affects only the case where a directory path is provided on the CLI. If people provide glob patterns on the CLI, ESLint behaves the same as currently.
- The
--ext
option precedences this enhancement. If the--ext
option was given, this enhancement is disabled. So people can use the current behavior by--ext .js
. - The ignoring configuration (
.eslintignore
) precedences this enhancement. If.eslintignore
contains the additional target files, ESLint just ignores those as same as currently.
The overrides
property means that people intend to check those files. So this behavior is intuitive.
💡 Example:
overrides:
- files: "*.ts"
parser: "@typescript-eslint/parser"
- files: "tests/**/*"
env: { mocha: true } With the above config, |
If a code block that processors extracted has the virtual filename, ESLint filters the file extension of the virtual filename with --ext
option. This enhancement affects to that check. ESLint lints the code block if the overrides
matches the virtual filename.
This enhancement doesn't affect legacy file extension processors. This means that plugins
property in config files never changes the kinds of target files.
On the other hand, extends
property in config files can change the kinds of target files by the overrides
property in the shareable configs.
- For files, we can add the check to lib/cli-engine/file-enumerator.js#L410.
- For code blocks, we can add the check to lib/cli-engine/cli-engine.js#L248.
This enhancement needs migration guide because of a breaking change.
- If your config contains
overrides
property,eslint
command with directory paths lints the files which are matched automatically. This may increase errors of your command.
If you don't want to add file types to check, please use glob patterns instead of directory paths or--ext .js
option.
This enhancement, so it needs to update some documents.
- In the description of
--ext
CLI option, it should say that your config file may add file types automatically. - In the description of
overrides
property, it should say that theoverrides[].files
property adds target files automatically.
- This is a breaking change.
- Implicit behavior may be confusing people.
In the following situation, eslint
command increases errors.
- Their configuration has
overrides
property (withfiles
property which doesn't end with*
). - Their
eslint
command is using directory paths without--ext
option.
I guess that the impact is limited because people use --ext
option or glob patterns if they use configuration which affects files other than *.js
.
- To add
extensions
property that behaves as same as--ext
option. Explicit reduces confusion. However, plugins and shareable configs cannot add theextensions
property without the breaking change that drops old ESLint support.
- eslint/eslint#801 - Configurable Extension Filter
- eslint/eslint#1674 - Allow setting file extensions in .eslintrc
- eslint/eslint#2274 - Configure file extensions in .eslintrc
- eslint/eslint#2419 - Allow configuration of default JS file types
- eslint/eslint#7324 - File extensions in .eslintrc
- eslint/eslint#8399 - Add .jsx to the default --ext extensions list
- eslint/eslint#10828 - Support specifying extensions in the config
- eslint/eslint#11223 - Add --ext to
eslintrc
or other config files