JSHint-Use of javascript syntax checking standard tools and integration with Sublime
- 1. Install jshint of nodejs
- Install the Node. js Environment
- Install nodejs jshint [4] csshint
- Ii. install and configure jshint in sublime
- Method 1: Use Sublimelinter to support css and other language Verification
- Method 2: Use Sublime JSHint Gutter and only support js Verification
- Iii. Three configuration methods for jshint check rules [1]
- 1. Custom. jshintrc File
- 2. Put the configuration in the package. json file of the project, under jshintConfig
- 3. Inline configuration)
- 4. Configure. jshintrc in Sublimelinter or JSHint Gutter
- V. detailed definition of jshintrc configuration in Chinese [2], official configuration list [3]
- 1. Enforcing options if it is set to true, more error messages will be generated.
- 2. Loose options (Relaxing options) If set to true, fewer error messages will be generated.
- 3. Environment (Environments)
JSHint, a community-driven tool that discovers errors and potential problems
JSLint error Parsing1
1. Install Node. js jshint to install the Node. js Environment
Jshint functions must be supported by node. js. Therefore, go to the node. js official website and click the version of the current platform to download and install jshint.
Install nodejs jshint
2 csshint$ Npm install-g jshint $ npm install-g csshint # test $ jshint-v $ csshint-v # Use verification test alone $ jshint myfile. jsmyfile. js: line 10, col 39, Octal literals are not allowed in strict mode.1 error
Ii. How to install and configure jshint in sublime I. Use Sublimelinter to support css and other language VerificationUse sublime package control to install Sublimelinter
In sublime, press Cmd + Shift + P to open the command search window, enter pci, find packge control install, and press Enter.
Wait for the package search window to pop up. Enter Sublimelinter and press enter to install the package.
Then install SublimeLinter-jshint and SublimeLinter-csshint in the same way.
In this case, you can open the editor and view the js file. You will find that the syntax check has been completed.
View SublimeLinter-jshint Settings, right-click and choose Sublimelinter-> Open User Settings
Disable Sublimelinter-jshint, right click-> Sublimelinter-> Toggle Linter, and press Enter.
Method 2: Use Sublime JSHint Gutter and only support js VerificationIn sublime, press Cmd + Shift + P to open the command search window, enter pci to find packge control install and press Enter. Wait until the package search window is displayed, enter js gutter, and press enter to install.
JS Gutter Configuration
By default, the check is disabled for js gutter. It is automatically checked when setting and editing, loading or saving.
Right-click-> JSHint-> Set Plugin Options and change the value of false to true to enable the check.
{ "lint_on_edit": true, "lint_on_load": true, "lint_on_save": true}
Iii. Three configuration methods for jshint check rules31. Custom. jshintrc FileIn general, the. jshintrc file is placed in the module root directory. If not found, it will always go up and find the directory until the root directory/of the file system is found. If not, the default rule is used.
2. Put the configuration in the package. json file of the project, under jshintConfig3. Inline configuration)Configure the following in the annotations in the js file:
/* jshint undef: true, unused: true *//* globals MY_GLOBAL */
4. Configure. jshintrc in Sublimelinter or JSHint GutterRight-click JSHint Gutter-> JSHint-> set Linting Preference default. jshintrc File
Right-click Sublimelinter-> Open User Settings to specify the. jshintrc file path
V. detailed definition of jshintrc Configuration4. Official configuration list51. Enforcing options if it is set to true, more error messages will be generated.{"Bitwise": true, // disables bitwise operators. bitwise operators are rarely used in JavaScript. They are often used to convert & into & "curly": true, // The loop or condition statement must be enclosed by curly brackets "eqeqeq": true, // force the third equal sign "es3": true, // compatible with low-level browsers IE 6/7/8/9 "freeze": true, // prohibit rewriting of native object prototype, such as Array, Date/* Array. prototype. count = function (value) {return 4 ;}; //-> Warning: Extending prototype of native object: 'array '. adding attributes to native objects does seem convenient, but it also brings a potential problem: if multiple projects add the same attributes (or functions) to the same object ), conflicts are likely to occur. If a segment of logic depends on Object Property traversal, an error may occur. */"Immed": true,/** anonymous function call is required (function () {// body} (), instead of (function () {// body }) (); this is to indicate that the expression value is the result of the function, not the function itself */"indent": 4, // code indent "latedef": "nofunc ", // disable the use of variables before definition. Ignore the function declaration "newcap": true, // The initial letter of the constructor function is capitalized "noarg": true, // disable the use of arguments. caller and arguments. callee will be discarded in the future, and arguments will not be used in ECMAScript 5. when callee "quotmark": false, // if it is true, do not mix single quotes and double quotes "undef": true, // The variable is not defined as "unused": true, // The variable does not use "strict": true, // strict mode "maxparams": 4, // maximum number of parameters "maxdepth": 4, // maximum nested depth "maxcomplexity": true, // complexity detection "maxlen": 600, // maximum number of rows "predef": ["before", "beforEach ", "after", "afterEach", "-toberemoved"] // use a custom environment variable, there is a-sign before the variable to remove the secondary variable from the Environment // the pre-defined variable is ReadOnly and cannot be used in the comments of the js file}
2. Loose options (Relaxing options) If set to true, fewer error messages will be generated.{"Asi": true, // control the warning "boss": true if the semicolon is missing, // control the warning "debug": true if the semicolon is missing, // "debug": true "edevil": true, // controls eval use warning "lastsemic": true, // check whether the semicolon after the last declaration of a line of code misses "laxcomma": true, // check unsafe lines, ignore the comma at the beginning of the programming style "loopfunc": true, // check nested function "multistr": true, // check the multi-line string "notypeof": true, // check the invalid typeof operator value "sub": true, // person ['name']. person. name "supernew": true, // new function (){...} and new Object; "validthis": true // use this in non-constructor functions}
3. Environment (Environments){"Browser": true, // predefines the global variables such as document, navigator, and FileReader. "devel": true, // defines the global variables used for debugging: console, alert "jquery": true, // defines the global variable $ "node": true, // defines the global variable module export and so on}
This article permanently updates the link address: