Turning off eslint rule for a specific file

Turning off eslint rule for a specific file

Is it possible to turn off the eslint rule for the whole file? Something such as:
// eslint-disable-file no-use-before-define

(Analogous to eslint-disable-line.) It happens to me quite often, that in a certain file, I’m breaking a specific rule on many places which is considered OK for that file, but I don’t want to disable the rule for the whole project nor do I want to disable other rules for that specific file.


Solution 1:

You can turn off/change a particular rule for a file by putting the configurations at the top of the file.

/* eslint no-use-before-define: 0 */  // --> OFF


/* eslint no-use-before-define: 2 */  // --> ON

More info: http://eslint.org/docs/user-guide/configuring.html#configuring-rules

Solution 2:

Just place /* eslint-disable */ at the top of the file

Check: https://evanhahn.com/disable-eslint-for-a-file/

Solution 3:

You can tell ESLint to ignore specific files and directories by creating an .eslintignore file in your project’s root directory:



The ignore patterns behave according to the .gitignore specification.
(Don’t forget to restart your editor.)

Related:  Fancybox is not a function

Solution 4:

You can also disable/enable a rule like this:

/* eslint-disable no-use-before-define */
... code that violates rule ...
/* eslint-enable no-use-before-define */

Similar to eslint-disable-line as mentioned in the question. It might be a better method if you don’t want to have to restore a complicated rule configuration when re-enabling it.

Solution 5:

To temporarily disable rule warnings in your file, use block comments in the following format:

/* eslint-disable */

This will disable ESLint until the

/* eslint-enable */

comment is reached.

You can read more about this topic here.

Solution 6:

Accepted answer didn’t work for me (maybe a different version of eslint…? I’m using eslint v3.19.0), but did find a solution with the following…

Place the following on the top of your file

/* eslint-disable no-use-before-define */

This will disable the rule for the entire file