How to disable ESLint rule via JavaScript comment

AD, please don't block.

Having recently switched to ESLint, I often find myself googling for how to disable a rule via JavaScript comment.

Hope writing this will help me to memorize the syntax, I’ll bookmark this page otherwise :smile:

ESLint provides both a way to disable, both to enable the linting via comments.

/* eslint-disable */

!function(){
  // no lint here!
}()

/* eslint-enable */

Not surprisingly, applying eslint-disable will disable the linting on the whole file, if then no eslint-enable is used.

However most of the time, what I need is to disable the linting for a specific rule, on a specific line; in this case I use one of the following methods:

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

or

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

Omitting the name of the rule it’s possible to disable the linting completely for a specific line.