这是我的档案:app/scripts/controllers/main.js
"use strict";
angular.module('appApp')
.controller('MainCtrl', ['$scope', function ($scope) {
$scope.awesomeThings = [
'HTML5 Boilerplate',
'AngularJS',
'Karma'
];
}]);
我的Gruntfile.coffee
有:
jshint:
options:
globals:
require: false
module: false
console: false
__dirname: false
process: false
exports: false
server:
options:
node: true
src: ["server/**/*.js"]
app:
options:
globals:
angular: true
strict: true
src: ["app/scripts/**/*.js"]
当我运行grunt
时,我得到:
Linting app/scripts/controllers/main.js ...ERROR
[L1:C1] W097: Use the function form of "use strict".
"use strict";
答案 0 :(得分:49)
问题在于,如果您不使用函数表单,它将适用于所有内容,而不仅仅是您的代码。解决方法是将use strict
范围放在您控制的函数中。
请参阅此问题:JSLint is suddenly reporting: Use the function form of “use strict”。
而不是做
"use strict";
angular.module('appApp')
.controller('MainCtrl', ['$scope', function ($scope) {
$scope.awesomeThings = [
'HTML5 Boilerplate',
'AngularJS',
'Karma'
];
}]);
你应该这样做
angular.module('appApp')
.controller('MainCtrl', ['$scope', function ($scope) {
"use strict";
$scope.awesomeThings = [
'HTML5 Boilerplate',
'AngularJS',
'Karma'
];
}]);
或者将代码包装在一个自动执行的闭包中,如下所示。
(function(){
"use strict";
// your stuff
})();
答案 1 :(得分:8)
将我的Gruntfile.coffee
更改为包含globalstrict
jshint:
options:
globalstrict: true
globals:
require: false
module: false
console: false
__dirname: false
process: false
exports: false