我想通過咕嚕運行jshint,但我得到以下錯誤。當我輸入咕嚕聲,我得到'jshint:所有失敗'的錯誤
Warning: Task "jshint:all" failed. Use --force to continue.
Aborted due to warnings.
我試過強迫它,但它只做了一小部分工作。
Execution Time (2016-07-07 20:05:33 UTC)
loading tasks 50ms ▇▇▇▇ 11%
loading grunt-contrib-jshint 233ms ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 51%
jshint:all 172ms ▇▇▇▇▇▇▇▇▇▇▇▇▇ 38%
Total 456ms
我已經按照上coursera的說明,並在'use strict';
添加到我的app.js
,因爲它被扔使用嚴格的被丟失的錯誤。我甚至在jshint:options
中加入了要求的.jshintrc
文件。我仍然收到錯誤消息。我在下面包括腳本。
app.js
var app = angular.module('confusionApp', [])
.controller('menuController', function(){
'use strict';
this.tab = 1;
this.filtText = '';
var dishes=[
{
name: 'Uthapizza',
image: 'images/uthapizza.png',
category: 'mains',
label: 'Hot',
price:'4.99',
description: 'A unique combination of Indian Uthappam (pancake) and Italian pizza, topped with Cerignola olives, ripe vine cherry tomatoes, Vidalia onion, Guntur chillies and Buffalo Paneer.',
comment: ''
},
{
name: 'Zucchipakoda',
image: 'images/Zucchipakoda.png',
category: 'appetizer',
label: '',
price:'1.99',
description: 'Deep-fried with mildly spiced Chickpea flour batter accompanied with a tamarind sauce.',
comment: ''
},
{
name: 'Vadonut',
image: 'images/vadonut.png',
category: 'appetizer',
label: 'New',
price:'1.99',
description: 'A quintessential experience, is it a vada or is it a donut.',
comment: ''
},
{
name: 'ElaiCheese Cake',
image: 'images/elaicheesecake.png',
category: 'dessert',
label: '',
price:'2.99',
description: 'A delectable, semi-sweet New York Style Cheese Cake with Graham cracker crust spiced with Indian cardamoms',
comment: ''
}
];
this.dishes = dishes;
this.select = function(setTab){
this.tab = setTab;
if(setTab === 2)
this.filtText = "appetizer";
else if(setTab === 3)
this.filtText = "mains";
else if(setTab === 4)
this.filtText = "dessert";
else
this.filtText = "";
};
this.isSelected = function(checkTab) {
return (this.tab === checkTab);
};
});
Gruntfile.js
'use strict';
module.exports = function(grunt){
//Time how long tasks take. Can help when optimizing times
require('time-grunt')(grunt);
//Automatically load grunt tasks
require('jit-grunt')(grunt, {
default: 'default'
});
//Define the configuration of all the tasks
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
//Make sure code styles are up to par and there are no obvious mistakes.
jshint: {
options: {
jshintrc: '.jshintrc',
reporter: require('jshint-stylish')
},
all: {
src: [
'Gruntfile.js',
'app/scripts/{,*/}*.js'
]
}
}
});
grunt.registerTask('build', [
'jshint'
]);
grunt.registerTask('default', ['build']);
};
錯誤說的是什麼?您可能需要一個全局性的'use strict',它可能會抱怨未聲明的變量,或者取決於您的設置的其他任何事情。 –
它提供了上述錯誤以及以下'warnings.app/scripts/app.js line 52 col 17預期'{',而是看到'this'。 line 54 col 17預期'{',而是看到'this'。 第56欄第17欄預期'{',而是看到'this'。 line 58 col 17預期'{',而是看到'this'。 第1行第5行'app'被定義但從未使用過。 ⚠5個警告 警告:任務「jshint:all」失敗。使用--force繼續。 由於警告而中止.' – muzzo
因此請閱讀警告。它告訴你它期望你在你的if語句中加上大括號('if(setTab === 2){...}')並且你沒有使用你的'app'變量。 –