Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 399
runtimeZero Avatar asked Jan 01 '15 15:01

runtimeZero


People also ask

How do I disable ESLint for multiple lines?

For those converting eslint-disable-next-line to eslint-disable (for multiple lines), remember two things. 1. /* */ instead of // 2. It's eslint-disable and not eslint-disable-next-line . Just reiterating coz I did the same and had to search many more things due to the 2nd point.

How do you exclude something from ESLint?

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 ). Excerpt from the ESLint documentation "In addition to any patterns in a .

How do I turn off the lint rule?

In addition to global configuration, you may also enable/disable linting for a subset of lint rules within a file with the following comment rule flags: /* tslint:disable */ - Disable all rules for the rest of the file. /* tslint:enable */ - Enable all rules for the rest of the file.


2 Answers

To disable next line:

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

Or use the single line syntax:

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

See the eslint docs

like image 155
goofballLogic Avatar answered Oct 15 '22 21:10

goofballLogic


Update

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

Old answer:

You can use the following

/*eslint-disable */  //suppress all warnings between comments alert('foo');  /*eslint-enable */ 

Which is slightly buried in 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*/ 
like image 30
Nick Tomlin Avatar answered Oct 15 '22 20:10

Nick Tomlin