0

To start with, I know that I'm doing something wrong, but grunt-contrib-jshint is not linting my JS properly, and is simply passing the files.

I read the docs, but couldn't find my error.

Here is a link to the branch of my basic bootstrap app where the problem is occurring. https://github.com/bengrunfeld/grunt_bower_app/tree/jshint-not-working

And here is the full copy of my Gruntfile.js and its output:

Gruntfile.js

module.exports = function(grunt) {
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    jshint: {
        all: ['Gruntfile.js', 'dev/js/*.js']
    },
    clean: ['dist/'],
    copy: {
      main: {
        files: [
          {expand: true, src: ['bower_components/jquery/dist/jquery.min.js'], dest: 'dist/js', filter: 'isFile'},

          {expand: true, src: ['bower_components/bootstrap/dist/js/bootstrap.min.js'], dest: 'dist/js', filter: 'isFile'},

          {expand: true, src: ['bower_components/bootstrap/dist/css/bootstrap.min.css'], dest: 'dist/css', filter: 'isFile'} ,

          {expand: true, src: ['bower_components/bootstrap/dist/fonts/*'], dest: 'dist/fonts', filter: 'isFile'},
        ],
      }
    },
  });

  // Load in Grunt's plugins
  grunt.loadNpmTasks('grunt-contrib-jshint');
  grunt.loadNpmTasks('grunt-contrib-clean');
  grunt.loadNpmTasks('grunt-contrib-copy');
  grunt.loadNpmTasks('grunt-contrib-uglify');

  // Default tasks
  grunt.registerTask('default', ['jshint', 'clean', 'copy']);

};

Output

$ grunt
Running "jshint:all" (jshint) task
>> 3 files lint free.

Running "clean:0" (clean) task
>> 1 path cleaned.

Running "copy:main" (copy) task
Copied 8 files

But I have a very clear error that I introduced in my Javascript:

dooooooocument.getElementsByClassName("hero-btn")[0].addEventListener("click", function(){
    console.log('The hero button was clicked');
});

document.getElementsByClassName("store-btn")[0].addEventListener("click", function(){
    console.log('The store button was clicked');
});

So, oh wise council of the infallible internets, what am I doing wrong?

Ben
  • 5,085
  • 9
  • 39
  • 58

1 Answers1

0

The issue is that jshint, by default, does not check any rules. So your files pass, and it's not very useful, until you set the rules you want, as a .jshintrc file or as grunt options.

For example, if you want the same level of checking as the website jshint.com, you need a pretty beefy list of rules: https://github.com/jshint/jshint/blob/master/examples/.jshintrc

Xavier Priour
  • 2,121
  • 1
  • 12
  • 16