【问题标题】:grunt whitespace/indentation errorsgrunt 空格/缩进错误
【发布时间】:2014-02-06 13:41:13
【问题描述】:

我试图修改我的 gruntfile,但我收到了大量关于我的缩进的错误。空格对于 gruntfile 总是很重要吗?解决这些错误的最佳方法是什么,计算空格?

$ grunt
Running "newer:jshint" (newer) task

Running "newer:jshint:all" (newer) task

Running "jshint:all" (jshint) task

Gruntfile.js
  line 33  col 11  Expected 'options' to have an indentation at 9 instead at 11.
  line 36  col 7   Expected '}' to have an indentation at 9 instead at 7.
  line 37  col 7   Expected 'js' to have an indentation at 9 instead at 7.
  line 38  col 9   Expected 'files' to have an indentation at 11 instead at 9.
  line 39  col 9   Expected 'tasks' to have an indentation at 11 instead at 9.
  line 40  col 9   Expected 'options' to have an indentation at 11 instead at 9.
  line 41  col 11  Expected 'livereload' to have an indentation at 13 instead at 11.
  line 42  col 9   Expected '}' to have an indentation at 11 instead at 9.
  line 43  col 7   Expected '}' to have an indentation at 9 instead at 7.
  line 43  col 9   Trailing whitespace.
  line 44  col 7   Expected 'compass' to have an indentation at 9 instead at 7.
  line 45  col 9   Expected 'files' to have an indentation at 11 instead at 9.
  line 46  col 9   Expected 'tasks' to have an indentation at 11 instead at 9.
  line 47  col 7   Expected '}' to have an indentation at 9 instead at 7.
  line 48  col 7   Expected 'gruntfile' to have an indentation at 9 instead at 7.
  line 49  col 9   Expected 'files' to have an indentation at 11 instead at 9.
  line 50  col 7   Expected '}' to have an indentation at 9 instead at 7.
  line 51  col 7   Expected 'livereload' to have an indentation at 9 instead at 7.
  line 52  col 9   Expected 'options' to have an indentation at 11 instead at 9.
  line 53  col 11  Expected 'livereload' to have an indentation at 13 instead at 11.
  line 54  col 9   Expected '}' to have an indentation at 11 instead at 9.
  line 55  col 9   Expected 'files' to have an indentation at 11 instead at 9.
  line 56  col 11  Expected '<%= yeoman.app %>/{,*/}*.html' to have an indentation at 13 instead at 11.
  line 57  col 11  Expected '.tmp/styles/{,*/}*.css' to have an indentation at 13 instead at 11.
  line 58  col 11  Expected '<%= yeoman.app %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}' to have an indentation at 13 instead at 11.
  line 59  col 9   Expected ']' to have an indentation at 11 instead at 9.
  line 60  col 7   Expected '}' to have an indentation at 9 instead at 7.
  line 61  col 5   Expected '}' to have an indentation at 7 instead at 5.
  line 64  col 5   Expected 'connect' to have an indentation at 7 instead at 5.
  line 65  col 7   Expected 'options' to have an indentation at 9 instead at 7.
  line 66  col 9   Expected 'port' to have an indentation at 11 instead at 9.
  line 68  col 9   Expected 'hostname' to have an indentation at 11 instead at 9.
  line 69  col 9   Expected 'livereload' to have an indentation at 11 instead at 9.
  line 70  col 7   Expected '}' to have an indentation at 9 instead at 7.
  line 71  col 7   Expected 'livereload' to have an indentation at 9 instead at 7.
  line 72  col 9   Expected 'options' to have an indentation at 11 instead at 9.
  line 73  col 11  Expected 'open' to have an indentation at 13 instead at 11.
  line 74  col 11  Expected 'base' to have an indentation at 13 instead at 11.
  line 75  col 13  Expected '.tmp' to have an indentation at 15 instead at 13.
  line 76  col 13  Expected '<%= yeoman.app %>' to have an indentation at 15 instead at 13.
  line 77  col 11  Expected ']' to have an indentation at 13 instead at 11.
  line 78  col 9   Expected '}' to have an indentation at 11 instead at 9.
  line 79  col 7   Expected '}' to have an indentation at 9 instead at 7.
  line 80  col 7   Expected 'test' to have an indentation at 9 instead at 7.
  line 81  col 9   Expected 'options' to have an indentation at 11 instead at 9.
  line 82  col 11  Expected 'port' to have an indentation at 13 instead at 11.
  line 83  col 11  Expected 'base' to have an indentation at 13 instead at 11.
  line 84  col 13  Expected '.tmp' to have an indentation at 15 instead at 13.
  line 85  col 13  Expected 'test' to have an indentation at 15 instead at 13.
  line 86  col 13  Expected '<%= yeoman.app %>' to have an indentation at 15 instead at 13.
  line 86  col 13  Too many errors. (21% scanned).

✖ 51 problems

Warning: Task "jshint:all" failed. Use --force to continue.

【问题讨论】:

  • 这只是 jshint 抱怨你的缩进没有像它想要的那样整齐地格式化。使其停止产生这些错误的唯一方法是修复空白并继续使用正确的空白以避免再次发生,或者可以将 jshint 设置为忽略混乱的空白,但我不知道该怎么做.
  • 所以这是一个特定于 jshint 的东西。 grunt 不关心空格,对吧?
  • 我不这么认为。我总是遇到这样的错误,因为我使用制表符并忘记了我项目中的其他人使用空格,但一切仍然运行。
  • 您可以告诉 jshint 任务忽略缩进错误,方法是从其配置中的 options 对象中删除 "indent"。如果您从 Gruntfile 发布 jshint 配置代码,我可以为您提供更多帮助。您可以阅读有关 JSHint 选项的更多信息here
  • +1 仅用于修复空白。这一切都归结为代码的一致性。我会说,不要告诉 jshint 忽略空格……如果你真的不希望它检查 Gruntfile 中的缩进,然后告诉 jshint 忽略 Gruntfile。

标签: gruntjs jshint


【解决方案1】:

注释掉 .jshintrc 文件或 package.json 中的 'indent' 属性。对“缩进”一词进行全局查找应该可以找到。

我发现空白确实增加了代码的可读性,尤其是 JS。如此之多,以至于我根本不知道它应该被 linted,特别是因为它对 JS 的执行方式没有影响。

【讨论】:

    【解决方案2】:

    您可能会从“lint”中得到缩进错误。

    如果您有一个“eslintrc”文件,您可以删除以下行 来自规则键值对

    ' 缩进:[2, 2, {"SwitchCase": 1}],'

    【讨论】:

    • 我发现缩进在我们代码的某些部分运行良好,但有些部分很奇怪。所以这个技巧运作良好。通过考试当然很好。
    猜你喜欢
    • 2018-09-03
    • 1970-01-01
    • 1970-01-01
    • 2017-08-30
    • 1970-01-01
    • 2014-08-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多