tinglesoftware / dependabot-azure-devops

Tools for updating dependencies in Azure DevOps repositories using https://dependabot.com
MIT License
201 stars 66 forks source link

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

Closed rhyskoedijk closed 4 days ago

rhyskoedijk commented 1 week ago

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.

mburumaxwell commented 4 days ago

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

rhyskoedijk commented 4 days ago

@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 commented 4 days ago

Sounds ideal

rhyskoedijk commented 3 days ago

Git hooks will be disabled by default after https://github.com/tinglesoftware/dependabot-azure-devops/pull/1472