Front-end automation tools Grunt plug-in Jshint simple use (iv)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.