Detailed explanation of using Baidu style in eslint in React project

Detailed explanation of using Baidu style in eslint in React project

1. Install Baidu Eslint Rule plugin

npm i -D eslint @babel/eslint-parser @babel/eslint-plugin @ecomfe/eslint-config

// react project npm i -D eslint-plugin-react eslint-plugin-react-hooks
 
// If you need to support typescript, then npm i -D @typescript-eslint/parser @typescript-eslint/eslint-plugin

2. Configure the .eslintrc file

{
    "parser": "@typescript-eslint/parser", // typescript parser "extends": [
        "@ecomfe/eslint-config", // Inherit the factory EE-eslint rule configuration "@ecomfe/eslint-config/react"
    ],
    "plugins": [
        "@typescript-eslint", // Add some typescript syntax checks "react", // react syntax check "react-hooks" // hooks syntax check],
    "rules": {
        "indent": [
            "error",
            4,
            {
                "SwitchCase": 1
            }
        ], // Force 4-grid style "no-unused-vars": "off", // Turn off eslint no-unused-vars default configuration "@typescript-eslint/no-unused-vars": [
            "warn",
            {
                "vars": "all",
                "args": "after-used",
                "ignoreRestSiblings": false
            }
        ], // Use @typescript-eslint/no-unused-vars configuration "import/no-unresolved": "off",
        "react/jsx-uses-react": 2, // Shield "React" is defined but never used error "import/order": "off", // No need to import order verification "comma-dangle": [
            "off"
        ], // Do not allow extra commas at the end "@typescript-eslint/consistent-type-definitions": [
            "off"
        ], // turn off first "react-hooks/rules-of-hooks": "error", // check Hook rules "react-hooks/exhaustive-deps": "warn", // check effect dependencies "max-params": [
            "warn",
            8
        ], // The method has a maximum of 8 parameters "no-use-before-define": "off",
        "@typescript-eslint/no-use-before-define": [
            "error",
            {
                "functions": false,
                "variables": false
            }
        ], // NOTE: Methods and variables can be defined after use! In order to solve the problem of circular dependencies that often appear in hooks, but be aware of the danger "react/jsx-no-bind": [
            "warn",
            {
                "allowArrowFunctions": true // Temporarily allow arrow functions to improve code readability}
        ],
        "max-nested-callbacks": [
            "warn",
            4
        ], // Maximum loop depth is 4, warning if more than 4 depths are given "react/require-default-props": "off", // Component's non-required properties are not required to have default values ​​"react/no-find-dom-node": "off", // Temporarily allow the use of react-dom's findDOMNode method "@babel/object-curly-spacing": "off",
        "object-curly-spacing": [
            "off",
            "always",
            {
                "arraysInObjects": false
            }
        ], // Whether to add spaces in object brackets "brace-style": [
            "off",
            "1tbs"
        ],
        "react/no-string-refs": "warn", // string type refs report warn
        "no-unreachable-loop": "off",
        "eol-last": ["error", "always"] // An extra blank line is required at the end of the file}
} 

insert image description here

3. Install Eslint, Prettier Eslint plugin

insert image description here
insert image description here

4. If not, check if the packages required by Prettier ESlint are installed

insert image description here

This is the end of this article about using Baidu style eslint in React projects. For more relevant content about using eslint in React projects, please search previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Using Eslint code checking tools and common problems in React projects
  • Detailed explanation of create-react-app custom eslint configuration
  • Detailed explanation of the essential eslint configuration for React development

<<:  Implement group by based on MySQL to get the latest data of each group

>>:  How to install Nginx in Docker

Recommend

Introduction to container data volumes in Docker

Table of contents Docker container data volume Us...

In-depth understanding of Vue's plug-in mechanism and installation details

Preface: When we use Vue, we often use and write ...

Search optimization knowledge to pay attention to in web design

1. Link layout of the new site homepage 1. The loc...

Vue implements tree table through element tree control

Table of contents Implementation effect diagram I...

Docker enables seamless calling of shell commands between container and host

As shown below: nsenter -t 1 -m -u -n -i sh -c &q...

Detailed explanation of nmcli usage in CentOS8

Common nmcli commands based on RHEL8/CentOS8 # Vi...

A brief analysis of the basic implementation of Vue detection data changes

Table of contents 1. Object change detection 2. Q...

Vue3 compilation process-source code analysis

Preface: Vue3 has been released for a long time. ...

The difference between distinct and group by in MySQL

Simply put, distinct is used to remove duplicates...

Detailed Example of JavaScript Array Methods

Table of contents Introduction Creating an Array ...

CentOS6.8 uses cmake to install MySQL5.7.18

Referring to the online information, I used cmake...

Complete Tutorial on Deploying Java Web Project on Linux Server

Most of this article refers to other tutorials on...