grunt-contrib-jshint没有在我的代码中发现错误

时间:2015-10-24 03:20:16

标签: javascript node.js gruntjs grunt-contrib-jshint

首先,我知道我做错了什么,但是grunt-contrib-jshint并没有正确地说明我的JS,而只是传递文件。

我阅读了文档,但无法找到我的错误。

这是我的基本引导程序应用程序分支的链接,其中发生了问题。 https://github.com/bengrunfeld/grunt_bower_app/tree/jshint-not-working

这是我的Gruntfile.js的完整副本及其输出:

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

};

输出

$ 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

但是我在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');
});

那么,无懈可击的互联网明智的理事会,我做错了什么?

1 个答案:

答案 0 :(得分:0)

问题是jshint默认不检查任何规则。 因此,在您设置所需的规则,作为.jshintrc文件或grunt选项之前,您的文件会通过,并且它不是非常有用。

例如,如果您想要与网站jshint.com进行相同级别的检查,则需要一个非常强大的规则列表:https://github.com/jshint/jshint/blob/master/examples/.jshintrc