Detailed explanation of create-react-app configuration eslint steps
This time I will bring you a detailed explanation of the steps for configuring eslint in create-react-app. What are the precautions for configuring eslint in create-react-app? The following is a practical case, let's take a look.
Use eslint and editorconfig to standardize code
Why use these:
-
Code specifications are conducive to team collaboration
Purely manual specifications are time-consuming and labor-intensive and cannot guarantee accuracy
Can cooperate with the editor to automatically remind errors and improve development efficiency
eslint
As the ECMAScript version is constantly updated, the Js lint tool has rich plug-ins and can apply specifications. The rules are very rich and can meet the needs of most teams.
eslint cooperates with git
In order to control everyone's specifications to the greatest extent, we can use git hook to call eslint for code specification verification when git commits the code. Canonical code cannot be submitted to the warehouse.
editorconfig
Different editors will have certain differences in the format of text. If some standards are not unified, you may update others every time you cooperate with others. There will be a lot of errors in the code - webstorm automatically supports the editorconfig configuration file.
First installeslintnpm i eslint
Because create-react-app is already installed by default
"babel-eslint": "7.2.3", "eslint": "4.10.0", "eslint-config-react-app": "^2.1.0", "eslint-loader": "1.9.0", "eslint-plugin-flowtype": "2.39.1", "eslint-plugin-import": "2.8.0", "eslint-plugin-jsx-a11y": "5.1.1", "eslint-plugin-react": "7.4.0",
For the custom configuration we want, we install it as follows
npm i babel-eslint \ \ eslint-config-airbnb eslint-config-standard \ \ eslint-loader \ \ eslint-plugin-import \ \ eslint-plugin-jsx-a11y \ \ eslint-plugin-node \ \ eslint-plugin-promise \ \ eslint-plugin-react \ \ eslint-plugin-standard -D
We create a new .eslintrc file in the root directory to make a standard specification for the entire project
{ "extends": "standard" }
The main project is the front-end project, so we create a new .eslintrc file in the front-end folder, go here Standardize client code. Client code uses jsx. Many rules are different from nodejs. Here, more strict specifications are used to require client code.
The value corresponding to the configured value: 0: off 1: warning 2: error
{ "parser": "babel-eslint", "env": { "browser": true, "es6": true, "node": true }, "parserOptions": { "ecmaVersion": 6, "sourceType": "module" }, "extends": "airbnb", "rules": { "semi": [0], "react/jsx-filename-extension": [0], "jsx-a11y/anchor-is-valid": [0] } }
Use babel-eslint to parse the code. The definition environment is browser and es6, which will contain public variables. Webpack therefore needs some environment variables of node, parserOptions to define the version, and jsmodule mode method writing.
Because you need to check the code before each compilation, you also need to configure webpack, which is the default of create-react-app
{ test: /\.(js|jsx|mjs)$/, enforce: 'pre', use: [ { options: { formatter: eslintFormatter, eslintPath: require.resolve('eslint'), }, loader: require.resolve('eslint-loader'), }, ], include: paths.appSrc, },
We hope to block the node_modules folder The code
exclude:[path.resolve(__dirname, '../node_modules')]
Create a new file .editorconfig in the project root directory. Webstom has the configuration by default
root = true Project root directory
-
[*] This rule applies to all files
charset = utf-8 encoding mode
indent_style = space uses tab style Tab characters and space
indent_size = 2
- ##end_of_line = lf line ending method
- insert_final_newline = true Automatically save the last line at the end of the line as a blank line
- trim_trailing_whitespace = true Automatically remove the spaces after the end of a line
// eslint-disable-line
/* eslint-disable */ at the end of the file
/ * eslint-enable */
npm i husky -D
"lint": "eslint --ext .js --ext .jsx src/", "precommit": "npm run lint"
How to use the entry component
How to use the Installation plug-in in actual projects
The above is the detailed content of Detailed explanation of create-react-app configuration eslint steps. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Understanding Linux Bashrc: Function, Configuration and Usage In Linux systems, Bashrc (BourneAgainShellruncommands) is a very important configuration file, which contains various commands and settings that are automatically run when the system starts. The Bashrc file is usually located in the user's home directory and is a hidden file. Its function is to customize the Bashshell environment for the user. 1. Bashrc function setting environment

Title: How to configure and install FTPS in Linux system, specific code examples are required. In Linux system, FTPS is a secure file transfer protocol. Compared with FTP, FTPS encrypts the transmitted data through TLS/SSL protocol, which improves Security of data transmission. In this article, we will introduce how to configure and install FTPS in a Linux system and provide specific code examples. Step 1: Install vsftpd Open the terminal and enter the following command to install vsftpd: sudo

PHP, Vue and React: How to choose the most suitable front-end framework? With the continuous development of Internet technology, front-end frameworks play a vital role in Web development. PHP, Vue and React are three representative front-end frameworks, each with its own unique characteristics and advantages. When choosing which front-end framework to use, developers need to make an informed decision based on project needs, team skills, and personal preferences. This article will compare the characteristics and uses of the three front-end frameworks PHP, Vue and React.

Integration of Java framework and React framework: Steps: Set up the back-end Java framework. Create project structure. Configure build tools. Create React applications. Write REST API endpoints. Configure the communication mechanism. Practical case (SpringBoot+React): Java code: Define RESTfulAPI controller. React code: Get and display the data returned by the API.

Vue.js is suitable for small and medium-sized projects and fast iterations, while React is suitable for large and complex applications. 1) Vue.js is easy to use and is suitable for situations where the team is insufficient or the project scale is small. 2) React has a richer ecosystem and is suitable for projects with high performance and complex functional needs.

Title: Computer configuration recommendations for building a high-performance Python programming workstation. With the widespread application of the Python language in data analysis, artificial intelligence and other fields, more and more developers and researchers have an increasing demand for building high-performance Python programming workstations. When choosing a computer configuration, in addition to performance considerations, it should also be optimized according to the characteristics of Python programming to improve programming efficiency and running speed. This article will introduce how to build a high-performance Python programming workstation and provide specific

React combines JSX and HTML to improve user experience. 1) JSX embeds HTML to make development more intuitive. 2) The virtual DOM mechanism optimizes performance and reduces DOM operations. 3) Component-based management UI to improve maintainability. 4) State management and event processing enhance interactivity.

Common problems and solutions for Laravel environment configuration file .env When using the Laravel framework to develop projects, the environment configuration file .env is very important. It contains key configuration information of the project, such as database connection information, application keys, etc. However, sometimes there are some common problems when configuring the .env file. This article will introduce these problems and provide solutions, and attach specific code examples for reference. Problem 1: Unable to read the .env file when we have configured the .env file
