Sublime2 using Jshint

Source: Internet
Author: User

Reasonable configuration of Jshint can help write high-quality code, through the Sublime2 plugin

Jshint Gutter

Can quickly provide development efficiency and reduce the number of bugs.

1. Installing the Jshint Gutter Plugin

Sublime2 in accordance with the plugin is pretty easy, but we need to save the JS file, we detect the quality of the code, you need to

Perferences->package Setting, Jshint gutter, Set Plugin Options

Set "Lint_on_save" to true.

The following is the most critical: what kind of strategy to detect JS, you can add a file in the JS directory. JSHINTRC, in this file configuration detection JS detection.

Configuration items are divided into four categories:

1.1.Enforcing://Set the code style to rigorous attributes: for example:

{        "Strict":false,//Use Strict mode"Unused":true,//variable not used"CamelCase":true,//the variable must be a hump"Curly":true,//loops or conditions must be surrounded with curly braces"Latedef":true,//disallow definitions before using variables, ignoring function function declarations"Newcap":true,//constructor function first letter uppercase"Undef":true          //variable not defined}

1.2. Relaxing://Good organization of code: for example:

{    "maxparams":  4,          / / Maximum number of parameters    "maxdepth":   4,          //  Maximum nesting depth    "maxcomplexity":true,     // complexity detection    "MaxLen":             // Maximum number of rows    " Evil ":true               // control eval use warning }

1.3.Environments://Your Code Runtime environment (NODEJS, browser, jQuery)

{    false,      / / Browser environment    true,          //  Define global variables for debugging: console, alert    "jquery":true,         //jquery environment    " Node ":true            //node Environment }

1.4.globals://a custom global variable

{   "globals": {        "$":true,            //$ for global variable        "jQuery":  True     //jquery is a global variable     }}

After writing the code to save, you can find your JS bug.

The red box indicates that you have a problem with the code, click on the left side of the??, in the status bar there is a specific problem with the line:

There is another way to see your code: Tools (Sublime2 menu)->jshint, Lint Code, the input box that pops up shows the error or warning prompt.

2. Configuration of the JSHINTRC

A total of three ways to configure:

Above is the first way,

The second way is to write the configuration information in the Jshintconfig field in the Package.json file, which is generally used in the Nodejs project. If your code is packaged with grunt, you need to use Grunt-jshint to check the syntax, configured in the Gruntfile.js file, such as:

Finally, there is an inline method, which can inline a function, or inline a file,

It only works for this function.

3. Command line using Jshint

Install the Jshint plugin first: sudo npm install-g jshint//global installation.

Verify that the installation was successful.

command line Direct Input command:jshint main.js.

Sublime2 using Jshint

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.