reactpy
reactpy copied to clipboard
Added pre-commit hook
Issues
Resolve #925
Summary
Added back Pre-Commit Hook
Checklist
- [ ] Tests have been included for all bug fixes or added functionality.
- [ ] The
changelog.rsthas been updated with any significant changes.
A couple areas for improvement:
- It might make sense to have
hatchactually run pre-commit rather than the other way around. Dong it this way, where pre-commit tellshatchto execute the set of linting tools might introduce a fair bit of latency to the typicalgit commitworkflow that could be avoided. I could be wrong about that though. - We'd also like to run the steps that are presently in
lint-jswith pre-commit as well. - We want pre-commit to fix what it can. Presently that involves passing a
--fixflag tohatch run lint-*
@rmorshea Opinion on respective point
- If pre-commit is running hatch command then it will be automated process whenever someone commits . Latency will be negligible I guess.
- Sure we can add lint-js
- We can add --fix as well
Planning to execute pre-commit in following order
- Fix Python lint.
- Check Python Lint
- Fix JS lint.
- Check JS lint. Let me know your thoughts on this.
We should make it so you don't have to run "fix" and then "check". The "fix" command should return a non-zero exit code if it needs to make corrections. For example, Ruff has a flag for this (--exit-non-zero-on-fix). I believe black does this by default. Not entirely sure if the JS tools are like Ruff (need a flag) or Black (non-zero on fix by default).
@rmorshea Actually I tried using --exit-non-zero-on-fix even without using it pre-commit will fail even if code has been auto formatted by --fix.
repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: 'v0.0.272'
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
pre-commit will keep failing unless 4 of the steps completed successfully. What's your suggestion should we make pre-commit like above example (without hatch) or use hatch?
I'll take a closer look at this shortly.
I think we can proceed using hatch run lint-<lang> --fix. Can you add pre-commit as a dependency in the root pyproject.toml file?
@rmorshea We still need to enable precommit on the repo