-1

I'm trying to run jshint through grunt but I'm getting the following error.

Warning: Task "jshint:all" failed. Use --force to continue.

Aborted due to warnings.

I tried forcing it, but it only does a fraction of the work.

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

I've followed the instructions on coursera and added in a 'use strict';to my app.js as it was throwing an error that use strict was missing. I even added the .jshintrc file which it asks for in jshint:options.I'm still getting the error. I am including the scripts below.

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']);

};
muzzo
  • 121
  • 1
  • 3
  • 9
  • What exactly does the error say? You might need a global `use strict`, it might be complaining about undeclared variables, or any number of other things depending on your settings. – Mike Cluck Jul 07 '16 at 20:23
  • 1
    It provides the above error along with the following `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.` – muzzo Jul 07 '16 at 20:25
  • 1
    So read the warnings. It's telling you it expects you to put braces on your `if` statements (`if(setTab === 2) { ... }`) and that you aren't using your `app` variable. – Mike Cluck Jul 07 '16 at 20:29
  • I also tried running `'use strict';` globally in the app.js file and got the same result. – muzzo Jul 07 '16 at 20:30
  • `'use strict'` isn't going to solve those problems. You need to read the warnings, understand what they're saying, then fix them. – Mike Cluck Jul 07 '16 at 20:30
  • OK, putting the braces around the if/else statement worked and adding in `app.controller` worked. Thank you. – muzzo Jul 07 '16 at 20:33

2 Answers2

0

So with the help of Mike C. I managed to figure out what was going wrong with my jshint:all not working. Adding in the braces around the if/else statement and separating out the .controller with an app.controller has seemed to have made it work. Thank you again.

muzzo
  • 121
  • 1
  • 3
  • 9
0

Replace var app = angular.module('confusionApp', []) .controller with angular.module('confusionApp', []) .controller. I hope this will fix the issue. The process is Aborted due to warning 'app' is defined but never used (if you see in the terminal).