20

For example this, at the top of a node.js source file:

#!/usr/bin/env node

...or unused local variables, etc.

Shazron
  • 2,446
  • 1
  • 18
  • 30
  • related to https://stackoverflow.com/questions/27732209/turning-off-eslint-rule-for-a-specific-line - many of the responses there should work. The docs seem to cover most of what's listed there as well though. https://eslint.org/docs/user-guide/configuring#disabling-rules-only-for-a-group-of-files – Mugshep Nov 26 '19 at 12:59

5 Answers5

40

Late to the party but in VSCode you can write // @ts-ignore just before the line you want to ignore.

enter image description here enter image description here

It is important to notice that it will just ignore the line after the declaration.

enter image description here

There is more info about it in the official documentation.

distante
  • 6,438
  • 6
  • 48
  • 90
  • 2
    This works in Visual Studio 2019 as well. use `// @ts-ignore` for an individual line of code, or `// @ts-nocheck` to exclude the entire file. – Sadra Abedinzadeh Apr 23 '21 at 21:55
5

For unused local variable, you can configure the user or the workspace settings.

From the preference menu item, choose user/workspace settings:

// Place your settings in this file to overwrite default and user settings.
{
    // Unused local variable.
    "javascript.validate.lint.unusedVariables": "ignore"
}

As for #!/usr/bin/env node what is the undesirable behavior that you want disable?

Sofian Hnaide
  • 2,284
  • 16
  • 13
  • 1
    Thanks - I know about the global options, just want to disable it on a line by line basis. The linter is complaining about the shebang which is valid for node scripts (but not valid js of course). – Shazron May 04 '15 at 03:45
3

You can tell jshint to ignore lines, or just certain rules. Here's how to ignore a line, from http://jshint.com/docs/

// Code here will be linted with JSHint.
/* jshint ignore:start */
// Code here will be ignored by JSHint.
/* jshint ignore:end */

Now, I'm just assuming that Code honors these directive.

AJ Morris
  • 1,099
  • 2
  • 10
  • 19
  • Thanks, tried it (as well as jslint options), doesn't seem to work. – Shazron May 04 '15 at 03:52
  • Finally at a real computer, and I tried, too. Indeed, those directives are ignored by the builtin javascript linter. I tried ignore syntax from several linters, and they all failed. `/*jshint ignore:start */ /*jsl:ignore */ /*ignore jslint start*/ /*eslint-disable */ /*jslint vars: false */ // jshint ignore:line` This leads me to believe that VSCode is doing its own thing. So, it probably needs to go to UserVoice here: https://visualstudio.uservoice.com/forums/293070-visual-studio-code – AJ Morris May 04 '15 at 12:03
3

You can select suggestion from PROBLEMS by hovering over the red x in the circle and then click on the lamp :

enter image description here enter image description here

Radi Totev
  • 91
  • 7
  • Just in case, this is for ESLint extension, which is not currently built-in. Related: https://eslint.org/ – Artfaith Dec 26 '21 at 13:08
0

You can do this via inline - e.g.: // eslint-disable-next-line [RULE] on the line prior to the line of code you want it to ignore. The RULE is optional, and will tell it to ignore a specific rule; if you don't specify one, it will tell it to ignore all rules.

Lots of other options available - see the docs for more detail: https://eslint.org/docs/user-guide/configuring#disabling-rules-with-inline-comments.

Mugshep
  • 788
  • 1
  • 9
  • 18