1. Purpose
Automated static code checking and improved code quality before committing to code
2. Preparation 1. Nodejs Installation:
Official address: http://nodejs.org/
Installation instructions: Download the corresponding version according to the computer configuration to install
To check if the installation was successful:
2. Install Grunt:
GRUNTJS Official website: http://www.gruntjs.org/
Installation Instructions:
1. Go to the command line and install the Grunt library.
2. Install GRUNT-CLI (you can run the grunt command directly at the command line after installation)
3. Check whether the installation is successful:
3. Installing Jshint
Go to the command line and execute:
4. Install the Grunt-jshint library:
3. Create grunt Automation Engineering 1. Loading grunt, Jshint plugins:
Go to the root directory where you want to automate the inspection (hereinafter referred to as the project directory ), and perform preparation steps 2, 3, 4.
2. Create a Package.json file
Go to the project directory and do the following: NPM Init
3. Create Gruntfile.js
Create the Gruntfile.js file manually in the project directory.
4. Configure Gruntfile
1, configure the wrapper function of grunt.
2. Initialize the configuration (Task configuration) object.
3. Read our project configuration Package.json file and store it in the Pkg property.
4. Add the task.
-
- Files settings must be set to the root directory first
- When configuring files that you do not want to be checked, add a "!" to the front. For example: files:[' script/*.js ', '!script/*.min.js ']
- Externally introduced JSHINTRC files:
5, load the required grunt plug-in
6. Registration Tasks
7, the complete gruntfile.js
4. Running
-
- Go to command line
2 Running a configured task
Appendix:
Jshint option:http://www.jshint.com/docs/options/
Nodejs + jshint Automated static code checking