Today, we introduce a checking tool for JS static code, which can help to better regulate the writing of code and check errors. Because the branch jshint of JSLint is relatively easy to use with many configuration items, this article mainly introduces the usage of Jshint.
The following is the directory for this article:
Introduction to Jshint
About the installation of Jshint
About the use of Jshint
Download about Jshint
1. Introduction to Jshint
Jshint is a branch of JSLint, which defines more configurations, is also relatively flexible to use, and jshint is primarily used for normative checking of JavaScript static code, which defines some stricter rules that can also be customized. More detailed explanation can be "click to view Jshint official website", but also "click to view jslint Baidu Encyclopedia explanation", "jslint official website".
2. About the installation of Jshint
The installation of Jshint in Eclipse is primarily possible by installing the Eclipse plug-in, which needs to be installed in an offline installation and online installation like the Android ADK, and is installed online in a way that first opens the Help>install new software >add then enter a name, enter the address of the plugin, the plugin online address can be obtained from the "plugin website", the legend is as follows.
In addition to the offline installation method needs to download the plugin can be "click to download the latest plug-in", and then need to create a server container for example, using Tomcat or Apache container can be, and then throw the plug-in into the container to make it accessible, the next step is similar to the following.
3. About the use of Jshint
After installation in eclipse, you can see the configuration options for Jshint in Window>preference, which is the global configuration of Eclipse, as shown below:
Of course, you can configure specific rules for a single project, you can select individual items and right-click the Jshint option, where you can configure which files to verify:
Finally click on the configuration Jshint below to set the specific configuration information, as shown below:
Some of Jshin's explanations are as follows:
jshint enforcing options================= #### * bitwise function: When the value is true, disable the use of bitwise operators, such as "^,|,&" and so on . #### * camelcase action: When the value is true, the variable name must use a camel style (such as "loginStatus") or Upper_case style (such as "Login_ STATUS ") . #### * curly Function: When the value is true, you cannot omit the curly braces after looping and conditional statements . remarks: such as "if (Con) ...", which need to be written as " if (Con) { ... } ". #### * eqeqeq function: When the value is true, "= =" and "! =" are forbidden, instead use "= = =" and "!==". #### * es3 action: A value of TRUE indicates that your code needs to comply with the ECMASCRIPT 3 specification . #### * forin function: When the value is true, in all "for in" loops, You must use Hasownpropery to filter out the members that inherit from the object. #### * immed Effect:???. #### * indent Role: This option requires that your code must use the specified tab indent width, such as "Indent:4" . #### * latedef function: When the value is true, it is forbidden to use it before the variable definition . #### * newcap function: When the value is true, the constructor name needs to be capitalized . Note: Tested to see if this option is active, Jshint does not check the constructor name . #### * noarg function: Arguments.caller and arguments.callee. #### are forbidden when the value is True * noempty function: When the value is true, empty statement blocks ("{}") in the code are not allowed . #### * nonew function: When the value is true, Suppresses the use of constructor calls that produce side effects, such as "New myconstructor ();". #### * plusplus action: When the value is true, the unary increment ("+ +") and decrement ("----") operators are forbidden . #### * quotmark function: This option is used for the style of quotation marks in uniform code, The optional value has three: (1) single -- can only use single quotation marks; (2) double -- use double quotes only; (3) true -- either, but not at the same time . #### * undef function: When the value is true, disable the use of undefined variables . #### * unused function: After this option is activated, for "defined but unused variables" will give a warning, the optional value is three: (1) vars -- check variables only, Do not check function parameters; (2) strict -- check variables and function parameters; (3) true -- check variables and function parameters, but allow this case: an unused formal parameter is followed by a used formal parameter . Example: The difference between strict and true (1) strict function show (x, y) {alert (y);} // jshint Check Result: ' X ' is defined but never used show (1); (2) true function show (x, y) {alert (y);} // jshint Check Results:pass show (1); #### * strict action: When the value is true, this option requires all functions to be ECMAScript 5 in strict mode run . Note: After this option is activated, only strict mode is enabled in the function scope (if enabled in the global scope, May affect third-party JS in the page .#### * trailing effect: When the value is true, it is forbidden to have a blank at the end of the code . #### * maxparams function: This option sets the upper limit for the number of parameters for each function, such as "Maxparams:3" . #### * maxdepth function: This option sets the upper limit for the nesting level of code blocks in each function, such as "Maxdepth:1" . Example:/* jshint maxdepth:1 */ function show () { if (1) { if (2) { // jshint Check results:blocks are nested too deeply. (2) &Nbsp; alert (' the second nested '); } } } #### * maxstatements function: This option sets the upper limit for the number of statements in each function, such as " Maxstatements:4 ". Note: a function declaration is treated as a statement . Example:/* jshint maxstatements:4 */ function main () { // jshint check Result: This function has too many statements. (5) Var i = 0; var j = 0; The // function declaration is treated as a statement function inner () { var i2 = 1; var j2 = 1; return i2 + j2; } j = i + j; return j; }#### * maxcomplexity Role:??? #### * maxlen function: This option sets the maximum character length for each line.
The above configuration is explained from GitHub "Jshint Configuration Item description (Chinese version)". More details can refer to the official website "Click to enter the official website".
4. Downloads for Jshint
Also here to provide the author Baidu share links:
Jshint plugin Download "Click to download".
http://www.startexample.com/2014/05/11/jshint-%E9%9D%99%E6%80%81%E4%BB%A3%E7%A0%81%E6%A3%80%E6%9F%A5%E5%B7%A5% e5%85%b7eclipse%e4%b8%ad%e4%bd%bf%e7%94%a8/
jshint-Static code checking tool used in eclipse