Configuring eslint in vscode

Install Nodejs and then eslint Use global installation: n...

Install Nodejs and then eslint

Use global installation:
npm install -g eslint
npm install -g eslint-plugin-html

After installation, we use the "eslint --init" command to generate a configuration file in the user directory (or anywhere you like): ". eslintrc.js“
After executing the command, we can select the corresponding code style or customize it. Here I use the public - > standard - > JSON style rules. For the customized rules, refer to:

{ "plugins": [ // "react", "html" ], "env": { "node": true, "jquery": true, "es6": true, "browser": true }, "globals": { "angular": false }, "parser": "babel-eslint", "rules": { //Official document http://eslint.org/docs/rules/ //Parameters: 0 off, 1 warning, 2 error // "quotes": [0, "single"], / / single quotes are recommended // "No inner declarations": [0, "both"], / / declaring variables or functions inside {} blocks is not recommended "no-extra-boolean-cast": 1, //Redundant exclamation point to Boolean "no-extra-semi": 1, //Extra semicolons "no-extra-parens": 0, //Extra brackets "no-empty": 1, //Empty code block //Undefined before use "no-use-before-define": [ 0, "nofunc" ], "complexity": [0, 10], //Cycle complexity greater than* //Define the last extra comma of an array or object "comma-dangle": [ 0, "never" ], // It is not allowed to assign values to global variables, such as window ='abc ' "no-global-assign": ["error", { // Define exceptions // "exceptions": ["Object"] }], "no-var": 0, //Replace var with let or const "no-const-assign": 2, //const reassignment not allowed "no-class-assign": 2, //class reassignment is not allowed "no-debugger": 1, //debugger debugging code not removed "no-console": 0, //console not deleted "no-constant-condition": 2, //Constant as condition "no-dupe-args": 2, //Duplicate parameter "no-dupe-keys": 2, //Duplicate object properties "no-duplicate-case": 2, //case repetition "no-empty-character-class": 2, //Regular cannot match any value "no-invalid-regexp": 2, //Invalid regular "no-func-assign": 2, //Function assigned "valid-typeof": 1, //Invalid type judgment "no-unreachable": 2, //Impossible code "no-unexpected-multiline": 2, //A lack of semicolons at the end of a line can cause some surprises "no-sparse-arrays": 1, //Comma in array "no-shadow-restricted-names": 2, //Keywords and naming conflict "no-undef": 1, //Variable not defined "no-unused-vars": 1, //Not used after variable definition "no-cond-assign": 2, //Prohibit assignment operation in conditional statement "no-native-reassign": 2, //Do not overwrite native objects "no-mixed-spaces-and-tabs": 0, //Code style optimization-------------------------------------- "no-irregular-whitespace": 0, "no-else-return": 0, //return, else is redundant in else code block "no-multi-spaces": 0, //Multiple spaces are not allowed //Suggested writing method of object direct quantity: no space before the next space "key-spacing": [ 0, { "beforeColon": false, "afterColon": true } ], "block-scoped-var": 1, //Variables should be declared in an external context, not in {} code blocks "consistent-return": 1, //Function return value may be of different types "accessor-pairs": 1, //object getter/setter methods need to appear in pairs //The newline call object method point operator should be written at the beginning of the line "dot-location": [ 1, "property" ], "no-lone-blocks": 1, //Extra {} nesting "no-labels": 1, //Useless mark "no-extend-native": 1, //Disable extending native objects "no-floating-decimal": 1, //Floating point type needs write all forbidden. 1 or 2. Write method "no-loop-func": 1, //Prohibit defining functions in the body of a loop "no-new-func": 1, //Prohibit new Function(...) writing "no-self-compare": 1, //Do not allow comparison with yourself as a condition "no-sequences": 1, //Suppress comma operators that may cause ambiguous results "no-throw-literal": 1, //It is forbidden to throw a direct quantity that should be an Error object //Assign when return is not allowed "no-return-assign": [ 1, "always" ], //Duplicate declaration not allowed "no-redeclare": [ 1, { "builtinGlobals": true } ], //Expression not executed "no-unused-expressions": [ 0, { "allowShortCircuit": true, "allowTernary": true } ], "no-useless-call": 1, //Meaningless function call or apply "no-useless-concat": 1, //Meaningless string concat "no-void": 1, //Disable void "no-with": 1, //Disable with "space-infix-ops": 0, //Space before and after operator //jsdoc "valid-jsdoc": [ 0, { "requireParamDescription": true, "requireReturnDescription": true } ], //Mark unwritten comments "no-warning-comments": [ 1, { "terms": [ "todo", "fixme", "any other term" ], "location": "anywhere" } ], "curly": 0 //if, else, while, for code blocks are surrounded by {} } }

The "package.json" file of the project needs to be set in the project to configure ESLint. If not, you can use "npm init" to set it.

5 May 2020, 10:25 | Views: 7615

Add new comment

For adding a comment, please log in
or create account

0 comments