Turning off eslint rule for a specific line

Turning off eslint rule for a specific line

In order to turn off linting rule for a particular line in JSHint we use the following rule:
/* jshint ignore:start*/
$scope.someVar = ConstructorFunction();
/* jshint ignore:end */

I have been trying to locate the equivalent of the above for eslint.


Solution 1:

You can use the single line syntax now:

var thing = new Thing(); // eslint-disable-line no-use-before-define

function Thing() {

     this.sayHello = function() { console.log("hello"); };


Or if you don’t want to have a comment on the same line with the actual code, it is possible to disable next line:

// eslint-disable-next-line no-use-before-define
var thing = new Thing();

Requested docs link: http://eslint.org/docs/user-guide/configuring.html#configuring-rules

Solution 2:

You can use the following

/*eslint-disable */

//suppress all warnings between comments

/*eslint-enable */

Which is slightly buried the “configuring rules” section of the docs;

To disable a warning for an entire file, you can include a comment at the top of the file e.g.

/*eslint eqeqeq:0*/


ESlint has now been updated with a better way disable a single line, see @goofballLogic’s excellent answer.

Solution 3:

You can also disable a specific rule/rules (rather than all) by specifying them in the enable (open) and disable (close) blocks:

/* eslint-disable no-alert, no-console */


/* eslint-enable no-alert */

via @goofballMagic’s link above: http://eslint.org/docs/user-guide/configuring.html#configuring-rules

Solution 4:

Disabling Rules with Inline Comments


/* eslint-disable no-alert, no-console */

/* eslint-disable */


/* eslint-enable */

/* eslint-disable no-alert, no-console */


/* eslint-enable no-alert, no-console */

/* eslint-disable */


/* eslint-disable no-alert */


alert('foo'); // eslint-disable-line

// eslint-disable-next-line

alert('foo'); // eslint-disable-line no-alert

// eslint-disable-next-line no-alert

alert('foo'); // eslint-disable-line no-alert, quotes, semi

// eslint-disable-next-line no-alert, quotes, semi

foo(); // eslint-disable-line example/rule-name

Solution 5:

The general end of line comment, // eslint-disable-line, does not need anything after it: no need to look up a code to specify what you wish ES Lint to ignore.

If you need to have any syntax ignored for any reason other than a quick debugging, you have problems: why not update your delint config?

I enjoy // eslint-disable-line to allow me to insert console for a quick inspection of a service, without my development environment holding me back because of the breach of protocol. (I generally ban console, and use a logging class – which sometimes builds upon console.)

Solution 6:


You can use an inline comment: // eslint-disable-next-line rule-name.


// eslint-disable-next-line no-console
console.log('eslint will ignore the no-console on this line of code');


ESLint – Disabling Rules with Inline Comments