我正在尝试将 JSHint 合并到我的构建过程中。我正在构建的应用程序使用 AngularJS。目前,我有一个冲突,我不确定如何解决。当我构建应用程序时,我收到一个 JSHint 错误,内容如下:
src\app\app.js
3 |var myApp = angular.module('myApp', []);
^ Redefinition of 'myApp'.
>> 1 error in 2 files
Warning: Task "jshint:source" failed. Use --force to continue.
我收到此错误是因为在我的 .jshintrc 文件中,我有以下内容:
“predef”:[“Angular ”,“myApp”],
如果我删除“myApp”,我会收到一个不同的错误:
src\app\account\welcome.html.js
3 |myApp.controller('WelcomeController', ['$scope', function($scope) {
^ 'myApp' is not defined.
1 error in 2 files
我之所以定义这样的 Controller 是因为根据 AngularJS documentation ,您不应该在全局范围内定义 Controller 。正如你所看到的,如果我这样做了,我就该死,如果我不这样做,我也该死。如何遵循 AngularJS 最佳建议,同时仍将 JSHint 包含在我的构建过程中?
谢谢!
最佳答案
我认为您可以使用 .jshintrc 文件中的全局键来解决此问题
{
"node": true,
"browser": true,
"esnext": true,
"bitwise": true,
"camelcase": true,
"curly": true,
"eqeqeq": true,
"immed": true,
"indent": 4,
"latedef": true,
"newcap": true,
"noarg": true,
"quotmark": "single",
"undef": true,
"unused": true,
"strict": true,
"trailing": true,
"smarttabs": true,
"multistr": true,
"globals": {
"myApp": false
}
}
关于angularjs - 将 jshint 与 AngularJS 和 Controller 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23216781/