ESLint is an open source JavaScript code inspection tool that validates code to detect potential problems in code, such as unused variable definitions, function definitions with duplicate arguments, variable names not named according to the specification, and so on.

VSCode can install plugins directly: vscode-esLint

Rules:

ESLint comes with a large number of rules, which should be modified according to the following requirements:

‘OFF’ or 0 – turn off the rule ‘WARN’ or 1 – turn on the rule, using warning level errors: WARN (will not cause the program to exit) ‘error’ or 2 – turn on the rule, using error level errors: error (when triggered, the program will exit)

Usage:

Install dependencies

"Eslint" : "^ 6.7.2", "eslint plugin - vue" : "^ 6.2.2", "eslint - plugin - import" : "^ 2.20.2", "eslint - plugin - node" : "^ 11.1.0 eslint -", "plugin - the promise", "^ 2", "eslint - plugin - standard" : "^ 4.0.0"Copy the code

Create the.eslintrc.js file in the project root directory

The general configuration is as follows:

// .eslintrc.js module.exports = { root: true, env: { node: true }, extends: [ 'plugin:vue/essential' ], plugins: ['vue'], parserOptions: {parser: 'babel-eslint'}, rules: {// Disable alert, confirm, prompt, console, debugger 'no-alert': process.env.NODE_ENV === 'production' ? 'warn' : 'off', 'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off', 'no - the debugger: process. The env. NODE_ENV = = =' production '? 'warn' : 'off', 'eqeqeq' : 'warn, / / requires the use of = = = and! == 'no-dupe-args': 'error', // disallow duplicate key 'no-eval' in object literals: 'error', // disallow eval() 'no-self-compare': 'error', // disallow self-comparison 'no-self-assign': 'error', // disallow self-assignment 'no-unused-vars': 'error', // disallow the unused variable 'no-const-assign': 'error', // disallow modifying the const variable 'no-fun-assign ': 'error', // Disallow reassignment of function declaration 'camelcase': 'error', // enforce camel spelling naming convention 'no-mixed-spaces-and-tabs': 'error', // Disallow mixing of tabs and Spaces. 'indent': [' WARN ', 2], // Indent style is not hard and fast here, but uniform within product groups. 'quotes': [' warn ', 'single'], / / request quotes type ` ` ' ' ' 'semi: [' error' and 'always'], forcing a semicolon}} / / statementsCopy the code

then

Vue-cli3 turns Lint on lintOnSave:true in vue.config.js

Now it’s all about setting it up in vscode

Open vscode and search for the plugin eslint

Installing a plug-in

Once installed, re-open the project and you can use it