Question

I have multiple jshint configurations in my gruntfile.

I tested each configuration, and it works great.

However, when I define a target in the gruntfile for each configuration, jshint stops working and all I can see is :

0 files linted. Please check your ignored files.

This is how my jshint configuration looks like with targets:

    jshint: {
        backend: {
            options: {
                jshintrc: '.jshintrc'
            },
            all: [
                'Gruntfile.js',
                'server.js',
                '*.js',
                'backend/{,*/}*.js'
            ]
        },
        test: {
            options: {
                jshintrc: 'test.jshintrc'
            },
            all: [
                'test/{,*/}*.js'
            ]
        }
    }
Was it helpful?

Solution

For multiple tasks changing:

'all' : {...} 

to

'files': { src: [...] } 

should fix it. It would seem that 'all' is a shorthand for a single task, with multiple tasks, jshint will be looking for files in files->src ie:

backend: {
    options: {
        jshintrc: '.jshintrc'
    },
    'files': { 
        'src': [
            'Gruntfile.js',
            'server.js',
            '*.js',
            'backend/{,*/}*.js'
        ]
    }
},
test: {
    options: {
        jshintrc: 'test.jshintrc'
    },
    'files': {
        'src': [
            'test/{,*/}*.js'
        ]
    }
}

OTHER TIPS

My team found out this works, we are using it on a project of ours. Even though I don't recommend using this method, it taught me something about how grunt works, and how you can programatically invoke tasks and change options at runtime so I find it relevant.

jshint: {
        options: {
            jshintrc: '.jshintrc'
        },
        all: [
            'Gruntfile.js',
            '<%= yeoman.app %>/scripts/{,*/}*.js'
        ],
        backend: [
            'server.js'
        ]
    },

 .... 

 grunt.registerTask('backend', function() {
    grunt.config.set('jshint.options.jshintrc', '.backendhintrc');
    grunt.task.run('jshint:backend');
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top