349

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?

1
  • 1
    eslint-babel seems to ignore any .eslint-ignore files and settings. Commented May 1, 2018 at 4:14

9 Answers 9

487

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
Sign up to request clarification or add additional context in comments.

8 Comments

This 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: stackoverflow.com/a/41316801/882638
Excerpt from the ESLint documentation "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.
Is 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?
There are multiple similar posts on this. I needed: --ignore-path and/or --ignore-pattern, and I think that also accurately answers this question.
To 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: eslint.org/blog/2019/11/eslint-v6.7.0-released
|
168

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": {}
    }

4 Comments

This 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.
This initially didn’t work for me. Make sure you don’t have a .eslintrc.js in that folder with an extends: "../.eslintrc.js"!
In this method, is there any solution to turn off all eslint for the folder?
This is the actual answer I was looking for in my search.
70

In ESLint 6.7.0+ use "ignorePatterns": [].

Paths can begin with /, like /dist/** or /test*/**, but cannot begin with ./, like ./build/**.

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

2 Comments

And notice that don't start your path with ./src/foo/bar. Use src/foo/bar instead.
@Kindred Importantly, you can start with /, and probably should for clarity, just not ./ which is a dumb oversight from the designers. ./ is expected.
7

For ESLint 9+ (flat config), this has changed. You can now use either --ignore-pattern="mydir/" on the command line, or the ignores section of the flat config. The .gitignore and .eslintignore files are no longer supported.

There is a surprising effect with the ignores section of the flat config. It means two different things if it is on its own, or combined in the same block as other rules.

On its own it means 'ignore these files for everything', but in a block with other rules it means only 'ignore these files for these other changes to the rules'.

So to ignore specific rules for a specific set of directories:

eslint.config.js

const js = require('@eslint/js');

module.exports = [
  // base rules applied to everything:
  js.configs.recommended,

  // rules applied to all files except those in
  // './myFolder':
  {
    ignores: [
      // for non-global ignores a full glob pattern is required
      'myFolder/**/*',
    ],
    rules: {
        'no-use-before-define': 'error'
    }
  }
]

(for eslint.config.mjs or ES6 modules, replace the require() with import js from "@eslint/js")

Or to just ignore a directory globally for all your ESLint rules:

const js = require('@eslint/js');

module.exports = [
  {
    ignores: [
      // for global ignores a directory name works:
      'alwaysIgnoredDir/'
    ]
  },
  js.configs.recommended,
  {
    // ... other config to override recommended config
  }
]

For the flat config, instead of using 'ignores' to ignore a directory like this, you might be better specifying the opposite: which files which parts of your config should apply to, using the files property.

Comments

3

YAML version:

overrides:
  - files: *-tests.js
    rules:
      no-param-reassign: 0

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

Comments

2

In ESLint 9 flat config, you create an array of objects, where the ones at the bottom are meant to be more specific and override the previous ones.

eslint.config.js

import pluginJs from '@eslint/js';
import tjwJsdoc from 'eslint-config-tjw-jsdoc';

export default [
  // Different plugin defaults
  pluginJs.configs.recommended,
  ...tjwJsdoc,

  // General rules/settings
  {
    rules: {
      // Turn this on globally
      'one-var': ['error', 'never']
    }
  },

  // Specific overrides
  {
    files: [
      './my-sub-folder/**/*',
      './other/sub/folder/**/*'
    ],
    rules: {
      // Turn this off for just the specified subfolders
      'one-var': 'off'
    }
  }
];

1 Comment

This correct answer for 2025, it works for ESLint version 9.x. Link for documentation: eslint.org/docs/latest/use/configure/…
1

On the command line or in a package.json command, you can use eslint . --ignore-pattern 'test/*' to ignore all files in the test directory.

1 Comment

And if you need to ignore several folders, you have to repeat the option, e.g. sh eslint . --ignore-pattern 'test/*' --ignore-pattern 'backup/*'
0

As of 2025, none of the above worked for me.

here is what worked https://eslint.org/docs/latest/use/configure/ignore#ignoring-files


import { defineConfig, globalIgnores } from "eslint/config";
export default [
  globalIgnores([".next/*", "dist/*"]),  {

    files: ["**/*.ts", "**/*.tsx"],
   ... your rule
  }
]

Comments

-1

Unfortunately, for some reason ignoring a path using .eslintignore may not work. If you are using a typescript project, the best practice is to exclude those paths in tsconfig.json like this:

{
  "compilerOptions": {
    "baseUrl": ".",
    "rootDir": "src",
    "target": "es6",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "incremental": true
  },
  "include": [
    "src",
    "declaration.d.ts"
  ],
  "exclude": [
    "node_modules",
    "src/your-custom-path"
  ]
}

This will ensure that your build will be completed successfully.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.