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
Table of contents Docker container data volume Us...
Preface: When we use Vue, we often use and write ...
1. Link layout of the new site homepage 1. The loc...
Table of contents Implementation effect diagram I...
Table of contents 1. Current limiting algorithm 2...
As shown below: nsenter -t 1 -m -u -n -i sh -c &q...
This article records the installation and configu...
Common nmcli commands based on RHEL8/CentOS8 # Vi...
Table of contents 1. Object change detection 2. Q...
Preface: Vue3 has been released for a long time. ...
Simply put, distinct is used to remove duplicates...
Regarding uninstalling the previously installed v...
Table of contents Introduction Creating an Array ...
Referring to the online information, I used cmake...
Most of this article refers to other tutorials on...