Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add husky pre-commit git hooks for prettier and codespell #1450

Merged

Conversation

rhyskoedijk
Copy link
Contributor

Adds pre-commit git hooks (via husky) to run prettier and codespell. This removes the need for contributors to manually run npm run format and codespell prior to commit, it now just happens automatically and will reject the commit if either commands fail.

pretty-quick is used to run prettier on the changed staged files only rather than all files, which keeps the command time to less than a second.

Example of a commit containing formatting and spelling errors:

rhys@dev-vm:~/development/dependabot-azure-devops$ git commit
🔍  Finding changed files since git revision b100a25.
🎯  Found 2 changed files.
✍️  Fixing up extension/tasks/dependabotV2/utils/dependabot-cli/DependabotCli.ts.
✅  Everything is awesome!
./extension/tasks/dependabotV2/utils/dependabot-cli/DependabotCli.ts:121: missspelling ==> misspelling
husky - pre-commit script failed (code 65)
rhys@dev-vm:~/development/dependabot-azure-devops$ 

The formatting is automatically updated, but commit is rejected due to typo.

Additionally, running npm install from the root directory will also trigger npm install in the /extension folder too.

@rhyskoedijk rhyskoedijk marked this pull request as ready for review November 9, 2024 12:43
@mburumaxwell
Copy link
Contributor

I'm not a big fan of pre-commit hooks, but they can save lives.

@mburumaxwell mburumaxwell merged commit 670973e into tinglesoftware:main Nov 18, 2024
1 check passed
@rhyskoedijk rhyskoedijk deleted the feature/husky-git-hooks branch November 18, 2024 09:40
@rhyskoedijk
Copy link
Contributor Author

@mburumaxwell, if you'd like, I can disable the husky init script from the npm prepare event so that it's disabled by default; contributors that want it can just initialise it themselves.

@mburumaxwell
Copy link
Contributor

Sounds ideal

@rhyskoedijk
Copy link
Contributor Author

Git hooks will be disabled by default after #1472

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants