【问题标题】:grunt-contrib-jshint not linting errors in my codegrunt-contrib-jshint 不在我的代码中检查错误
【发布时间】:2015-10-24 03:20:16
【问题描述】:

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

那么,哦,无误的互联网理事会,我做错了什么?

【问题讨论】:

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


    【解决方案1】:

    问题在于 jshint 默认情况下不检查任何规则。 所以你的文件通过了,它不是很有用,直到你设置你想要的规则,作为 .jshintrc 文件或作为 grunt 选项。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-24
      相关资源
      最近更新 更多