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