【问题标题】:Comma first validation with no space逗号第一个验证,没有空格
【发布时间】:2013-02-12 19:31:37
【问题描述】:

我正在为我正在编写的 JavaScript 套件构建 JSHint 集。我写对象的习惯如下:

var obj = {
   hello: 'World'
  ,foo: 'Bar'
  ,name: 'Dave'
};

我使用 Grunt 和 grunt-contrib-jshint 通过以下选项运行验证:

  • 浏览器:是的
  • eqeqeq: 假
  • laxcomma: true
  • 白色:真
  • 缩进:2

当我运行grunt jshint 时,我得到一个错误,即逗号后面应该有一个空格。如何忽略这个空间?

【问题讨论】:

  • 我认为这目前是不可能的。您实际上需要禁用white 规则(即white: false)。但如果你这样做,indent 规则将不再被检查。不幸的是,这两个设置绑定在一起。
  • 这种风格让我感到害怕和困惑。不是为了发动战争,而是亲爱的上帝……为什么?
  • @carbontax 一方面,它使注释对象字段变得更加容易......双//,你就完成了......不用担心悬空的逗号。
  • @carbontax 除了 dancrumb 的评论,在这种格式中查找缺少的逗号也容易得多。只需扫描二维码即可轻松找到。
  • 好吧,这些其实都是很好的理由。我不会开始这样做,但我明白你的意思。

标签: jshint gruntjs


【解决方案1】:

可以按照doc中写的方式忽略具体的错误; https://github.com/gruntjs/grunt-contrib-jshint 这是一个报价

忽略特定警告

如果您想忽略特定警告:

[L24:C9] W015:预期 '}' 在 11 处而不是 9 处有缩进。 您可以通过将 - 作为选项添加到警告 ID 来切换它:

grunt.initConfig({
  jshint: {
    ignore_warning: {
      options: {
        '-W015': true,
      },
      src: ['**/*.js'],
    },
  },
});

更新。 另外,我正在使用这样的配置并且没有逗号错误

,defaultOptions = {
            curly: true,
            eqeqeq: true,
            immed: true,
            latedef: 'nofunc',
            newcap: true,
            noarg: true,
            nonew: true,
            sub: true,
            undef: true,
            boss: true,
            eqnull: true,
            camelcase: true,
            quotmark: true,

            // lax
            laxcomma: true,

            // environment
            browser: true,
            devel: true,
            jquery: true,
        }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-03
    • 1970-01-01
    • 1970-01-01
    • 2020-02-21
    • 1970-01-01
    • 2018-10-17
    相关资源
    最近更新 更多