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} } 3. Install Eslint, Prettier Eslint plugin 4. If not, check if the packages required by Prettier ESlint are installed 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:
|
<<: Implement group by based on MySQL to get the latest data of each group
>>: How to install Nginx in Docker
Problem Description MySQL is started successfully...
Find the problem I wrote a simple demo before, bu...
transform and translate Transform refers to trans...
Common properties of tables The basic attributes ...
During development, a good user interface will al...
Table of contents Install Software Management Ano...
Table of contents 1. Monitoring port Relationship...
Preface This article mainly introduces the releva...
Table of contents 1. Number in JavaScript 2. Math...
Windows installation mysql-5.7.17-winx64.zip meth...
1: Install SVN yum install -y subversion 2. Creat...
Problem Description 1. Database of the collection...
Preface JSON is a lightweight data exchange forma...
Database MySQL version 8.0.18 Download a DBeaver....
The examples in this article are all written in s...