preface

As the saying goes, without rules, no fangyuan can be achieved. Good code specification is important both for individuals and teams. In order to provide code quality and uniform code specification, I chose ESLint and Prettier to use, and used Husky and Lint-stage to pre-check the code in the online repository for final submission to Git.

Eslint is different from prettier

ESLint primarily addresses code quality issues, and code quality problems can mean potentially buggy programs. Such as:

  • Code Quality Rules
    • no-unused-vars
    • no-extra-bind
    • no-implicit-globals
    • prefer-promise-reject-errors
    • .

Prettier’s main problem is code style, a problem that is, at best, unappealing. Such as:

  • Code-formatting rules
    • max-len
    • no-mixed-spaces-and-tabs
    • keyword-spacing
    • comma-style
    • .

Eslint and Prettier configurations conflict

Eslint and Prettier don’t go into details here, there are plenty of details in the community. Here’s the main caveat for pairing EsLint with Prettier. Because ESLint also checks code style during code inspections, if Prettier’s configuration conflicts with ESLint’s rules, an infinite loop can occur. Solutions are as follows:

npm install eslint-plugin-prettier eslint-config-prettier -D
Copy the code

Then configure the.eslintrc.json file:

"extends": ["plugin:prettier/recommended"]
Copy the code

Can. See here for details

husky

Husky is a tool that adds hooks to Git clients. You can customize some operations before you execute git. For example, the pre-commit hook will trigger git commit. You can implement some operations in pre-commit, such as lint checking, unit testing, code beautification, etc.

portal

lint-stage

Lint-stage A tool that simply filters out Git code staging files (files added by Git); This is useful because if we do a review of the entire project code, it can take a long time, and if we do an older project, we have to do a code specification review of the previous code and modify it, which can be troublesome, and can lead to major changes in the project. So this Lint-staged project is a great tool for team projects and open source projects, which act as a specification and discipline for the code that individuals must commit.

portal

Finally send to wangUI warehouse address