Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabling JSHint indentation check only for a specific file

I use jshint with the indent enforcing option enabled and set to 4, and would like to keep it that way for most files in the codebase.

In one specific file though, I would like to disable this check.

I tried adding the jshint comment at the top but that didn't work:

/* jshint indent: false */

This is too bad because this syntax works for other options. For example, I can disable the camelcase enforcing option with the following:

/* jshint camelcase: false */

How can I do this?

Some answers suggest that indent automatically enables the white option, but I tried the following and it didn't work either:

/* jshint white: false */
like image 503
St Kiss Avatar asked Apr 05 '13 00:04

St Kiss


1 Answers

This is currently not possible. JSHint validates the value of the indent option as follows:

if (typeof val !== "number" || !isFinite(val) || val <= 0 || Math.floor(val) !== val) {
    error("E032", nt, g[1].trim());
    return;
}

As you've noticed in the comments on your question, this will raise an error if the value is not an integer greater than 0. It doesn't actually put a maximum limit on that integer though.

Depending on how you are running JSHint it may be possible to override your default configuration for files that don't care about indentation. For example, with the JSHint Grunt task you can do this:

grunt.initConfig({
    jshint: {
        options: {
            /* Don't set indent here */
        },
        uses_defaults: ["somefile.js"],
        with_overrides: {
            options: {
                indent: 4
            },
            files: {
                src: ["someotherfile.js"]
            }
        }
    }
});

Update

I have opened a pull request with a suggested fix for this issue, so keep an eye on that and we will see if this functionality is something the JSHint team want to add.

like image 131
James Allardice Avatar answered Nov 11 '22 18:11

James Allardice