Adds pre-commit hook that runs automated tests & fixes lint errors #6558
+70
−0
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.
What?
After an npm command, configures git to run hooks in .githooks. Adds pre-commit hook that runs automated tests.
Fixes lint errors from several PRs
Why?
There is no native way to include Git hooks in the checked-in code.
All solutions require either running a command or installing a 3rd party package.
As Hubs developers will almost always run
npm installafter cloning the repo, this approach requires no change in development steps.npm run testwas not run before the commits that introduced lint errors, and there was no Git pre-commit hook.How to test
npm cito activate the new hookgit addgit commit— observe that tests are run, an error message is displayed, and the commit does not completegit addgit commit— observe that tests are run and the commit does completeDocumentation of functionality
No changes to docs, this just pushes validation to the left
Limitations
Note that developers can always prevent a hook from running by adding the flag
-n, so git hooks just support fail-fast.Enforcement has to occur in CI.
The pre-commit script also checks two things that are not currently enforced by anything:
Current code follows these rules, and they appeared good checks to add.
They could be removed if/when they get in the way.
Alternatives considered
Husky is an extra dependency and doesn't appear to allow any additional functionality of use.
Open questions
Should Husky be removed by this PR?
The tests take a noticeable amount of time to run, which can be annoying when updating a commit.
Should we move this to the pre-push hook, which is run less often?