Shint Introduction
Translated from Www.jshint.comJSHint (note not jslint:)) is a tool developed by the JavaScript community to check for JavaScript code errors and problems, and with him, you can keep a good coding style. You can easily configure it to fit into one of your current coding styles. At present, the source code of Jshint can be found on GitHub.
Jshint How documents are used Jshint
Jshint is a global function that accepts two parameters, Jshint (source,options); One is code source and the other is options (option) The first argument can be a string or an array of strings. If it is a string, then he will be divided by \ n and \ r, if the passed parameter is an array, ensure that each item of the array is a line of code. So the source parameters can be JavaScript code or a JSON form. Returns true if all detections are ok,jshint, or false. When you return false, you can use Jshint.errors to get the error message or use Jshint.data () to get lint information. If you want to learn more, see source code. With Jshint, you can set options at the start of the JS file, such as
/*jshint evil:true, boss:true * *
and setting the global parameter can tell the Jshint, the variable configuration. For example
/*global disqus:true, jquery:false * *
The above example tells you that Jshint,disqus is a global variable that you declare, and that jquery is the global variable that you introduce
What's the difference between Jshint and jslint?
Jshint is a branch of jslint (fork), he is more convenient than jslint. To constrain your code quality and coding style. Everyone has different coding habits and styles, and Jshint can be adapted to a variety of situations through configuration. Jshint for the environment
- Browser Environment (browsers)
- node. js
- Jquery
- ES5
- Couchdb
- Prototype.js
- Mootools.js
Jshint option to configure ASI
If true, Jshint ignores line endings without semicolons, and auto-complete semicolons are always a controversial syntactic feature of JavaScript. By default, Jshint will ask you to add a semicolon after each statement, but if you think you understand the ASI (automatic semicolon insertion), you can discard Jshint's check on the semicolon.
Bitwise
If true, Jshint disables the bitwise operator JavaScript to allow bit operations, but he does not have an integer, and the bitwise operator converts the number of participating operations from floating-point numbers to integers, and then transforms them back after the operation. So they are less efficient than they are in other languages.
Boss
Very domineering option, if true, then Jshint will allow assignment statements to be written in If,for,while. In general, we will be in the loop, judge and other statements to add the value of the comparison to do the statement of the operating conditions, sometimes the = = error is written as an assignment =, usually, Jshint will identify this as a mistake, but turn on this option, Jshint will not check the evaluation criteria in the assignment, you are boss, You said:).
Curly
If true, Jshint will ask you to explicitly block the code by adding {} When using structure statements such as if and while. JavaScript allows no parentheses in the case of an IF structure statement body with only one sentence. But doing so may make your code read a bit obscure.
Debug
If true, Jshint will allow debugger statements to appear in the code. However, it is recommended that you remove the debug statements before you detect the code.
Eqeqeq
If true, Jshint will see if you use = = = or!== in your code instead of = = and! =. We recommend that you use = = = and!=== when comparing 0, ' (null characters), Undefined,null,false and True.
Eqnull
If true, Jshint will allow "= = null" To be used for comparison. = = NULL is often used to determine whether a variable is undefined or null (then converted to false with ==,null and undefined).
Evil
If true, Jshint will allow the use of evaleval to provide access to the JavaScript compiler, which is sometimes useful, but it also poses a risk of injecting attacks on your code and makes debugging difficult. Remember, the function constructor is another ' eval ', and settimeout and setinterval are similar to eval when the arguments passed in are strings.
Forin
If true, then Jshint allows the hasownproperty,for in loop to traverse an object's properties in a for-in loop, which also includes attributes that he inherits from the prototype chain, Instead, hasOwnProperty can determine whether a property is a property of the object itself and not inherited.
Immed
If true, Jshint requires the invocation of an anonymous function as follows:
(function () {//} ());
Instead of
(function () {//bla bla}) ();
Laxbreak
If true, Jshint does not check for line breaks. JavaScript corrects some errors with auto-fill numbers, so this option can check for potential problems.
Maxerr
Set the threshold of the error, exceeding this threshold jshint no longer checks downward, prompting for too many errors.
Newcap
If true, Jshint will require each constructor name to start with a capital letter. A constructor is a function that creates an object using the new operator, Inode creates a new object and builds the object's own this, and if a constructor is run without the new operator, then his this will point to the global object and cause some problems to occur.
Noarg
If true, Jshint will disallow the use of Arguments.caller and Arguments.callee. The arguments object is an object of an array of classes that has an index value. Arguments.callee points to the currently executing function (which is disabled in ES5 's strict mode), and Arguments.caller points to the function that invokes the current function (if any), and he does not have it in all JavaScript implementations.
Noempty
If true, Jshint will disallow empty blocks of code (blocks of code without statements). If true, Jshint disables the constructor to avoid some problems. In JSLint, the constructor is actively disabled to avoid some potential problems, but the use of many constructors is not harmful, such as the following call
new Jsuiwindow ();//Note that this call does not assign the result of the constructor to the variable.
Therefore, we can disable this option when we need to use the constructor.
Nomen
If true, Jshint disables the underlined variable name. Many people use the _name way to name their variables to show that this is a private variable, but in fact, not, the underscore just makes an identity. If you want to use private variables, you can use closures to implement them.
Onevar
If true, Jshint expects the function to be declared only once in the form of Var.
Passfail
If true, Jshint will stop checking after the first error is found.
Plusplus
If true, Jshint disables the self-increment operation and the self-subtraction operation + + and--may bring some code to the reading of confusion.
Regexp
If true, Jshint will not be allowed to use. and [^ ...] The regular, because such a regular will often match the content you do not expect, and may be used to cause some harm.
Undef
If true, Jshint will require all non-global variables to be declared before they are used. If you do not declare a variable using var in a local scope, JavaScript puts it under the global scope. This can easily cause errors.
Sub
If true, Jshint will allow various forms of subscripts to access the object. Usually, Jshint wants you to use the dot operator to read the object's properties (unless the property name is a reserved word), and if you don't want to turn this option off.
Strict
If true, Jshint will ask you to use strict; Strict mode is a new feature in ES5 that allows you to put a program or function in a "strict" scope. Visible Resig wrote an article about strict mode of the blog strict mode did a few things:
1. He can catch some errors and anomalies
2. When we do an "unsafe" operation, he throws an exception, such as accessing global variables.
3, he will forbid you to use some kinky tricks, or bad code writing.
White
If the true,jshint will check your code against a strict blank specification.
Jshint Instructions for use