Jshint Options Translation

Source: Internet
Author: User
Tags bitwise bitwise operators shuffle types of functions dojo toolkit mootools couchdb

Enforcing options

When set to true, these options would make jshint produce more warnings about your code.

Bitwise

This option prohibits the use of bitwise operators such ^ as (XOR), | (OR) and others. Bitwise operators is very rare in JavaScript programs and quite often is & simply a mistyped && .

This option disables the use of bitwise operators such as ^ (XOR), | (or), and so on. Bit operators are very rare JavaScript programs and are often associated with just a && and & "

CamelCase

This option allows the all variable names to the use either CamelCase style or upper_case with underscores.

"This option allows you to force all variable names to be underlined using camel or upper_case. 】

Curly

This option requires all put curly braces around blocks in loops and conditionals. JavaScript allows omit curly braces when the block consists of only one statement, for example:

while (day)  shuffle();

However, in some circumstances, it can leads to bugs (you ' d-think that's a part of the loop while in sleep() reality it's n OT):

while (day)  shuffle();  sleep();
【此选项要求你总是把大括号各地块的循环和条件。 JavaScript允许你省略花括号当块只包含一个语句】

Eqeqeq

This options prohibits, and in == != favor of === !== . The former try to coerce values before comparing them which can leads to some unexpected results. The latter don ' t does any coercion so they is generally safer. If you would like to learn more about type coercion in JavaScript, we recommend Truth, equality and JavaScript by Angus Cr Oll.

"This option disables the use of = = and!" = Pro = = = and! = =. The former tries to compare the mandatory values before they can cause some unexpected results. The latter did not make any compulsion so they are usually more secure "

Es3

This option tells Jshint, your code needs to adhere to ECMAScript 3 specification. Use the This option if you need your program to being executable in older Browsers-such as Internet Explorer 6/7/8/9-and other Le Gacy JavaScript environments.

This option tells Jshint that your code needs to follow the ECMASCRIPT3 specification. Use this option if you need your program to be executable in older browsers, such as Internet explorer6/7/8/9-and other traditional JavaScript environments. 】

Forin

This option requires any for in loops to the Filter object ' s items. The for in statement allows for looping through the names of any of the properties of an object including those inherited Throught the prototype chain. This behavior can leads to unexpected items in your object so it's generally safer to always filter inherited properties O UT as shown in the example:

for (key in obj) {  if (obj.hasOwnProperty(key)) {    // We are sure that obj[key] belongs to the object and was not inherited.  }}

For more in-depth understanding for in of loops in JavaScript, read exploring JavaScript for-in loops by Angus Croll.

"This option requires all items that filter objects for the loop. In a declaration, a loop is allowed for the names of properties that are permitted through all of the objects that inherit the same prototype chain. This behavior can result in unexpected items for your object, so it is usually safe to "

Freeze

This options prohibits overwriting prototypes of native objects such Array as, and so on Date .

/* jshint freeze:true */Array.prototype.count = function (value) { return 4; };// -> Warning: Extending prototype of native object: ‘Array‘.
【这个选项禁止覆盖原生的对象,如数组,日期等的原型。】

Immed

This option prohibits the use of immediate function invocations without wrapping them in parentheses. Wrapping parentheses assists readers of your code in understanding this expression is the result of a function, and no t the function itself.

"This option immediately disables the use of function calls that are not wrapped in parentheses. Wrapping brackets Help the reader understand your code, and the expression is the result of a function, not the function itself.

The feeling is to immediately execute the function and function expressions related to the "

Indent

This option enforces specific tab width for your code. For example, the following code would trigger a warning on line 4:

/*jshint indent:4 */if (cond) {  doSomething(); // We used only two spaces for indentation here}
【此选项强制特定的标签宽度为您的代码】

Latedef

This option prohibits the use of a variable before it is defined. JavaScript has function scopes only and, in addition to, all variables is always moved-or hoisted-to the top of the function. This behavior can leads to some very nasty bugs and that's why it's safer to always use variable only after they has been explicitly defined.

Setting this option to "Nofunc" would allow the function declarations to be ignored.

For more in-depth understanding of scoping and hoisting in JavaScript, read JavaScript scoping and hoisting by Ben Cherry.

This option disables the use of a variable before it is used to define it. JavaScript has function scope only, and in addition, all variables are always moved or hoisted to the top of the function. This behavior can lead to some very annoying errors, which is why it is safe to use variables only after they have been explicitly defined.

Setting this option to "Nofunc" will allow the function declaration to be ignored.

For a deeper understanding of scoping and rigging in JavaScript, read the scope of JavaScript and be hoisted by Ben Cherry.

Newcap

This option requires your to capitalize names of constructor functions. Capitalizing functions that was intended to being used with new operator was just a convention that helps programmers to vis Ually distinguish constructor functions from the other types the functions to help spot mistakes when using this .

Not doing so won ' t broke your code in any browsers or environments but it'll be a bit harder to figure out-by reading th E code-if the function is supposed to being used with or without new. And this is a important because when the function of is intended to be used new with is used without it, would this poi NT to the global object instead of a new object.

This option requires the name of your older constructor. The purpose of this move is to work with new operators using a feature that is just a convention that helps programmers visually distinguish constructors from other types of functions when using it to help find errors.

Noarg

This option prohibits the use of arguments.caller and arguments.callee . Both and make .caller .callee quite a few optimizations impossible so they were deprecated in the future versions of JavaScript. In fact, ECMAScript 5 forbids the use of in arguments.callee strict mode.

"This option prohibits the use of Arguments.caller and Arguments.callee. Both of them. Incoming calls and. It's called a lot of optimizations and it's impossible to let them be discarded in a future version of JavaScript. In fact, the ECMAScript 5 standard does not allow the use of Arguments.callee in strict mode. 】

Noempty

This option warns if you have a empty block in your code. JSLint is originally warning for all empty blocks and we simply made it optional. There were no studies reporting that empty blocks in JavaScript break your code on any.

"This option warns you when you have an empty block of code. JSLint's initial warning of all the empty blocks, we just made an optional "

nonbsp

This option is warns about "non-breaking whitespace" characters. These characters can is entered with Option-space on MAC computers and has a potential of breaking in web pages.

"This option warns about the" non-disruptive spaces "character. These characters can be used on Mac computer options, spaces, and have the potential to break non-UTF8 pages. 】

Nonew

This option prohibits the use of constructor functions for side-effects. Some people like-to-call constructor functions without assigning it result to any variable:

new MyConstructor();

There is no advantage in this approach over simply calling since the object that the MyConstructor operator new creates isn ' t us Ed anywhere so you should generally avoid constructors like this one.

"Suppress empty constructors This option disables the use of the constructor's side effects. Some people prefer to call a constructor without specifying the result of any variable: "

Plusplus

This option prohibits the use of unary increment and decrement operators. Some people think that ++ and -- reduces the quality of their coding styles and there is programming Languages-such As Python-that go completely without these operators.

"This option disables the use of unary increment and decrement operators. Some people think that + + and--reduce the quality of their coding style and have programming languages like Python, that goes completely without these operators. 】

Quotmark

This option enforces the consistency of quotation marks used throughout your code. It accepts three values: true if you don ' t want to enforce one particular style but want some consistency, "single" if you WA NT to allow is only a single quotes and if you want to allow only "double" double quotes.

"This option forces the use of quotation marks throughout the code to be consistent. It accepts three values: true if you do not want to force a particular style, but to be certain of coherence, "single" If you want to only allow single quotes and "double" if you want to allow only double quotes. 】

Undef

This option prohibits the use of explicitly undeclared variables. This option is very useful for spotting leaking and mistyped variables.

/*jshint undef:true */function test() {  var myVar = ‘Hello, World‘;  console.log(myvar); // Oops, typoed here. JSHint with undef will complain}

IF your variable is defined in another file, you can use the directive to tell /*global ... */ Jshint about it.

"This option disables the use of variables that do not display declarations. This option is useful for variables that detect leaks and spelling errors. 】

Unused

This option warns the define and never use your variables. It is very useful for general code cleanup, especially when used in addition to undef .

/*jshint unused:true */function test(a, b) {  var c, d = 2;  return a + d;}test(1, 2);// Line 3: ‘b‘ was defined but never used.// Line 4: ‘c‘ was defined but never used.

In addition to, this option would warn you about unused global variables declared via /*global ... */ directive.

This can is set to vars a check for variables, not function parameters, or to strict check all variables and Paramet ERs. The default (TRUE) behavior is to allow unused parameters, which is followed by a used parameter.

"This option warns you when you define and never use a variable. It is useful for general code cleanup "

Strict

This option requires any functions to run in ECMAScript 5 ' s strict mode. Strict mode is a-restricted variant of JavaScript. Strict mode eliminates some JavaScript pitfalls that didn ' t cause errors by changing them to produce errors. It also fixes mistakes that made it difficult for the JavaScript engines to perform certain optimizations.

Note: This option enables strict mode for function scopes only. It prohibits the global scoped strict mode because it might break third-party widgets on your page. If you really want to use global strict mode, see the globalstrict option.

This option requires all the features that are running in strict mode in ECMAScript 5. Strict mode is a variant restriction that chooses to join JavaScript. Strict mode eliminates some javascript flaws that do not change them to produce errors that result in errors. It also corrects errors, making it difficult to perform certain optimizations on the JavaScript engine.

Note: This option turns on the only functional range of strict mode. It prohibits strict mode on a global scale as it may disrupt third-party widgets on your Web pages. If you really want to use global strict mode, see the Globalstrict option.

Trailing

This option makes it an error to leave a trailing whitespace in your code. Trailing Whitespaces can is source of nasty bugs with multi-line strings in JavaScript:

// This otherwise perfectly valid string will error if// there is a whitespace after var str = "Hello World";
【通过该选项,错误的留在你的代码中的尾随空格。尾部空格可以是讨厌的错误在JavaScript中使用多行字符串来源:】

Maxparams

This option lets you set the max number of formal parameters allowed per function:

/*jshint maxparams:3 */function login(request, onSuccess) {  // ...}// JSHint: Too many parameters per function (4).function logout(request, isManual, whereAmI, onSuccess) {  // ...}
【此选项允许您设置的每个函数允许的形式参数的最大数量】

MaxDepth

This option lets the control how nested does you want your blocks to be:

/*jshint maxdepth:2 */function main(meaning) {  var day = true;  if (meaning === 42) {    while (day) {      shuffle();      if (tired) { // JSHint: Blocks are nested too deeply (3).          sleep();      }    }  }}
【此选项可让您控制如何嵌套的数量,你希望你的模块是:】

Maxstatements

This option lets you set the max number of statements allowed per function:

/*jshint maxstatements:4 */function main() {  var i = 0;  var j = 0;  // Function declarations count as one statement. Their bodies  // don‘t get taken into account for the outer function.  function inner() {    var i2 = 1;    var j2 = 1;    return i2 + j2;  }  j = i + j;  return j; // JSHint: Too many statements per function. (5)}
【此选项允许您设置每个功能允许报表的最大数量:】

Maxcomplexity

This option lets you control cyclomatic complexity throughout your code. Cyclomatic complexity measures the number of linearly independent paths through a program ' s source code. Read more about cyclomatic complexity on Wikipedia.

"What does it mean to control complexity?"

This option allows you to control the cyclomatic complexity throughout the code. Cyclomatic complexity measures the number of linear independent paths through the source code of a program. Learn more about the complexities on the lap Wikipedia. 】

MaxLen

This option lets your set the maximum length of a line.

"This option allows you to set the maximum length of a row"

Environments

These options let Jshint know about some pre-defined global variables.

Browser

This option defines globals exposed by modern Browsers:all the "the" good old and to the document navigator HTML5 and FileReader ot Her new developments in the browser world.

"Support code to run on the browser, including the relevant API"

Note: This option doesn ' t expose variables like alert or console . See option for more devel information.

Couch

This option defines globals exposed by CouchDB. CouchDB is a document-oriented database, can be queried, and indexed in a MapReduce fashion using JavaScript.

"This option defines the exposure global for the COUCHDB. COUCHDB is a document-oriented database that can be queried and indexed in a way that uses JavaScript mapreduce. 】

Devel

This option defines globals that is usually used for logging Poor-man ' s debugging: console , alert , etc. It is usually a good idea to not ship them in production because, for example, console.log breaks in legacy versions of the Internet Explorer.

"Developing and debugging APIs used, this option defines global variables, usually used to log in to poor debugging: consoles, reminders, etc., this is usually a good idea to not ship them in production, because, for example, the old version of Console.log in Internet Explorer breaks. 】

Dojo

This option defines globals exposed by the Dojo Toolkit.

Jquery

This option defines globals exposed by the JQuery JavaScript Library.

MooTools

This option defines globals exposed by the MooTools JavaScript framework.

Node

This option defines globals available when your code is running inside of the Node runtime environment. node. JS is a server-side JavaScript environment this uses an asynchronous Event-driven model. This option also skips some warnings, make sense in the browser environments but don ' t do sense in Node such as file -level use strict pragmas and console.log statements.

nonstandard

This option defines non-standard but widely adopted globals such as escape and unescape .

Phantom

This option defines globals available when your core is running inside of the PHANTOMJS runtime environment. Phantomjs is a headless WebKit scriptable with a JavaScript API. It has fast and native support for various web standards:dom handling, CSS selector, JSON, Canvas, and SVG.

Prototypejs

This option defines globals exposed by the Prototype JavaScript framework.

Rhino

This option defines globals available when your code is running inside of the Rhino runtime environment. Rhino is a open-source implementation of JavaScript written entirely in Java.

Worker

This option defines globals available if your code is running inside of a Web Worker. Web Workers provide a simple means for Web content to run scripts in background threads.

Wsh

This option defines globals available when your code was running as a script for the Windows script Host.

Yui

This option defines globals exposed by the YUI JavaScript framework.

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.