【问题标题】:When I type in grunt, I get a 'jshint:all failed' error当我输入 grunt 时,我收到一个“jshint:all failed”错误
【发布时间】:2016-07-07 20:21:02
【问题描述】:

我正在尝试通过 grunt 运行 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 上的说明进行操作,并在我的 app.js 中添加了 'use strict';,因为它抛出了缺少 use strict 的错误。我什至在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 Expected '{' and instead saw 'this'. line 54 col 17 Expected '{' and instead saw 'this'. line 56 col 17 Expected '{' and instead saw 'this'. line 58 col 17 Expected '{' and instead saw 'this'. line 1 col 5 'app' is defined but never used. ⚠ 5 warnings Warning: Task "jshint:all" failed. Use --force to continue. Aborted due to warnings.
  • 所以请阅读警告。它告诉您它希望您在 if 语句 (if(setTab === 2) { ... }) 上加上大括号,并且您没有使用您的 app 变量。
  • 我也尝试在 app.js 文件中全局运行 'use strict'; 并得到相同的结果。
  • 'use strict' 不会解决这些问题。您需要阅读警告,理解它们在说什么,然后修复它们。

标签: javascript gruntjs gruntfile


【解决方案1】:

在 Mike C 的帮助下,我设法弄清楚我的 jshint 出了什么问题:all not working。在 if/else 语句周围添加大括号并用 app.controller 分离出 .controller 似乎已经使它工作了。再次感谢。

【讨论】:

    【解决方案2】:

    var app = angular.module('confusionApp', []) .controller 替换为angular.module('confusionApp', []) .controller。 我希望这能解决这个问题。由于警告“应用程序”已定义但从未使用过(如果您在终端中看到),该进程被中止。

    【讨论】:

      猜你喜欢
      • 2016-05-05
      • 1970-01-01
      • 1970-01-01
      • 2011-11-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多