Hello! I’m working on a personal project and want to include features such as mypy, ruff, and auto runs of tests. As far as testing I’ve seen some cool integrations with GitHub actions. For ruff and mypy I’ve seen it go both ways in a pre-commit hook or in actions. Is there a standard for where ruff or mypy should be used?
Videos
Use How Git hooks made me a better (and more lovable) developer.
I think you can just add some regular expression to detect localMode = true into the sample code at the page.
Yes, you can use a pre-commit hook.
Just drop a shell script named pre-commit (without any extension) inside your ".git/hooks" folder with the logic to check your variable and either:
- change it to
falseand continue with the commit or - print a message telling the user to correct the value manually, and exit with a non-zero code to abort the commit
The hooks folder should contain a few samples, such as "pre-commit.sample", which you might find helpful.
From the documentation:
The
pre-commithook is run first, before you even type in a commit message. It’s used to inspect the snapshot that’s about to be committed, to see if you’ve forgotten something, to make sure tests run, or to examine whatever you need to inspect in the code. Exiting non-zero from this hook aborts the commit, although you can bypass it with git commit --no-verify. You can do things like check for code style (run lint or something equivalent), check for trailing whitespace (the default hook does exactly this), or check for appropriate documentation on new methods.