Search code examples
javascriptjshintjscs

JSHint and JSCS inline ignore for the same next line


Is it possible to somehow make JSHint and JSCS play along nicely on inline ignore for the same next line?

I would like to do something like:

/* jshint camelcase: false, jscs requireCamelCaseOrUpperCaseIdentifiers: false */

I tried a couple of different variations of that (separate "comment blocks", semi-colon in between, different lines for ignore), but couldn't make it work. Perhaps I'm missing something obvious? Or is it simply not possible? Thnx.


Solution

  • JSHint doesn't allow disabling a specific rule for a single line, but it is possible to disable all validations for a line:

    var do_something; /* jshint ignore:line */
    

    For JSCS, the syntax to enable/disable a single rule is like this:

    // jscs:disable requireCamelCaseOrUpperCaseIdentifiers
    ...
    // jscs:enable requireCamelCaseOrUpperCaseIdentifiers
    

    Put together, to disable both JSHint and JSCS validation for a particular line, one would use a combination of the comments above:

    // jscs:disable requireCamelCaseOrUpperCaseIdentifiers
    var var_name_with_underscores; /* jshint ignore:line */
    // jscs:enable requireCamelCaseOrUpperCaseIdentifiers
    

    If the non-camelcase identifier is used in multiple lines inside a block (as is normally the rule), it may be necessary to enclose the whole function in comments.

    // jscs: disable requireCamelCaseOrUpperCaseIdentifiers
    /* jshint ignore:start */
    function foo()
    {
        var var_name_with_underscores;
        ...
        var_name_with_underscores = 123;
        ...
    }
    /* jshint ignore:end */
    // jscs: enable requireCamelCaseOrUpperCaseIdentifiers