经过命令行:
npm install grunt-contrib-jshint --save-devjquery
globals :
Type : object
Default:null
定义了全局变量的字典,key就是全局变量名,布尔类型的值来表示是否能够赋值,这不是 JSHint 的标准选项,可是会做为第三个参数传递给 JSHint。
若是要用jquery,则在此配置项中加入变量key以下代码:npm
options: { globals: { $: false, jQuery:false } }
定义了全局变量后就可使用jquery了
jshintrc:
Type: String or true
Default: null
若是设置为 true,这里的配置参数不会传递给 JSHint,JSHint 将会经过 .jshintrc 文件来获取参数。
若是设置了文件名,将会经过这个文件获取配置参数. 这个 jshintrc 文件必须是一个合法的 JSON 文件,相似这样。
须要注意的是 :
jshintrc 文件的配置信息不会与 gruntfile.js 中的配置进行合并。
extentions :
Type: String
Default: ' '
须要检查的非 dot-js 扩展名列表
ignores :
Type: Array
Default: null
须要忽略的文件和目录列表. 将会覆盖 .jshintignore 文件。
force :
Type: Boolean
Default: false
设置为 true 将会报告 JSHint 错误,而不会将任务失败掉。
reporter:
Type: String
Default: null
容许修改输出插件,默认使用 Grunt 内置的报告器. 能够配置为自定义的报告器路径,或者 JSHint 内置的报告器之一: jslint 或者 checkstyle。
See also: Writing your own JSHint reporter. 能够指定一个外部的报告器,例如: jshint-stylish: 首先经过 npm 进行安装。
$ npm install --save-dev jshint-stylish
而后进行配置curl
options: { reporter: require('jshint-stylish') }
reporterOutput:
Type: String
Default: null
配置报告的输出路径. 若是配置,输出将不会输出到标准输出流,而是这个设置的路径。
wildcards :
下面的这个例子,执行 grunt jshint:all ( 因为 jshint 是一个多任务的任务,能够直接使用 grunt jshint, ) 将会使用默认的 JSHint 配置。检查 Gruntfile.js,lib 下面的任何 js 文件,test 下面的任何 js 文件ide
grunt.initConfig({ jshint: { all: ['Gruntfile.js', 'lib/**/*.js', 'test/**/*.js'] } });
Linting before and after concatenating :
下面的这个例子中,执行 grunt jshint 将会检查 'beforeconcat' 和 'afterconcat' 的全部文件,这并不理想,由于 dist/output.js 会在 grunt-contrib-concat plugin 的 concat 任务建立它以前被检查。
在这种状况下,应该先检查 'beforeconcat' 中的文件, 而后合并文件,最后再检查 'afterconcat' 中的文件,这样执行:grunt jshint:beforeconcat concat jshint:afterconcat.grunt
grunt.initConfig({ concat: { dist: { src: ['src/foo.js', 'src/bar.js'], dest: 'dist/output.js' } }, jshint: { beforeconcat: ['src/foo.js', 'src/bar.js'], afterconcat: ['dist/output.js'] } });
Specifying JSHint options and globals : 这个例子演示了定制 JSHint 的配置. 注意在 grunt jshint:uses_defaults 执行的时候,将会使用默认的配置, 可是当 grunt jshint:with_overrides 执行的时候,将使用合并以后的配置。ui
grunt.initConfig({ jshint: { options: { curly: true, eqeqeq: true, eqnull: true, browser: true, globals: { jQuery: true }, }, uses_defaults: ['dir1/**/*.js', 'dir2/**/*.js'], with_overrides: { options: { curly: false, undef: true, }, files: { src: ['dir3/**/*.js', 'dir4/**/*.js'] }, } }, });
Ignoring specific warnings : 若是但愿忽略特定的警告:url
[L24:C9] W015: Expected '}' to have an indentation at 11 instead at 9.
能够经过在警告标识以前加上减号 (-) 来关掉它。spa
grunt.initConfig({ jshint: { ignore_warning: { options: { '-W015': true, }, src: ['**/*.js'], }, }, });