最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Disabling JSHint indentation check only for a specific file - Stack Overflow

programmeradmin4浏览0评论

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 ment 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 */

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 ment 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 */
Share edited Apr 5, 2013 at 2:14 skiss asked Apr 5, 2013 at 0:28 skissskiss 2133 silver badges10 bronze badges 3
  • When I played around with it on their site it indicated that it expects a small integer for the indent input. So my guess is that there is no way to override a default. You may want to open an issue on their github page: github./jshint/jshint/issues – Ben McCormick Commented Apr 5, 2013 at 1:58
  • of course if you just want to specify a different specific indentation for that page, you can always set that directly. Just doesn't seem to be a way to ignore it pletely. Depending on what plugin/mand line tool you're using, you may also be able to get JSHint to ignore the file pletely or reference a different configuration file for this file. – Ben McCormick Commented Apr 5, 2013 at 2:01
  • Yes that is also what I saw, jshint was expecting an int after indent. – skiss Commented Apr 5, 2013 at 2:05
Add a ment  | 

1 Answer 1

Reset to default 3

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 ments 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.

发布评论

评论列表(0)

  1. 暂无评论