You can configure ESLint to ignore certain files and directories while linting by specifying one or more glob patterns. You can ignore files in the following ways:
ignorePatternsto a configuration file.
- Create a dedicated file that contains the ignore patterns (
ignorePatterns in Config Files
You can tell ESLint to ignore specific files and directories using
ignorePatterns in your config files.
ignorePatterns patterns follow the same rules as
.eslintignore. Please see the
.eslintignore file documentation to learn more.
"ignorePatterns": ["temp.js", "**/vendor/*.js"],
- Glob patterns in
ignorePatternsare relative to the directory that the config file is placed in.
- You cannot write
- Patterns defined in
.eslintignoretake precedence over the
ignorePatternsproperty of config files.
If a glob pattern starts with
/, the pattern is relative to the base directory of the config file. For example,
lib/.eslintrc.json matches to
lib/foo.js but not
If a config is provided via the
--config CLI option, the ignore patterns that start with
/ in the config are relative to the current working directory rather than the base directory of the given config. For example, if
--config configs/.eslintrc.json is present, the ignore patterns in the config are relative to
. rather than
You can tell ESLint to ignore specific files and directories by creating a
.eslintignore file in your project’s root directory. The
When ESLint is run, it looks in the current working directory to find a
.eslintignore file before determining which files to lint. If this file is found, then those preferences are applied when traversing directories. Only one
.eslintignore file can be used at a time, so
.eslintignore files other than the one in the current working directory are not used.
Globs are matched using node-ignore, so a number of features are available:
- Lines beginning with
#are treated as comments and do not affect the ignore patterns.
- Paths are relative to the current working directory. This is also true of paths passed in via the
- Lines preceded by
!are negated patterns that re-include a pattern that was ignored by an earlier pattern.
- Ignore patterns behave according to the
Of particular note is that like
.gitignore files, all paths used as patterns for both
--ignore-pattern must use forward slashes as their path separators.
.gitignore’s specification for further examples of valid syntax.
In addition to any patterns in the
.eslintignore file, ESLint always follows a couple of implicit ignore rules even if the
--no-ignore flag is passed. The implicit rules are as follows:
- dot-files (except for
.eslintrc.*) as well as dot-folders and their contents are ignored.
There are also some exceptions to these rules:
If the path to lint is a glob pattern or directory path and contains a dot-folder, all dot-files and dot-folders are linted. This includes dot-files and dot-folders that are buried deeper in the directory structure.
eslint .config/would lint all dot-folders and dot-files in the
.configdirectory, including immediate children as well as children that are deeper in the directory structure.
If the path to lint is a specific file path and the
--no-ignoreflag has been passed, ESLint would lint the file regardless of the implicit ignore rules.
eslint .config/my-config-file.js --no-ignorewould cause
my-config-file.jsto be linted. It should be noted that the same command without the
--no-ignoreline would not lint the
Allowlist and denylist rules specified via
.eslintignoreare prioritized above implicit ignore rules.
For example, in this scenario,
.build/test.jsis the desired file to allowlist. Because all dot-folders and their children are ignored by default,
.buildmust first be allowlisted so that eslint becomes aware of its children. Then,
.build/test.jsmust be explicitly allowlisted, while the rest of the content is denylisted. This is done with the following
# Allowlist 'test.js' in the '.build' folder
# But do not allow anything else in the '.build' folder to be linted
--ignore-patternis also equivalent:
eslint --ignore-pattern '!.build' --ignore-pattern '.build/*' --ignore-pattern '!.build/test.js' parent-folder/
Using an Alternate File
If you’d prefer to use a different file than the
.eslintignore in the current working directory, you can specify it on the command line using the
--ignore-path option. For example, you can use
.jshintignore file because it has the same format:
eslint --ignore-path .jshintignore file.js
You can also use your
eslint --ignore-path .gitignore file.js
Any file that follows the standard ignore file format can be used. Keep in mind that specifying
--ignore-path means that the existing
.eslintignore file is not used. Note that globbing rules in
.eslintignore follow those of
Using eslintIgnore in package.json
.eslintignore file is not found and an alternate file is not specified, ESLint looks in
package.json for the
eslintIgnore key to check for files to ignore.
"eslintIgnore": ["hello.js", "world.js"]
Ignored File Warnings
When you pass directories to ESLint, files and directories are silently ignored. If you pass a specific file to ESLint, then ESLint creates a warning that the file was skipped. For example, suppose you have an
.eslintignore file that looks like this:
And then you run:
You’ll see this warning:
0:0 warning File ignored because of a matching ignore pattern. Use "--no-ignore" to override.
✖ 1 problem (0 errors, 1 warning)
This message occurs because ESLint is unsure if you wanted to actually lint the file or not. As the message indicates, you can use
--no-ignore to omit using the ignore rules.
Consider another scenario where you want to run ESLint on a specific dot-file or dot-folder, but have forgotten to specifically allow those files in your
.eslintignore file. You would run something like this:
You would see this warning:
0:0 warning File ignored by default. Use a negated ignore pattern (like "--ignore-pattern '!
'") to override
✖ 1 problem (0 errors, 1 warning)
This message occurs because, normally, this file would be ignored by ESLint’s implicit ignore rules (as mentioned above). A negated ignore rule in your
.eslintignore file would override the implicit rule and reinclude this file for linting. Additionally, in this case,
--no-ignore could be used to lint the file as well.