Many people give up using ESLint after they introduce it, and find that there are so many errors in their projects that they seem to become obsessive-compulsive. Small make up in this is to say in the project will use eslint, especially at the start of project building structures, agreed well, won’t appear many people to help do not have a unified code, looked at more nausea, development problems also reduce just know code at run time, ensure write grammatically correct, the style is unified code. Finally, some flexibility is traded for greater stability and maintainability.

— EsLint

ESLint is a QA tool that checks ECMAScript/JavaScript syntax rules and code styles to ensure that syntactically correct and consistent code is written.

ESLint is designed to be fully configurable, and its goal is to provide a plug-in for javascript code detection. This means you can turn off each rule and use only basic syntax validation, or mix and match bundled rules and custom rules to make ESLint work perfectly for your project.

[ESlint Chinese official website] : eslint.cn/

Check out the official website: eslint.org/

Why use ESLint?

  1. In multi-person projects, it is common for multiple people to cross-edit multiple files. This leads to a variety of coding styles in various files. The most common ones are: Spaces or tabs indented 2 Spaces or 4 Spaces or 8 Spaces Single quotation marks or double quotation marks. Do you want JavaScript to end a line with a semicolon? Do you want to add Spaces before and after keywords? The mix of styles greatly affects the readability and quality of your code. It is therefore important to maintain a consistent code style in a multiplayer project.
  2. JavaScript We know that the language is flexible. In addition to basic syntax errors that can be detected at startup, many hidden errors pop up at runtime. Unless your program has 100% test coverage, it may crash one day because a XXX is undefined. To avoid this error, you may just need to use the tool to statically analyze the code when you submit it. ESLint is a plug-in javascript code detection tool that can be used to check for common javascript code errors, as well as code style checking, so that we can specify a set of ESLint configurations to our liking and then apply them to the projects we’re writing. In order to realize the implementation of the auxiliary coding specification, effectively control the quality of the project code. So, with all the static code detection tools out there, why would we choose Eslint? The main reason is that it is flexible and easy to extend, so it has a very good ecosystem, and major editors can integrate Eslint.

Eslint has the following features?

  • 1. Everything is pluggable. You can call any rule API or Formatter API to package or define a rule or formatter.
  • 2. Any rule is independent
  • 3. There is no specific coding style, you can configure it yourself


Four, installation,

To run ESLint on Node.js, you must have NPM installed. If NPM is not installed, follow the instructions here: https://www.npmjs.com/ Once NPM is installed, run the following

  • A. Local installation

    npm install eslint --save-devCopy the code

    Generating a Configuration File./node_modules/.bin/eslint --init After that, you can run ESLint in any file or directory as follows:./node_modules/.bin/eslint index.jsIndex.js is the JS file you need to test. Any plugins or shared configurations you use (which must be installed locally to work with ESLint installed locally).

  • If you want ESLint to be available to all projects, you are advised to install ESLint globally.

    npm install -g eslint Copy the code
  • C. Generate the configuration file and initialize it

    eslint --init
    Copy the code

    Running eslint-init will generate one in the current directory.eslintrcFile in which you can configure some rules. After that, you can run ESLint in any file or directory

    eslint index.js Copy the code
  • PS:eslint --initIs the directory where esLint is set up and configured for each project and where locally installed ESLint and its plug-ins will be executed. If you prefer to use globally installed ESLint, any plugins used in your configuration must be globally installed.

Configuration of ESLint

ESLint’s design is fully configurable, which means you can either turn off each rule and run it with just basic syntax validation, or mix and match bundled rules and custom rules to make ESLint perfect for your project.

There are two main ways to configure ESLint:

1. Configuration comments – Use JavaScript comments to embed configuration information directly into a file.

2. Configuration files – Use any of the following files to specify configuration information for all directories and their subdirectories.

  • A, javascript: Use the.eslintrc.js file and export an object containing the configuration.
  • YAML:.eslintrc. YAML or.eslintrc.
  • C, yML JSON:.eslintrc.json, and this file allows JS comments
  • D. Obsolete usage:.eslintrc, this file can be JSON or YAML
  • E. Package. json: Create the eslintConfig property in package.json file, where all configuration is contained.

Js >.eslintrc.yaml >.eslintrc.yml >.eslintrc.json >.eslintrc > package.json).

The complete configuration hierarchy from highest priority to lowest priority is as follows:

1, inline configure /*eslint-disable*/ and /*eslint-enable*/ /*global*/ /*eslint-env*/

–global –rule –env -c, –config

3. Project-level configuration: .eslintrc.* or place the package.json file in the same directory as the Linted file to continue searching.eslintrc and package.json files in the ancestor directory (the parent has highest priority, then the grandparent, etc.), Up to and including the root directory or found in a configuration “root”: true.

In the absence of any configuration from (1) through (3), go back to the personal default configuration ~/.eslintrc.

Json in the form of package.json in files or eslintConfig fields in files, which ESLint will automatically find and read, or you can specify configuration files on the command line. If you have configuration files in your home directory (usually ~/), ESLint will only use it if ESLint can’t find any other configuration files. If.eslintrc and package.json find a file in the same directory,.eslintrc will take precedence and package.json will not use the file.

Several pieces of information can be configured:

There are three types of information that can be configured:

Environments: What Environments (nodejs, Browser, CommonJS, etc.) your javascript footsteps will run in.

  • Buy a ticket – The environment in which scripts are designed to run. Each environment comes with a predefined set of global variables.
  • Queue global variables – Other global variables that a script accesses during execution.
  • Rules for the system – Which rules are enabled and the fault level.

All of these options give you precise control over how ESLint handles your code.

You can specify additional global variables in configuration files or in comments. False indicates that the variable is read-only: comments: /* global var1, var2 */ /* global var1:false, var2:false */ JSON: { “globals”: { “var1”: true, “var2”: false } }


Six, rules,

  1. ParserOptions:

"parserOptions": {
"ecmaVersion": 6, // Version of ES, default is 5"sourceType": "module", / / specify the location of the code, the script | module, the default for the script."ecmaFeatures": {// specify which other language objects to use"experimentalObjectRestSpread": true,// enable extension to objects"jsx": true, // Enable JSX syntax"globalReturn":true, / / permitreturnUse globally"impliedStrict":true// Enable strict check mode}}Copy the code

By default, ESLint uses the Espree parser, whose default Settings can be changed here.

parser":"babel-eslint",

Copy the code

3. Environment Configuration (env) By default, all environment variables are false, and the environments are not in conflict, so you can use them as you like. The environment defines predefined global variables. The available environments are:

 Browser - The browser global variable.  Node-node. js global variables and the Node.js scope.  CommonJS - CommonJS global variables and CommonJS scopes (browser code using Browserify/WebPack).  shared-node-browser-node. js is a common global feature of browser.  ES6 - Enable all ECMAScript 6 features except modules (this automatically sets the ecmaVersion parser option to 6). worker - The network worker global variable.  AMD - The AMD specification defines require() and define() as global variables.  Mocha - Added all mocha test globals.  Jasmine - Added all jasmine test globals for version 1.3 and 2.0. jest - is a global variable.  Phantomjs - Phantomjs global variable.  Protractor - Protractor global variable. qunit - qunit global variable.  jquery-jquery global variables.  Prototypejs-prototype.js Global variable.  Shelljs-shelljs global variable.  Meteor - Meteor global variable.  mongo-mongodb global variables.  Applescript - Applescript global variable.  Nashorn - Java 8 The Nashorn global variable. serviceworker - the serviceworker global variable.  Atomtest-atom Tests the assistant global variable.  EmberTest - Ashes Test helper global.  Webextensions - Global Network tensions. Greasemonkey - GreasemonKey global variableCopy the code

These environments are not mutually exclusive, so you can define multiple environments at once.

You can specify the environment within a file, in a configuration file, or using the –env command line flag.

To specify the environment with comments in a JavaScript file, use the following format:

/* eslint-env node, mocha */Copy the code

env: {
node: true,},Copy the code

In a package.json file

{
    "name": "mypackage"."version": "0.0.1"."eslintConfig": {
        "env": {
            "browser": true."node": true}}}Copy the code

In YAML:

---
  env:
    browser: true
    node: true
Copy the code

4. Plugins

"plugins": ["standard"."promise"."react"].Copy the code

5. Global variables (globals) of the specified global variable value is true | false. True indicates that a variable can be overwritten, false indicates that it is not allowed to be overwritten.

"globals": {
"document": true."navigator": true."window": true."think": true
},
Copy the code

6. Custom rules (Settings)

"settings": {
"sharedData": "Hello"
}
Copy the code

7. Disable persistent lookup (root) By default, ESLint will look for configuration files in all parent folders under the root directory. This property stops the search for the parent folder once the configuration file is found

"root": true
Copy the code

8. Shared Configuration (extends)

The property can be

The eslint command, which can also be the path to inherited files.

Eslint :all: introduces all core rules of the current version of ESLint.

Eslint :recommended: Indicates that core functionality of ESLint is introduced and common bugs are reported. If the value is absolute or relative, it corresponds to the rule configuration of the import path.

"extends": recommended,
Copy the code

"extends": "./eslint-config-public.js".Copy the code

9. You can set some rules in the configuration file.

There are three levels of error in rules:

  • Either “off” or 0: disables the rule.
  • Anyway “warn” or 1: opens the rule as a warning (without affecting exit code).
  • Anyway “error” or 2: opens the rule, and acts as an error (exit code will be 1).

Example:

1. To use configuration comments for rules within a configuration file, use comments in the following format:

  • A, /* eslint eqeqeq: "off", curly: "error" */ In this example, eqeqeq is turned off and Curly turns on as an error.

  • B. You can also use a number equal to the severity of the rule:/* eslint eqeqeq: 0, curly: 2 */ 

  • C, if rules have other options, they can be specified using array literal syntax, for example: /* eslint quotes: ["error", "double"], curly: 2 */ 

2. To configure rules within the configuration file, use the rules key along with the error level and any options you want to use.

Such as:

{
    "rules": {
        "eqeqeq": "off"."curly": "error"."quotes": ["error"."double"]}}Copy the code

 

3. In YAML:

---
rules:
  eqeqeq: off
  curly: error
  quotes:
    - error
    - doubleCopy the code

To configure the rules defined in the plug-in, you must prefix the rule ID with the plug-in name and a /.

Such as:

{
    "plugins": [
        "plugin1"]."rules": {
        "eqeqeq": "off"."curly": "error"."quotes": ["error"."double"]."plugin1/rule1": "error"
    }}
Copy the code

In YAML:

---
plugins:
  - plugin1
rules:
  eqeqeq: 0
  curly: error
  quotes:
    - error
    - "double"
  plugin1/rule1: errorCopy the code

Note: When specifying rules from plug-ins, be sure to omit eslint-plugin-. ESLint internally uses only prefix names to find rules.

4. Disable rules with inline comments

  • A. To temporarily disable rule warnings in A file, use block comments in the following format: To disable rule warnings throughout A file, in A file/* eslint-disable */Top placed block comments: /* eslint-disable */ alert('foo'); /* eslint-enable */

  • B. To disable all rules on a particular line, use a line comment in one of the following formats: alert('foo'); // eslint-disable-line // eslint-disable-next-linealert('foo'); 

5. Use a configuration fileAccording to the diagram:

  • 1. The “parserOptions” property configures the parser contents. The ecmaVersion attribute configures the syntax version of the JS. The “sourceType” attribute configures the loading mode of the JS file. The value is “script” or “module”. The ecmaFeatures property configures additional language features you want to use.
  • 2. The env attribute configures a predefined global environment. We currently have three environments “ES6”, “Node” and “AMD” enabled.
  • 3. The “plugins” property configures third-party plug-ins that need to be loaded. Here we need to install the corresponding plug-in to use. 4. The “globals” attribute defines the set of global variables, and the attributes contained in this set are considered global by the tool without being warned by the no-undef rule.
  • 5. The “extends” property configures a base rule based on which the rules configured in the “Rules” property are configured.
  • 6. The “rules” property configures check rules.

Enable rules and levels to report when errors occur

There are three levels of error in rules:

  • 0 or ‘off’ : disables the rule.
  • 1 or ‘WARN’ : Opens the rule as a warning (does not result in a failed check).
  • 2 or ‘error’ : opens the rule as an error (the exit code is 1 and the check fails).

Parameter Description:

  • Parameter 1: error level
  • Parameter 2: processing mode

Configuration code comments use JavaScript comments to embed configuration information directly into a file

Example:

  • Ignore the no-undef check /* eslint-disable no-undef */ 

  • Ignore the no-new check/* eslint-disable no-new */ 

  • Set up inspection/*eslint eqeqeq: off*/ /*eslint eqeqeq: 0*/ 

Eslint checks directives

  • Check and fixeslint * --fix 

  • Checking specified files eslint app.js --fix 

Once again, some basic configuration rules and notes are attached below.

7. Basic use cases


Here’s a step-by-step example of how to use ESLint:

  1. Generate a package.json file in the project root directory

    npm init -yCopy the code

     

  2. Install ESLint (install depending on your project needs, use global install here)

    npm install -g eslintCopy the code

     

  3. Create an index.js file and write a function inside.

        function test () {
        var ret = {};
        for (var i in arguments) {
            var m = arguments[i];
            for (var j in m) ret[j] = m[j];
        }
        return ret;
    }
    console.log(test({a: 123}, {b: 456})); Copy the code

The output



4. Use ESLint to check

  eslint index.jsCopy the code

Output:



The execution result is failure because the corresponding configuration file is not found. In this case, the configuration file is used to illustrate:

During the generation process, you need to select the generation rules, support environment, and other content. The following describes some small series of generation options



The generated content is in.eslintrc.js,

module.exports = {"env": {"browser": true},"extends": "eslint:recommended"."parserOptions": {"ecmaVersion": 5},"rules": {"indent": ["error"."tab"]."linebreak-style": ["error"."unix"]."quotes": ["error"."double"]."semi": ["error"."always"]}};Copy the code

This is generated by default, leaving an extends, and the rest you can configure your own rules.

 

module.exports = {
      "extends": "eslint:recommended"
  };Copy the code

For now let’s start with the built-in ESLint :recommended configuration, which contains a set of core rules that report common problems.

In this implementation

eslint index.jsCopy the code



This occurs because the ESLint rule disables the no-console rule.

How do you avoid this error?

  • 1. Delete the console statement from the code.
  • 2. Turn this rule off in the.eslintrc.js rule, because during development tests we may need to print something, test.

module.exports = {  extends: 'eslint:recommended',  rules: {    'no-console': 'off',}};Copy the code

Re-check and again prompt no-undef



This is because JavaScript runs in many different environments, such as browsers and Node.js, and there are many software systems that use JavaScript as their scripting engine. PostgreSQL, for example, supports JavaScript as a storage engine. These environments may not have a console object. In addition, there are window objects in the browser environment, but not in Node.js. Process objects are available under Node.js, but not in the browser environment.

So in the configuration file we also need to specify the target environment for the program:


module.exports = {
  extends: 'eslint:recommended',
  env: {
    node: true,
  },
  rules: {
    'no-console': 'off',}};Copy the code


When the check is re-executed, there is no output indicating that index.js has passed the check completely.

Exceptions:

ESLint rules are designed to avoid making mistakes, but we also want to avoid making them too formal and putting the cart before the horse.

ESLint provides several ways to temporarily disable rules. For example, we can skip checking the next line with an eslint-disable-next-line comment:

// eslint-disable-next-linevar a = 123; var b = 456;Copy the code

In the example code above, var a = 123 is not checked, while var b = 456 is checked again. Under the eslint-config-lei configuration rule we used above, var b will report an error because var is not allowed to declare variables. There are also pairs of eslint-enable and eslint-disable remarks to disable checking for a piece of code, but accidentally missing one eslint-disable remark could result in all subsequent file checks being disabled, so I don’t recommend it.

Use a shared configuration file

ESLint supports adding shared Settings to configuration files. Most of the time, individuals or teams have several projects, and each project may use different rules or need to configure different rules. If they all write to the same configuration or change the configuration file every time, it will be troublesome to manage.



Create a new file such as eslint-config-public.js and add a rule or two to the contents of the file.

module.exports = {
extends: 'eslint:recommended',
env: {
node: true,
},
rules: {
'no-console': 'off'.'indent': [ 'error', 4].'quotes': [ 'error'.'single'],}};Copy the code

Then change the original.eslintrc.js file to something like this:

module.exports = {
  extends: './eslint-config-public.js'};Copy the code


Var ret = {}; var ret = {}; var ret = {}; var ret = {}; Put a space or something in front of it, and it makes a big difference.




The eslint-config-public.js public configuration file is in effect. The eslint-config-public.js public configuration file is in effect. The eslint-config-public.js public configuration file is in effect.

9. Ignore files

In our entire project, there are some files that don’t need to be checked by ESLint, so we can use ignore files.

Create a new file in our project directory called “.eslintignore “and Eslint will automatically recognize this file.

Each line in the configuration file is a glob statement in the following format:

  • Lines that start with # buy a ticket are treated as comments, regardless of the ignore mode.
  • A virtual path is the location relative to.eslintignore or the current working directory. This also affects the path passed through –ignore-pattern.
  • Ignore the pattern as with the.gitignore specification
  •  to! The opening line is a negation pattern, which will recontain a previously ignored pattern.

.esLintignore ESLint supports files to exclude files from linting processes when ESLint runs on directories. Files given as separate CLI parameters will be excluded. The.eslintignore file is a plain text file with one schema per line. It can be in the ancestor of any target directory; It affects files in its include directory and all subdirectories.

Here is a simple.eslintignore file example:

 node_modules/* 

**/vendor/*.js 

Ps: ESLint always ignores /bower_components/* in /node_modules/*, except for any modes in.eslintignore files

1. You can override this behavior by providing paths to different files. –ignore-path

 

eslint --ignore-path tmp/.eslintignore file.js
eslint --ignore-path .gitignore file.jsCopy the code

–no-ignore disables exclusion from files eslintignore, –ignore-path, and –ignore-pattern

eslint --no-ignore file.jsCopy the code

For example, if you have ignored a file in eslintignore, but you run the eslint file on the command line, you can use the –no-ignore ignore rule as a warning.

3. Use eslintIgnore in package.json

If.eslintignore does not find the file and no alternate file is specified, ESLint will look for the Eslintignore key in package.json to check for files to ignore.

{
  "name": "mypackage"."version": "0.0.1"."eslintConfig": {
      "env": {
          "browser": true."node": true}},"eslintIgnore": ["hello.js"."world.js"]}
Copy the code

Use ESLint in Webpack

  • 1. Use the ESLint loader in the WebPack configuration.

    loaders: [
    {
    test: /\.jsx? $/, exclude: /node_modules/, loader:'react-hot! babel'
    },
    {
    test: /\.js$/,
    exclude: /node_modules/,
    loader: 'eslint-loader'}}]Copy the code
  • You can also create.eslintrc and import webpack.config.js

    eslint:{ 
    configFile: './.eslintrc' 
    },Copy the code
  • 3. Use Webpack preLoaders

    module:{ 
    preLoaders:[ 
    { 
    test: /\.js$/, 
    exclude: /node_modules/, 
    loader: 'eslint-loader' 
    }, 
    ], 
    loaders:[ 
    { 
    test: /\.jsx? $/, exclude: /node_modules/, loader:'react-hot! babel'}},Copy the code
  • Ps: WebPack3 configuration

    module: {
    rules: [
    {
    test: /\.(js|jsx)$/,
    exclude: /node_modules/,
    enforce: 'pre',
    loader: 'eslint-loader'}}]Copy the code

11. Use it in the editor

You can install the ESLint integration in the editor so that errors or warnings will appear as you write code, without having to run ESLint every time to know if there is a problem.

  • Eslint can be used by visual Code by directly installing esLint in the extension and loading it.


  • 2. Use on WebStorm


Preferences -> Languages & Frameworks -> JavaScript -> Code Quality Tools -> Eslint -> Enable -> Apply -> OK


Xii. Rule table interpretation

{// The environment defines predefined global variables."env"The environment defines predefined global variables. Check out more on the official website"browser": true."node": true."commonjs": true."amd": true."es6": true."mocha": true}, // JavaScript language options"parserOptions": {// ECMAScript version"ecmaVersion": 6,
"sourceType": "module", // Set to"script"(Default) or"module"If your code is an ECMAScript module. // Additional language features you want to use:"ecmaFeatures": {// Allows use in global scopereturnstatements"globalReturn": true,
// impliedStric
"impliedStrict": true, // Enable JSX"jsx": true."modules": true}}, //----- let ESLint support JSX start"plugins": [
"react"]."extends": [
"eslint:recommended"."plugin:react/recommended"], //----- enable ESLint to support JSX end /** *"off"Or 0 - close the rule *"warn"Or 1 - Turn on the rule and use 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) */"rules": {/ / / / / / / / / / / / / / / / / / possible errors / / / / / / / / / / / / / / / / / / / / prohibited assignment operator in a conditional expression"no-cond-assign": 2, // Disable console"no-console": 0, // Disallows constant expressions in conditionsif (false{/ /doSomethingUnfinished();
// } //cuowu
"no-constant-condition"// Disallow control characters in regular expressions: new RegExp("\x1f")
"no-control-regex": 2, // Array and object key-value pairs last comma, never argument: no trailing comma, always argument: mandatory trailing comma, // always-multiline: multi-line mode must have comma, single-line mode cannot have comma"comma-dangle": [1, "never"], // Disable the debugger"no-debugger": 2, // DisablefunctionDuplicate parameter appears in definition"no-dupe-args"// Disallow duplicate keys in object literals"no-dupe-keys": 2, // No duplicatescaseThe label"no-duplicate-case": 2, // Disallow empty statement blocks"no-empty": 2, // Disallow null character sets in regular expressions (/^ ABC []/)"no-empty-character-class": 2, // Disallows reassigning the parameters of the catch clause"no-ex-assign": 2, // Disallow unnecessary Boolean conversions"no-extra-boolean-cast"//(a * b) + c; / / an error"no-extra-parens": 0, // Disallow unnecessary semicolons"no-extra-semi": 2, // Forbid yesfunctionDeclare reassignment"no-func-assign": 2, // Forbid occurrence in nested blocksfunctionOr the var statement"no-inner-declarations"A: [2,"functions"], // disallow invalid regular expression strings in the RegExp constructor"no-invalid-regexp": 2, // Disallow irregular whitespace outside strings and comments"no-irregular-whitespace": 2, // Disable ininNegative left-hand operand occurs in expression"no-negated-in-lhs": 2, // disallow global objects (Math and JSON) as function calls: var Math = Math();"no-obj-calls": 2, // Disallow direct use of object.prototypes built-in attributes"no-prototype-builtins": 0, // Disallows multiple Spaces in regular expression literals"no-regex-spaces": 2, // Disable sparse arrays"no-sparse-arrays": 2, // Disallow confusing multi-line expressions"no-unexpected-multiline": 2, // Disable inreturn, throw,continuebreakStatement followed by unreachable code"no-unreachable": 2, // require isNaN() to check NaN"use-isnan": 2, // Enforce the use of valid JSDoc annotations"valid-jsdoc": 1, // Forces the comparison of typeof expressions with valid strings // typeof foo ==="undefimed"error"valid-typeof": 2, / / / / / / / / / / / / / / / / best practices / / / / / / / / / / / / / / / / / / object definitionsetWhen accessor properties are defined, enforce get"accessor-pairs": 2, // in the callback function of the mandatory array methodreturnstatements"array-callback-return": 0, // Enforce the use of a variable within its defined scope"block-scoped-var": 0, // limit cyclomatic complexity, i.e. similarif elseHow many can I connect in a row"complexity": [2, 9], // requirementsreturnThe statement either always specifies the returned value, or it does not"consistent-return": 0, // Forces all control statements to use the same parenthesis style"curly"A: [2,"all"], // switch statement enforces the default branch, you can also add // no default comment to cancel the warning"default-case": 2, // Enforce the position of. In object.key. Parameter: // property,'. 'The number should be on the same line as the attribute // object,'. 'The number should be on the same line as the object name"dot-location"A: [2,"property"], // Mandatory use. Attribute // parameter: allowKeywords:trueThis parameter can be used only when reserved characters are used as attribute names. Method takes the attribute //falseWhen reserved word is used as the attribute name, only [] can be used to retrieve attribute LLDB [2, {"allowKeywords": false}] // allowPattern: If the attribute name matches the provided regular expression, the value of [] can be used. Otherwise, only [] can be used. Number Value LLDB [2, {"allowPattern": "^[a-z]+(_[a-z]+)+$"}]
"dot-notation": [2, {
"allowKeywords": false}], // use === instead of == allow-null null and undefined=="eqeqeq"A: [2,"allow-null"], / / requirementsforThere is one in the -in loopifstatements"guard-for-in": 2, // Disable alert, confirm and prompt"no-alert": 0, // Disable arguments.caller or arguments.callee"no-caller": 2, // not allowed incaseLexical declarations are used in clauses"no-case-declarations": 2, // Disallows the division operator to appear explicitly at the beginning of a regular expression"no-div-regex": 2, // DisableifIn the statementreturnAfter aelse
"no-else-return": 0, // disable null functions. If a function contains a comment, it will not be considered problematic."no-empty-function": 2, // Disallow the use of empty deconstruction pattern no-empty-pattern"no-empty-pattern": 2, // Disallows null comparisons without the type-checking operator"no-eq-null": 1, // Disableeval(a)"no-eval": 2, // Forbid extension of native types"no-extend-native": 2, // Disallow unnecessary.bind() calls"no-extra-bind": 2, // Disable unnecessary labels"no-extra-label:": 0, // DisablecaseEvery statement"no-fallthrough": 2, // Disallow leading and trailing decimal points in numeric literals"no-floating-decimal": 2, // Do not use short symbols for type conversions (!! fOO)"no-implicit-coercion": 0, // Disallow the use of var and named globallyfunctionThe statement"no-implicit-globals": 1, // Do not use similareval() method"no-implied-eval": 2, // Disallow the this keyword outside of classes and class objects"no-invalid-this": 0, // Disables the __iterator__ attribute"no-iterator": 2, // Disable label statements"no-labels": 2, // disable unnecessary nesting blocks"no-lone-blocks": 2, // Disable occurrences in the loopfunctionDeclarations and expressions"no-loop-func": 1, // Disable magic number (constant for 3.14)"no-magic-numbers": [1, {
"ignore": [0, -1, 1]}], // Do not use multiple Spaces"no-multi-spaces": 2, // Disallow multi-line strings. In JavaScript, you can create multi-line strings using a slash before a new line"no-multi-str": 2, // Disallow assignment to native objects"no-native-reassign": 2, // Disallows the new operator in non-assignment or conditional statements"no-new": 2, // Disallow the new operator on Function objects"no-new-func": 0, // Disallow the new operator for String, Number, and Boolean"no-new-wrappers": 2, // Disables octal literals"no-octal": 2, // Disallow octal escape sequences in strings"no-octal-escape": 2, // Not allowedfunctionThe parameter is reassigned"no-param-reassign": 0, // Disables the __proto__ attribute"no-proto"// Do not use var to declare the same variable more than once"no-redeclare": 2, // disable the specified module loaded by require"no-return-assign": 0, // Disable javascript: URL"no-script-url": 0, // Disables self-assignment"no-self-assign": 2, // Disallow self comparison"no-self-compare": 2, // Disable the comma operator"no-sequences": 2, // Disallows throwing non-exception literals"no-throw-literal": 2, // Disable immutable loop conditions"no-unmodified-loop-condition": 2, // Disallow unused expressions"no-unused-expressions": 0, // Disable unused labels"no-unused-labels": 2, // Disallow unnecessary.call() and.apply()"no-useless-call": 2, // Disallow unnecessary concatenation of string literals or template literals"no-useless-concat": 2, // Disable unnecessary escape characters"no-useless-escape": 0, // Disable the void operator"no-void": 0, // Disallow specific warning terms in comments"no-warning-comments"0, // Disable the with statement"no-with": 2, // Enforce the cardinality argument in parseInt()"radix"// All var declarations are required to appear at the top of their scope"vars-on-top": 0, // IIFE is required to be enclosed in parentheses"wrap-iife"A: [2,"any"], // Require or disallow the "Yoda" condition"yoda"A: [2,"never"], // Requires or disallows the use of strict mode directives"strict": 0, / / / / / / / / / / / / / / / / variable declaration / / / / / / / / / / / / / / / / / / requirement or prohibit the var statement of initialization (initial)"init-declarations": 0, // The argument of the catch clause is not allowed to have the same name as a variable in the outer scope"no-catch-shadow": 0, // Disables variable deletion"no-delete-var": 2, // Labels are not allowed to have the same name as variables"no-label-var": 2, // disable specific global variables"no-restricted-globals": 0, // Disallow var declarations with the same name as variables in the outer scope"no-shadow": 0, // Disallows overwriting restricted identifiers"no-shadow-restricted-names": 2, // Disables undeclared variables unless they are mentioned in the /*global */ comment"no-undef": 2, // disallow initializing variables as undefined"no-undef-init": 2, // Disallow undefined as identifier"no-undefined": 0, // Disallow unused variables"no-unused-vars": [2, {
"vars": "all"."args": "none"}], // It is not allowed to use variables before they are defined"no-use-before-define": 0,

//////////////////////////
// Node.js and CommonJS //
//////////////////////////

// require return statements after callbacks
"callback-return": 0, // require require() in the top-level module scope"global-require"// Error tolerance is required in the callback function"handle-callback-err"A: [2,"^(err|error)$"], // disallow mixing regular var declarations with require calls"no-mixed-requires": 0, // Disallow the new operator when calling require"no-new-require"// Disallow string concatenation of __dirname and __filename"no-path-concat": 0, // disable process.env"no-process-env": 0, // disable process.exit()"no-process-exit": 0, // Disable the synchronization method"no-sync": 0, / / / / / / / / / / / / / / / / style guide / / / / / / / / / / / / / / / / / / will be separated with a space between elements of the specified array (behind), never parameters: [and] before after cannot take space, always parameters: [and] before then must take Spaces"array-bracket-spacing"A: [2,"never"], // Disallow or enforce Spaces in single-line blocks of code (disable)"block-spacing": [1, "never"], // Enforces consistent indentation as the second argument"tab"", will use TAB, //if while functionThe following {must be andifOn the same line, Java style."brace-style"A: [2,"1tbs", {
"allowSingleLine": true}], // Bactrian camel naming format"camelcase": 2, // Controls Spaces before and after commas"comma-spacing": [2, {
"before": false."after": true}], / / or appear at the beginning of comma in the tail of controlling (default end-of-line) / / http://eslint.org/docs/rules/comma-style"comma-style"A: [2,"last"], / /"SwitchCase"(Default: 0) in the mandatory switch statementcaseClause indent level // Whether Spaces are required before [and] when taking object attributes in square brackets. Optional parameters are never, always"computed-property-spacing"A: [2,"never"], // this is the name of the variable that points to this in the callback function."that"Var that = this. That cannot refer to anything else, and this cannot be assigned to anything other than that"consistent-this": [1, "that"], // Enforce namedfunctionexpression"func-names": 0, // Force a newline at the end of the file"eol-last": 2."indent": [2, 4, {
"SwitchCase": 1}], // enforces consistent spacing between keys and values in attributes of object literals"key-spacing": [2, {
"beforeColon": false."afterColon": true}], // enforce a consistent line break style"linebreak-style": [1, "unix"], // Requires empty lines around comments (requires empty lines before block-level comments)"lines-around-comment": [1, {
"beforeBlockComment": true}], // enforce the consistent use of function declarations or function expressions, method definition style, parameter: // declaration: enforce the use of method declarations,function f(){} e.g [2, "declaration"] // expression: how to force method expressions. Var f =function() {} e.g [2, "expression"] // allowArrowFunctions: declaration style allows arrow functions. e.g [2,"declaration", { "allowArrowFunctions": true }]
"func-style": 0, // Enforces a maximum nesting depth of 5 layers for the callback function"max-nested-callbacks": [1, 5], // Disallow the specified identifier"id-blacklist": 0, // Enforces the latest and maximum length of the identifier"id-length": 0, // Requires the identifier to match a specified regular expression"id-match": 0, // Enforces consistent use of double or single quotes in JSX attributes"jsx-quotes": 0, // Force consistent Spaces around keywords (front and back required)"keyword-spacing": 2, // Enforces the maximum line length"max-len": [1, 200], // Enforce the maximum number of lines"max-lines": 0, // MandatoryfunctionThe maximum number of arguments allowed in the definition"max-params": [1, 7], // MandatoryfunctionBlock maximum number of statements allowed"max-statements": [1, 200], // Enforces the maximum number of statements allowed in each line"max-statements-per-line"(requires that the new operator is called with a function of initial letter size, allows the function to be called with an uppercase letter without the new operator.)"new-cap": [2, {
"newIsCap": true."capIsNew": false}], // require parentheses when calling the no-argument constructor"new-parens": 2, // A blank line after the var declaration statement"newline-after-var": 0, // Disable the Array constructor"no-array-constructor": 2, // Disable bitwise operators"no-bitwise": 0, // requestreturnStatement is preceded by an empty line"newline-before-return": 0, // requires a newline character for each call in the method chain"newline-per-chained-call": 1, // Disablecontinuestatements"no-continue": 0, // Disallows inline comments after lines of code"no-inline-comments": 0, // DisableifAppears as the only statement inelseIn the statement"no-lonely-if": 0, // Disallow mixing different operators"no-mixed-operators": 0, // does not allow space and TAB to be indent together"no-mixed-spaces-and-tabs": 2, // Multiple blank lines are not allowed"no-multiple-empty-lines": [2, {
"max": 2}], // Negative expressions are not allowed"no-negated-condition": 0, // Nested ternary expressions are not allowed"no-nested-ternary": 0, // Disallow use of Object constructors"no-new-object"// Disallow the unary operators ++ and --"no-plusplus": 0, // Disables the use of specific syntax"no-restricted-syntax": 0, // DisablefunctionSpaces appear between identifiers and parentheses"no-spaced-func": 2, // Ternary operators are not allowed"no-ternary": 0, // Disable end-of-line whitespace"no-trailing-spaces": 2, // Disallow dangling underscore _bar in identifier"no-underscore-dangle": 0, // Disallows ternary operators when simpler alternative expressions are available"no-unneeded-ternary": 2, // Disallow whitespace before attributes"no-whitespace-before-property": 0, // enforces consistency of newlines within curly braces"object-curly-newline": 0, // Enforces consistent Spaces in curly braces"object-curly-spacing": 0, // Forces the attributes of the object to be placed on different lines"object-property-newline": 0, // Forces variables in a function to be declared either together or separately"one-var": [2, {
"initialized": "never"}], // requires or disallows line breaks around var declarations"one-var-declaration-per-line": 0, // Requires or disallows the use of simplified assignment operators where possible"operator-assignment": 0, // forces operators to use consistent line breaks"operator-linebreak"A: [2,"after", {
"overrides": {
"?": "before".":": "before"}}], // requires or disallows block padding"padded-blocks": 0, // Requires the object literal attribute names to be quoted"quote-props": 0, // Enforces consistent backticks, double quotes, or single quotes"quotes"A: [2,"double"."avoid-escape"], // JSDoc annotations are required"require-jsdoc": 1, // Require or disallow semicolons instead of ASI (which controls semicolons at the end of lines)"semi"A: [2,"always"], // Enforces consistent Spaces before and after semicolons"semi-spacing": 0, // Requires variables in the same declaration block to be sorted in order"sort-vars": 0, // enforces consistent Spaces before blocks"space-before-blocks"A: [2,"always"], // force infunctionUse a consistent space before the open parenthesis of"space-before-function-paren": [0, "always"], // enforces consistent Spaces inside parentheses"space-in-parens"A: [2,"never"], // Requires Spaces around the operator"space-infix-ops": 2, // enforces consistent Spaces around unary operators"space-unary-ops": [2, {
"words": true."nonwords": false}], // force consistent Spaces in comments // or /*"spaced-comment"A: [2,"always", {
"markers": ["global"."globals"."eslint"."eslint-disable"."*package"."!"], // Require or disallow Unicode BOM"unicode-bom": 0, // Requires the regular expression to be enclosed in parentheses"wrap-regex": 0, / / / / / / / / / / / / / / / / ES6. / / / / / / / / / / / / / / / / / / requirement arrow function body using curly braces"arrow-body-style": 2, // Require parentheses for arguments to arrow functions"arrow-parens": 2."arrow-spacing": [2, {
"before": true."after": true}], // force the superclass constructor to be called with super() in the subclass constructor, as the TypeScrip compiler prompts"constructor-super": 0, // Forces a consistent space around the * in generator functions"generator-star-spacing": [2, {
"before": true."after": true}], // disallow modifying class declared variables"no-class-assign": 2, // does not allow arrow functions, where they can be confused by comparisons"no-confusing-arrow": 0, // Disallows modifying variables declared by const"no-const-assign": 2, // Disallow duplicate names in class members"no-dupe-class-members": 2, // Imports of duplicate modules are not allowed"no-duplicate-imports": 0, // disables the Symbol constructor"no-new-symbol": 2, // Allows you to specify imports when modules are loaded"no-restricted-imports": 0, // Disallow this or super in constructors before calling super()"no-this-before-super": 2, // Disallow unnecessary computation of the text of the performance key object"no-useless-computed-key": 0, // required to useletOr const instead of var"no-var": 0, // Requires or disallows the use of shorthand syntax for methods and properties in object literals"object-shorthand": 0, // requires the arrow function as the callback"prefer-arrow-callback": 0, // Requires const variables that are not modified after being declared"prefer-const"0, // Reflect is required where appropriate"prefer-reflect": 0, // Requires the extension operator instead of.apply()"prefer-spread": 0, // Requires template literals instead of string concatenations"prefer-template": 0,
// Suggest using the rest parameters instead of arguments
"prefer-rest-params"Yield is required for generator functions"require-yield": 0,
// enforce spacing between rest and spread operators and their expressions
"rest-spread-spacing": 0, // forces the ordering of imports within the module"sort-imports": 0, // Requires or disallows the use of whitespace around embedded expressions in template strings"template-curly-spacing": 1, // Enforces Spaces around * in yield* expressions"yield-star-spacing": 2}}Copy the code