【问题标题】:JSHint behave differently in Webstorm and GruntJSHint 在 Webstorm 和 Grunt 中的行为不同
【发布时间】:2014-03-27 07:56:02
【问题描述】:

我使用 angular-generator 使用 Grunt 创建了一个新服务,然后使用 WebStorm Ctrl+ALT+L kbd> 因为制表符/空格似乎有所不同。

然后当使用 Grunt 并且任务 JSHint 抱怨我得到以下错误:

app/scripts/services/poteservice.js
  line 11  col 13  Expected '}' to have an indentation at 15 instead at 13.
  line 14  col 13  Expected '}' to have an indentation at 15 instead at 13.

另一个奇怪的问题是我发现我可以在 WebStorm 中启用 JSHint,但随后我遇到了类似的问题

 JSHINT: angular not defined

    and

 Use the function form of use strict

任何人都知道如何让每个人都很好地一起玩,例如 WebStorm 和 Grunt 等。

我确实安装了 Angular 的 WebStorm 插件。

谁能帮忙?

【问题讨论】:

  • 您必须确保缩进在 webstorm 和 .jshintrc 文件中设置为相同的值

标签: javascript angularjs gruntjs webstorm jshint


【解决方案1】:

首先,您应该将 WebStorm 配置为使用与 Grunt 相同的 JSHint 文件。

转到Project Settings -> Javascript -> Code Quality Tools -> JSHint,点击Enable并在您的项目中引用.jshintrc

其次,您应该在所有 JavaScript 文件的顶部添加这两行代码:

/* global angular */
'use strict';

【讨论】:

  • 太好了,谢谢。我还必须将 jshint 文件中的缩进从 2 更改为 4,一切正常……谢谢……它似乎正在工作
  • 您还可以使用 globals 属性在 .jshintrc 文件中定义角度,例如 "globals" : { "angular": false}
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多