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

Solution to MySQL startup successfully but not listening to the port

Problem Description MySQL is started successfully...

Solution to the img tag problem below IE10

Find the problem I wrote a simple demo before, bu...

Table shows the border code you want to display

Common properties of tables The basic attributes ...

CSS animation property usage and example code (transition/transform/animation)

During development, a good user interface will al...

Implementation steps for installing FTP server in Ubuntu 14.04

Table of contents Install Software Management Ano...

About Zabbix custom monitoring items and triggers

Table of contents 1. Monitoring port Relationship...

Example of how to quickly delete a 2T table in mysql in Innodb

Preface This article mainly introduces the releva...

Introduction to JavaScript Number and Math Objects

Table of contents 1. Number in JavaScript 2. Math...

MySQL 5.7.17 winx64 installation and configuration method graphic tutorial

Windows installation mysql-5.7.17-winx64.zip meth...

How to build svn server in linux

1: Install SVN yum install -y subversion 2. Creat...

How to solve the mysql error 1033 Incorrect information in file: 'xxx.frm'

Problem Description 1. Database of the collection...

Instructions for using JSON operation functions in Mysql5.7

Preface JSON is a lightweight data exchange forma...

Sample code for implementing horizontal infinite scrolling with pure CSS3

The examples in this article are all written in s...