Is there a way to disable specific rules for a folder? For example, I don't want to have required JSDoc comments for all my test files in the test
folder. Is there a way to do this?

- 4,566
- 3
- 16
- 27
-
1eslint-babel seems to ignore any .eslint-ignore files and settings. – ivanixmobile May 01 '18 at 04:14
4 Answers
To ignore some folder from eslint rules we could create the file .eslintignore
in root directory and add there the path to the folder we want omit (the same way as for .gitignore
).
Here is the example from the ESLint docs on Ignoring Files and Directories:
# path/to/project/root/.eslintignore
# /node_modules/* and /bower_components/* in the project root are ignored by default
# Ignore built files except build/index.js
build/*
!build/index.js

- 33,433
- 13
- 94
- 101

- 5,159
- 1
- 20
- 15
-
98This solution doesn't really answer the original question, which asks how to disable *specific* rules for a particular directory. Here you're disabling *all* rules for the given directories. Better answer is here: https://stackoverflow.com/a/41316801/882638 – ericgio Apr 10 '18 at 22:50
-
5Excerpt from the [ESLint documentation](https://eslint.org/docs/user-guide/configuring#ignoring-files-and-directories) "_In addition to any patterns in a .eslintignore file, ESLint always ignores files in /node_modules/* and /bower_components/*._" So there's no need to add `/node_modules`, `/dist` alone is enough to exclude the both of the directories. Also glob pattern is supported whilst specifying (sub)directories. – ozanmuyes Aug 02 '18 at 12:43
-
-
5Is there anyway of configuring which directories to ignore in the `.eslintrc.json` configuration file itself so we don't need yet another .estlint file and we can inherit ignore values from an `eslint-config-myconfig` shared configuration? – Joshua Pinter Mar 13 '19 at 17:39
-
1There are multiple similar posts on this. I needed: `--ignore-path` and/or `--ignore-pattern`, and I think that _also_ accurately answers this question. – Neil Gaetano Lindberg Jul 05 '19 at 17:02
-
Beware running `eslint src/**` because it somehow bypassed my `.eslinignore` file and caused an error because eslint was trying to apply its linter in subfolders where there was no files, and was crashing because of that. - Fixed it by running `eslint src/` instead – Vadorequest Dec 10 '19 at 17:28
-
3To answer my own comment from a year ago, as of ESLint 6.7.0+, you can now use a top-level attribute `ignorePatterns` to provide an Array of patterns to ignore. Read the release announcement here: https://eslint.org/blog/2019/11/eslint-v6.7.0-released – Joshua Pinter May 11 '20 at 03:48
The previous answers were in the right track, but the complete answer for this is going to be about disabling rules only for a group of files, there you'll find the documentation needed to disable/enable rules for certain folders (Because in some cases you don't want to ignore the whole thing, only disable certain rules). Example:
{
"env": {},
"extends": [],
"parser": "",
"plugins": [],
"rules": {},
"overrides": [
{
"files": ["test/*.spec.js"], // Or *.test.js
"rules": {
"require-jsdoc": "off"
}
}
],
"settings": {}
}

- 19,951
- 7
- 52
- 82

- 2,561
- 1
- 14
- 21
-
11This answer is better because you can turn off a _specific_ rule for a given directory. Instead of just turning off all rules for a directory. – Storm Muller Sep 10 '19 at 10:38
-
6This initially didn’t work for me. Make sure you don’t have a `.eslintrc.js` in that folder with an `extends: "../.eslintrc.js"`! – Florian Wendelborn Feb 23 '20 at 17:09
-
4In this method, is there any solution to turn off all eslint for the folder? – Anand Feb 10 '21 at 11:58
-
4
In ESLint 6.7.0+ use "ignorePatterns": [].
You can tell ESLint to ignore specific files and directories using ignorePatterns in your config files.
example of .eslintrc.js
module.exports = {
env: {
// ...
},
extends: [
// ...
],
parserOptions: {
// ...
},
plugins: [
// ...
],
rules: {
// ...
},
ignorePatterns: ["src/test/*"], // <<< ignore all files in test folder
};
Or you can ignore files with some extension:
ignorePatterns: ['**/*.js']
You can read the user-guide doc here.
https://eslint.org/docs/user-guide/configuring/ignoring-code

- 14,110
- 21
- 98
- 160

- 1,226
- 11
- 13
-
1And notice that don't start your path with `./src/foo/bar`. Use `src/foo/bar` instead. – Kindred May 03 '22 at 01:53
YAML version :
overrides:
- files: *-tests.js
rules:
no-param-reassign: 0
Example of specific rules for mocha tests :
You can also set a specific env for a folder, like this :
overrides:
- files: test/*-tests.js
env:
mocha: true
This configuration will fix error message about describe
and it
not defined, only for your test folder:
/myproject/test/init-tests.js
6:1 error 'describe' is not defined no-undef
9:3 error 'it' is not defined no-undef

- 1
- 1

- 12,494
- 5
- 50
- 73