First, the use of Contrib-jshint plug-in
1, install "Grunt-contrib-jshint" plug-in command (in the terminal into the project root directory execution)
NPM Install Grunt-contrib-jshint--save-dev
2, in the project root directory to provide Jshint plug-in task configuration required SRC directory and need to be detected source files (JS source files placed in the SRC directory)
mkdir SRC
3. Configure the Jshint task in the Gruntfile.js file
wrapper function
Module.exports = function (grunt) {
Task configuration, configuration information for all plugins
Grunt.initconfig ({
Get information on Package.json
Pkg:grunt.file.readJSON (' Package.json '),
Configuration information for the Jshint plugin
Jshint: {
Options: {
'-w060 ': true,//Specify error based on error code masking
JSHINTRC: '. Jshintrc '//Specify the configuration file for Jshint grammar detection rules
},
Specific task configuration
Build: [' src/*.js ']//need to make JS syntax detection of the source file, you can specify multiple files at the same time
}
});
Load the specified plug-in task
Grunt.loadnpmtasks (' Grunt-contrib-jshint ');
Tasks that are performed by default
Grunt.registertask (' Default ', [' jshint ']);
};
The configuration of the Ps:jshint plugin has two items:
In options, you specify the configuration file for the Jshint syntax detection rule by using the "JSHINTRC" property, and the code in the. jshintrc file is also strictly compliant with the JSON syntax specification, otherwise it is not valid.
"Build" specifies which JS files are required for syntax detection.
4. Finally run the grunt command at the terminal
PS: If prompted "done, without errors." There's nothing wrong with proving it.
5. Configuration of the. jshintrc file (the file is placed in the project root directory)
{
"ASI": True, //Prohibit missing semicolon warning
Loopfun C ": True, //whether the function inner loop is forbidden
" expr ": true, // Support for using regular expressions
"node": true, //Whether the file is a node. js file
"Curly": true, //code block must use braces
"Eqeqeq": false, &N Bsp //whether to use "= = =" For Equality, "!==" means unequal
"Eqnull": false, //whether "= = null is forbidden" "Compare
" undef ": true, //whether the specified variable must first be declared after use
" strict " : false, //prohibit use of strict mode
}
please refer to http://jshint.com/docs/options/for the specific meanings of the options in the Ps:jshintrc file.
This article from "Luo Chen's Blog" blog, reproduced please contact the author!
Front-end automation tools Grunt plug-in Jshint simple use (iv)