DEV Community

loading...
Cover image for How to disable ESLint for some lines, files, or folders

How to disable ESLint for some lines, files, or folders

coderslang profile image Coderslang: Become a Software Engineer Originally published at learn.coderslang.com on ・2 min read

ESLint - is a very convenient tool to control code quality. But, sometimes it’s necessary to disable it. In this tutorial, you’ll learn how to turn off ESLint for certain directories and files.

General case

For demo purposes imagine you have a file with a couple of console.log() statements that ESLint doesn’t like.

To temporarily turn off ESLint, you should add a block comment /* eslint-disable */ before the lines that you’re interested in:

/* eslint-disable */
console.log('JavaScript debug log');
console.log('eslint is disabled now');
Enter fullscreen mode Exit fullscreen mode

Once ESLint sees the /* eslint-disable */ comment it turns off the parsing.

To turn it back on you should use the block comment /* eslint-enable */.

/* eslint-disable */
console.log('JavaScript debug log');
console.log('eslint is disabled now');
/* eslint-enable */
Enter fullscreen mode Exit fullscreen mode

Now ESLint is enabled once again and will parse the rest of the file normally.

Disabling specific ESLint rules

To disable not all, but only some specific ESLint rules, you should list them in the same comment. Split the rules with commas:

/* eslint-disable no-console, no-control-regex*/
console.log('JavaScript debug log');
console.log('eslint is disabled now');
Enter fullscreen mode Exit fullscreen mode

The rules eslint-disable and eslint-enable should always be placed in the block comments. This doesn’t work:

// eslint-disable no-console, no-control-regex
console.log('JavaScript debug log');
console.log('eslint is disabled now');
Enter fullscreen mode Exit fullscreen mode

Ignore a single line

To disable ESLint for a single line, there are 2 options.

To turn off linter for the current line, you add a comment after that line:

console.log('eslint is disabled for the current line'); // eslint-disable-line
Enter fullscreen mode Exit fullscreen mode

To turn off the linter for the next line, you place the comment before the line that you want to ignore:

// eslint-disable-next-line
console.log('eslint is disabled for the current line');
Enter fullscreen mode Exit fullscreen mode

Ignore multiple files or folders

To turn off ESLint in the whole file, you can add /* eslint-disable */ in the first line of that file.

Alternatively, you can create a file .eslintignore in the root catalog. The format of this file matches the format of .gitignore and you can add there not only files but directories too.

build/*.js
config/*.js
components/bar/*.js
Enter fullscreen mode Exit fullscreen mode

Learn Full Stack JavaScript

Discussion (0)

Forem Open with the Forem app