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.


You can use the single line syntax now:

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

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


You can use the following

/*eslint-disable */

//suppress all warnings between comments
alert('foo');

/*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 eg

/*eslint eqeqeq:0*/

Update

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


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 */

alert('foo');
console.log('bar');

/* eslint-enable no-alert */

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

链接地址: http://www.djcxy.com/p/73410.html

上一篇: 无法在流星公开目录中查看新文件

下一篇: 关闭特定线条的eslint规则