TOOLS: Add pre-commit hooks #2326
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Note: This is an experimental PR. I'm not sure if we really need this one.
Ideally, when a contributor creates a PR, they should run all these steps:
npm run format: Reformat code.npm run lint: Run ESLint to catch potential mistakes.npm run test: Run all test suites.npm run doc: Generate docs.However, many contributors do not do them. Some don't know that they should do that. Some (including me) are lazy and just let the CI system catch the problems. Recently, a contributor asked us if
npm run docis in our workflow, and the answer is no. Setting pre-commit hooks may be useful, and it is also common practice in many projects, so I decide to test it.Currently, the process of creating a PR is fairly "free-style". The contributor can ignore all those npm steps while drafting the PR. They only need to deal with them right before we review the PR. I think this is good; it's annoying to be forced to run many commands every commit, especially in the early stage of the PR. Therefore, in this PR, I only run prettier and
npm run docwhen necessary and only with staged files.Note that even after running
npm run doc, the contributor still has to manually stage some files (e.g.,src/Documentation/pages.ts, md and images files insrc/Documentation/). We can automatically stage them, but it may be annoying for the contributor if there are some files that they specifically don't want to commit (e.g., incomplete md files).@d0sboots What do you think about this idea?