0

首先,我知道我做错了什么,但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');
});

所以,哦,可靠的互联网理事会,我做错了什么?

4

1 回答 1

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

于 2015-11-03T21:20:02.420 回答