-
Notifications
You must be signed in to change notification settings - Fork 23
[onhold] chore: setup frontend pre commit hook #1161
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
base: main
Are you sure you want to change the base?
Conversation
f125f69
to
5b2f883
Compare
Makefile
Outdated
git config --unset-all core.hooksPath | ||
uv run pre-commit install | ||
pushd lumigator/frontend && npm run prepare && popd |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when running npm install
it will now run the prepare
script in
lumigator/lumigator/frontend/package.json
Line 18 in 2574e89
"prepare": "cd ../../ && husky install lumigator/frontend/.husky" |
husky sets the core.hooksPath
to frontend/.husky
during its installation which breaks whatever checks uv pre-commit
does when running make local-up
(core.hooksPath
defines the folder/path where github looks at to see where the hooks are defined)
I was getting this error when running make local-up
uv run pre-commit install
[ERROR] Cowardly refusing to install hooks with core.hooksPath set.
hint: git config --unset-all core.hooksPath
make: *** [local-up] Error 1
so this is a workaround to unset core.hooksPath
before running uv run pre-commit install
to make things work then run the npm prepare script to install husky (which sets git config core.hooksPath
to frontend/.husky
) and make the frontend pre-commit hook work alongside the backend one, where we run the uv run pre-commit run
from frontend/.husky/pre-commit
(so technically I think we can even get rid of running uv run pre-commit install
in the make file since its already part of the pre-commit hook in .husky
)
This feels hacky, but I'm not sure if there's a better way to do it. cc @macaab26, essentially all the frontend needs to do is run npx lint-staged
from the frontend folder, so to avoid all this setting/unsetting hooksPath
stuff, we could technically get rid of husky and rely on the normal .git/hooks/pre-commit
however this file is automatically generated/overwritten by ruff so that wouldn't work either, perhaps we could create a custom pre-commit hook file and manually append to the generated pre-commit hooks or something along these lines which would also kinda hacky 🤷, or we could just rely on husky to run both backend & frontend linting which is what it currently does
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed uv run pre-commit install
in 4ce0d50 now that .husky/pre-commit
is responsible for running linting for both backend and frontend where it would run uv run pre-commit run
and npx lint-staged
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
What's changing
Closes #951
Setup pre-commit hooks for linting & formatting changed frontend files before creating a commit using husky & lint-staged
How to test it
Steps to test the changes:
npm install
from the frontend directory to install the new dependencies (lint-staged & husky)make local-up
git commit -am "test commit"
I already...
/docs
)