Now we introduce JSHint, a JS code verification tool that checks simple errors under Node.
For a specific introduction to JSHint, refer to http://www.jshint.com/about/. To put it bluntly, JSHint is a tool to check the specifications of JS code. It can be used to check the standardization of JS code in any (including server side and client side). It provides a configuration method, allowing developers to define which specifications to check for errors. This brings great convenience to developers, because during the development process, especially during the team development process, you will often encounter various problems caused by non-compliance with the specifications, or some common text errors, such as the use of undefined functions or parameters.
1. Install JSHint.
Open the cmd command window and enter the following command:
The code copy is as follows:
npm install -g jshint //-g means global use
Note: If the prompt npm is not an internal or external command, then most of the reason you do not have node or npm installed. For specific installation process, please refer to http://dailyjs.com/2012/05/03/windows-and-node-1/.
2. Run JSHint.
Open the cmd command window, use cd to switch to your corresponding application directory, and enter the following command:
The code copy is as follows:
jshint my_app.js
Note: my_app.js is the file you intend to verify or check.
3. Configure JSHint.
JSHint provides configuration methods, allowing you to define checking and verification rules based on your team or hobbies. You can copy the default rule file at https://github.com/jshint/node-jshint/blob/master/.jshintrc.
Method 1: If you name the copied rule file as a .jshintrc file and place the file in the corresponding directory or parent directory, then when running JSHint, this rule file will be automatically retrieved and used.
Method 2: If you do not name the rule file as a name that conforms to the rules (i.e., use .jshintrc), you can manually specify the rule file when running JSHint, for example, you name the rule file jshint.json. Then you can use the following command to run JSHint and apply your rules:
The code copy is as follows:
jshint my_app.js --config /root/application/jshint.json //Specify the rule file path
4. Rules of configuration files.
There are many rules for configuration files, including the common semicolon use or not, the initial letter of the class constructor function, etc. The specific rules will not be described one by one, please refer to http://www.jshint.com/docs/.
By using JSHint, you will check out many common errors or accidentally wrong codes in your JS code. Of course, JSHint is not strong enough to check out all your errors. But don't worry, there are several other debugging tools that can be used for Node. This time I will only introduce JSHint.
The above are my stupid opinions. If there is any error, please point them out. Welcome to exchange and discuss.