Prettier (Git commits automatic formatting)
Yarn add –dev –exact prettier
Then let’s create a new configuration file from the command line
echo {}> .prettierrc.json
Default configuration, so the inside of the empty line, the subsequent want to add a separate configuration can be added
For files that do not need formatting, we create a new one
. Prettierignore Configuration file used to solve the problem
Configuring Automatic Formatting
Husky is recommended on the website, so let’s install it by command first
npx mrm@2 lint-staged
After installation, let’s take a look at package.json
Here according to my configuration is good, the left is the file type to be formatted, the right is the formatting script command, you can run the command verification
You can modify any code and commit it with Git to see if it is automatically formatted
Use with ESLint
In order for it to work properly, we need to do some configuration. I use the react-create-app to create the project, so there is no need to install the built-in ESLint. If it is not in the project, you need to install it yourself
Yarn add ESlint-config-prettier now install the dependency yarn add esLint-config-prettier package
Where prettier’s rule replaces part of ESLint’s rule for prettier