78

I'm looking for a way for jscs (JavaScript Code Style) do the same behavior as jshint to ignore certain rules per file with a comment at the top, or per line, with a start and end comment.

jshint example to ignore a specific rule in the file :

/* jshint undef: false */

jshint example to ignore a specific rule in a block:

// Code here will be linted with JSHint.
/* jshint ignore:start */
// Code here will be linted with ignored by JSHint.
/* jshint ignore:end */
fernandopasik
  • 9,565
  • 7
  • 48
  • 55

3 Answers3

118

This is available since jscs 1.6.0

For a file scope:

Put this on top of the file to ignore all rules

// jscs:disable

Put this on top of the file to ignore a specific rule:

// jscs:disable specificRule

Also for ignoring the whole file you can add it to .jscsrc, adding an entry to excludeFiles.

For block scope:

To ignore all rules

// Code here will be linted with JSCS.
// jscs:disable
// Code here will be ignored by JSCS.
// jscs:enable

To ignore a specific rule:

// Code here will be linted with JSCS.
// jscs:disable specificRule
// Code here will be ignored by JSCS.
// jscs:enable specificRule
Community
  • 1
  • 1
fernandopasik
  • 9,565
  • 7
  • 48
  • 55
  • I assume ignoring all rules in a codeblock would be ```//jscs:disable // Code here will be ignored by JSCS. //jscs:enable``` – Olga Dec 23 '14 at 19:49
  • 2
    Just a quick note on file scope. You can also ignore files/directories by creating `.jscsrc` file and adding `excludeFiles` key with the name of the file/directories as value. There has been some talks on having `.jscsignore` file but it will be coming in 2.0, I believe. – shriek Aug 16 '15 at 02:00
  • 1
    add space after `//` to not trigger the `requireSpaceAfterLineComment` rule like @AndrewAnthonyGerst suggests – Joe B Aug 21 '15 at 16:32
15

to disable a particular rule for just the one line

// jscs:ignore maximumLineLength
Nazik
  • 8,696
  • 27
  • 77
  • 123
umasudhan
  • 177
  • 1
  • 7
3

To ignore the whole file just add the following line at the top of the file.

// jscs:disable
Andrew
  • 3,733
  • 1
  • 35
  • 36