Jshint Configuration Item Description

Source: Internet
Author: User
Tags deprecated shuffle dojo toolkit jquery library couchdb

Jshint Configuration Item Description
author 9I attention 2016.01.26 17:07 words 3475 read 4081 comments 0 likes 2 What is jshint?

The official website is described As:

jshint, A Static Code analysis Tool for JavaScript;
This is jshint, a-tool, helps to detect errors and potential
Problems in your JavaScript Code.

This shows that Jshint is a JavaScript code Analysis detection Tool that not only helps us detect JS code errors and potential problems, but also helps us to standardize code Development.

Jshint installation (IED webstrom) NPM installation
    install jshint -g
Jshint settings
    • The Webstrom has built-in jshint and jslint:
      Default_setting-->languages and Frameworks-->javascript-->code quality Tools-->jshint

      Paste_image.png
Jshint Configuration Three Ways
  • Manual Configuration Via--config tag;
  • Using The. jshintrc file:

    This setting allows you to have different profiles for each project. Put your files into the project root directory, as long as you run Jshint from anywhere in your project directory tree, will use the same configuration File.

  • The configuration is placed in the Project's Package.json file, jshintconfig below
    The configuration file is a simple JSON file that specifies the Jshint option to turn on or off. For example, the following file will enable warning for undefined and unused variables and tell jshint global variable name My_global
      {    "undef": true,    "unused": true,   "predef": [ "MY_GLOBAL" ] }
    Inline configuration
  • In addition to using configuration files, you can start with jshint or globals in your files and configure Jshint with a colon-separated list of values for the configuration Item. For example, The following code fragment enables warning for undefined and unused variables and tells the Jshint global variable to name My_global.
      undef: true, unused: true */ /* globals MY_GLOBAL */
    Jshint can be configured with one or more rows, and if placed inside a function, only the function is Affected. Jshint Ignore
  • Ignore tells Jshint to ignore a block of code
    Code here will be linted with JSHint. /* jshint ignore:start */ // Code here will be ignored by JSHint. /* jshint ignore:end */
    All the code between Jshint Ignore:start and Ignore:end will be jshint ignored, so you can use an extended framework like Facebook React.
  • You can omit one line:
      ignoreThis(); // jshint ignore:line
    Jshint configuration options
  • Bitwise
    Disable bit operators, bit operators are used less in JavaScript, and often are && errors are lost to &.
      bitwise: true
  • CamelCase
    Warning: This option has been deprecated and will be removed in the next major version of Jshint.
    This option forces all variable names to be underlined using hump style or Upper_case.
      camelcase:true/false
  • Curly
    Loops or conditional statements must be surrounded with curly braces.
    This option requires you to always put curly braces in the block loop and Condition. JavaScript blocks can be omitted when parentheses contain only one statement, for example:
       while (day)      shuffle();
    however, in some cases it can lead to an error (you might think that sleep () is part of a loop, and in fact it is not)
       while (day)        shuffle();     sleep();
  • Enforceall
    Warning: This option has been deprecated and will be removed in the next major version of Jshint.
    It enables all enforcement options and disables all relaxing options defined in that version;
  • Eqeqeq
    Set to True to disallow use of this option = = and! =, forcing use = = = And!==.
     eqeqeq: true
  • Es3
    Warning: This option will be removed in the next major version of jshint, using Esversion:3 instead.
    Use the ECMAScript 3 Specification. Use this option primarily to be compatible with low-level browsers IE 6/7/8/9-and other legacy JavaScript environments.
  • Es5
    Warning: This option will be removed in the next major version of jshint, using Esversion:5 instead.
    This option allows the syntax to define the ECMAScript 5.1 specification, which includes allowing reserved keywords as Object properties.
  • Esversion
    This option is used to specify the ECMAScript version code that must be Followed. It can assume one of the following values:
    3--if you need executable programs in old browsers such as Internet Explorer 6/7/8/9-and other legacy JavaScript environments
    5--first defines the ECMAScript 5.1 specification in the Syntax. This includes allowing reserved keywords as Object properties.
    6--tells Jshint code to use ECMAScript 6 specific syntax. Please note that not all browsers implement Them.
  • Forin
    This option requires all for in loops to filter the Object's Item. He allows for traversal in a declaration the names of all properties of an object include attributes inherited through the prototype Chain.
    for (key in obj) {    if (obj.hasOwnProperty(key)) { // We are sure that obj[key] belongs to the object and was not inherited. } }
  • Freeze
    This option disables rewriting of native Object's prototype columns such as array, date, and so On.
  • Funcscope
    Disallow external access to internally declared variables
    function test() {   if (true) { var x = 0; } x += 1; // Default: ‘x‘ used out of scope. // No warning when funcscope:true }
  • Futurehostile
    Allows warning of identifiers defined in future versions of Js.
  • Globals
    This option can be used to specify a white list of global variables that are not formally defined.
    Configure globals in a single file to see the inline Configuration.
  • Immed
    Warning: This option has been deprecated and will be removed in the next major version of Jshint.
    Functions that need to be called directly must be surrounded by parentheses, such as:(function(){}());
  • Indent
    Warning: This option will be removed in the next major version of Jshint.
    Set Code indent length
  • Iterator
    Suppresses warnings about the iterator Property.
    This property does not support all browsers, so use it with Care.
  • Latedef
    Disables the definition before using Variables.
    Setting this option to "nofunc" will allow the function declaration to be Ignored.
  • Maxcomplexity
    Sets the code file independent linear path maximum complexity Detection.
  • MaxDepth
    Sets the maximum nesting depth of code.
    // 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(); } } } }
  • Maxerr
    Sets the maximum number of Jshint warnings. Default 50
  • MaxLen
    Warning: This option will be removed in the next major version of Jshint
    Set maximum number of rows
  • Maxparams
    This option allows you to set the maximum number of parameters for each function

    // jshint maxparams:3 function login(request, onSuccess) { // ... } // JSHint: Too many parameters per function (4). function logout(request, isManual, whereAmI, onSuccess) { // ... }
  • Maxstatements
    This option allows you to set the maximum number of declarations allowed by the Statement:
    Shint 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)}                 
    Functions are also counted as Declarations.
  • Newcap
    Warning This option has been deprecated and will be removed in the next major version of Jshint
    Requires all constructor usage new F() forms.
  • Noarg
    It is forbidden to use this option Arguments.caller and Arguments.callee. These two. caller
    And. Callee will be Deprecated. In fact, ECMAScript 5 Strict mode prohibits the use of Arguments.callee
  • Nocomma
    This option disables the use of the comma Operator.
  • Noempty
    Warning This option has been deprecated and will be removed in the next major version of Jshint.
    Empty code block Warning.
  • nonbsp
    Whitespace warning for Non-newline
  • Nonew
    This option disables the use of the new constructor Function. Some people prefer to call a constructor, but not assign a value to any object:
    new MyConstructor();
  • Notypeof
    Check the value of the invalid typeof operator
    // ‘fuction‘ instead of ‘function‘ if (typeof a == "fuction") { // Invalid typeof value ‘fuction‘ // ... }
  • Predef
    Extended implicit global variables
  • Quotmark
    Warning This option has been deprecated and will be removed by the next major version of Jshint.
    This option executes the consistency of quotation marks in the Code. It accepts a value of three:
    • The True--code string prohibits single-quote double-quotes from being mixed,
    • "single"--only One quotation mark is allowed
    • "double"--only double quotes are Allowed.
  • Shadow
    Check for duplicate definitions of variables
    He accepts a value of 4:
    • "inner" only checks if the definition is repeated in the same scope
    • "outer" Check External scopes
    • False as with Inne
    • True to allow variable overrides
  • Singlegroups
    Prohibit use of grouping operators
    // jshint singleGroups: true delete(obj.attr); // Warning: Unnecessary grouping operator.
  • Strict
    ECMAScript 5 Strict mode
    • "global"-strict mode "use strict" at the global level;
    • "implied"-the Document uses "use strict";
    • False-prohibit use of Strict mode
    • True-a "use strict" must be used above the function;
  • The
  • undef
    variable is undefined
    //jshint Undef:truefunction test (var myVar =  ' Hello, World '; //Oops, typoed Here. Jshint with undef will complain console.log (myvar);} If you define a variable in another file, you can use the The global directive tells Jshint. 
  • The
  • unused
    variable definition is not used
     // Jshint unused:true function test< Span class= "hljs-params" > (a, b) {var c, d = 2; return A + d; } Test (1, 2); //line 3: ' B ' is defined but never Used. //line 4: ' C ' is defined but never used        
  • Varstmt
    When set to true, disables declaring variables with Var
    // jshint varstmt: true var a; // Warning: `var` declarations are forbidden. Use `let` or `const` instead.
    When the loose option is set to true, these options cause code jshint to produce fewer warnings.
  • Asi
    Prohibit missing semicolon warning
  • Boss
    The value of the suppress comparison expression does not reach the expected warning.
    normally, The code if (a = 10) {} is an error, but he could have used it
    person; person = people[i]; i++) {}
    You can prohibit this error, such as
    person; (person = people[i]); i++) {}
  • Debug
    Ignore debugger
  • Elision
    Tells the jshint code to use the ES3 array to omit elements, or empty elements (for example, [1,,, 4,,, 7]
    ).
  • Eqnull
    suppress = = NULL Comparison. Usually this is useful when you want to check whether a variable is null
    or undefined
  • Eqnull
    Warning This option will be replaced by Esversion:6 in the next major version of Jshint
    Using ECMAScript 6 specific syntax, some browsers do not support
  • Evil
    Use of Eval is forbidden
  • Expr
    The use of expressions is forbidden, generally using function calls.
  • Globalstrict
    The next version will use Strict: "global" instead.
    Global strict mode conflicts with Third-party widgets, so it is not recommended.
  • Lastsemic
    Check that a line of code finally declares whether the semicolon behind it is missing
    var name = (function() { return ‘Anton‘ }());
  • Laxbreak
    Check for unsafe broken lines (the next version will be deleted)
  • Laxcomma
    Check the programming style of the comma at the front of the line of code
     var obj = {    name: ‘Anton‘   , handle: ‘valueof‘  , role: ‘SW Engineer‘ };
  • Loopfunc
    The inner loop is forbidden, and the internal loop that defines the function can cause such errors:
    var nums = [];  for (var i = 0; i < 10; i++) { nums[i] = function (j) { return i + j; }; }nums[0](2); // Prints 12 instead of 2
    To resolve the above code, you need to copy the variable I:
    var nums = [];    for (var i = 0; i < 10; i++) { (function (i) { nums[i] = function (j) { return i + j; }; }(i)); }
  • Moz
    Jshint Mozilla Extension. This option is not required unless you are developing a dedicated Firefox web Browser.
  • Multistr
    will be removed in the next release
    This option suppresses the warning of multiple lines of string. Allowing multiple lines of string in JavaScript is dangerous, and if you carefully enter a space between an escape character () and a new line, the entire string error will Result.
    Note that even though this option allows the correct multiline string, it still warns that there are no escape characters between the multiline string or with any escape characters and Spaces.
    // jshint multistr:truevar text = "Hello\World"; // All good.text = "HelloWorld"; // Warning, no escape character.text = "Hello\World"; // Warning, there is a space after \
  • Noyield
    Check that the function generator does not have a yield declaration
  • Plusplus
    Prohibit the use of unary increment and decrement operators
  • Proto
    Suppress __proto__ warnings about attributes
  • Scripturl
    Scripting URL targeting is prohibited, such asjavascript:...
  • Sub
    The next version will be deleted
    Check [] use, can use. instead of []
    person[‘name‘] vs.person.name.
  • Supernew
    Check out the weird structurenew function () { ... }和 new Object;
    Such a structure is sometimes used in a single column in Javascript:
    var singleton = new function() { var privateVar; this.publicMethod = function () {} this.publicMethod2 = function () {} };
  • Validthis
    Note: You can use this option only in the scope of the function
    Use this in a non-constructor function
  • Withstmt
    Check the With Usage Declaration.
    The WITH declaration statement can cause confusion between the developer and the unexpected global variable Definition.
Environment variables

These options let jshint know some pre-defined global variables.

  • Browser
    Exposes global variables for browser properties, such as window,document;
    Note: This option does not expose variable alert or console.
  • Browserify
    This option defines the global variables used when using the Browserify tool to build a project
  • Couch
    This option defines the global exposure Couchdb. COUCHDB is a document-oriented database that can query and index mapreduce in a way that uses JavaScript
  • Devel
    This option defines the global variables, which are typically used for log debugging: console, alert, etc.
  • Dojo
    This option defines the globally exposed dojo Toolkit.
  • Jasmine
    This option defines the unit test framework for global exposure JASMINE.
  • Jquery
    This option defines a globally exposed jquery library.
  • Mocha
    This option defines the UI Mocha Unit test framework for globally exposed "BDD" and "TDD".
  • Module
    This option tells Jshint that the input code describes a ECMAScript 6 Module. The code for all modules is interpreted as strict mode Code.
  • MooTools
    This option defines the globally exposed mootoolsjavascript Framework.
  • Node
    This option defines a global variable that can be run when your code runs in Node's runtime environment
  • nonstandard
    This option defines a non-standard but widely adopted global variable such as escape and Unescape.
  • Phantom
    This option defines the global availability of your core runtime internal PHANTOMJS runtime environment
  • Prototypejs
    This option defines the globally exposed Prototypejs Framework.
  • Qunit
    This option defines the global Exposure Qunit Unit test framework
  • Rhino
    This option defines a global variable that can be run when your code runs in Rhino's runtime Environment. Rhino is an open source implementation of JavaScript written entirely in Java.
  • Shelljs
    This option defines the global Exposure Shelljs Library
  • Typed
    This option defines the global variable array type Constructor.
  • Worker
    This option defines the global variables that can be used when your code is running on the web Worker.web worker is a JavaScript that runs in the background, independent of other scripts and does not affect the performance of the Page.
    Web worker is supported in all major browsers, except Internet Explorer.
  • Wsh
    This option defines a global variable that can be run when your code runs in Windows Script host's run-time Environment
  • Yui
    This option defines the global exposure of the Yui Frame.

Jshint Configuration Item Description

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.