I have been troubled by how to standardize everyone’s code submission in the company before, and there has been no good method. It all depends on supervision and self-consciousness. Today, WHEN I see his method in the new company, I think it is very good. I have to say, finding wheels is a real no-brainer. Here is a summary of the detailed steps
1. Take a look at the Husky plugin
Husky add Git hooks to your project. With this plug-in, you can execute the necessary scripts or commands at various stages of git operation, first by installing -d and then by configuring them in package.json
"husky": {
"hooks": {
"pre-commit": "lint-staged".// Execute lint-staged commands before COMMIT
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS" // Verify that the remarks added during the commit comply with the rules}},Copy the code
This is where the two hooks that I mentioned earlier need to be standardized are configured
2. Next, take a look at Lint-staged plug-ins
NPM Run Lint is known to format the entire project slowly, whereas lint-formatted files in Git staging can still be formatted into submitted code (package.json)
"lint-staged": {
"*.{js,vue}": "eslint --fix --quiet".// Perform ESLint formatting for js and VUE files in the staging area
"*.{less,vue}": "stylelint --fix --allow-empty-input" // Performs stylelint formatting for less and Vue
},
Copy the code
So far there has been a specification for committed code, but the specification is the same as the specification for commit information
Commitlint standardizes the management of commit information
The Commitlint plugin can write a.commitlintrc.js file in a project to specify rules. The configuration is left to the commitlintrc.js file, which is not detailed here