git-hooks.nix
git-hooks.nix copied to clipboard
typos: allow configPath to be of type string or path + take excludes from `.typos.toml` into account when `pre-commit run typos --all-files` runs
Unfortunately, the typos story still isn't solved properly at this point. My concerns decsribed here still exist.
The Problem
Hint: The problem is also shortly discussed in the commit messages.
Yes, using pass_filenames = false should only be done if no other variant is possible (pass_filenames = true is fine). My first "fix" merged a few months ago was wrong. And a commit hook should only run on changed files, I agree.
But, people also use pre-commit run --all-files to run all checks on the whole repo. Some people don't even use Git commit hooks at all and just use pre-commit to run all style checks at once. And that's a perfeclty valid usecase.
The problem is that if you run $ pre-commit run typos --all-files, typos behave differently compared to $ typos ..
The Fix
I modified typos.configPath in a way to be either of type string or path. The change is additive and not breaking.
To use the new option, you have to do something like this:
settings = {
typos = {
# configuration = "" # POSSIBLE
# configPath = ".typos.toml"; # OLD
configPath = .typos.toml; # NEW, RECOMMENDED
};
};
You can verify that my solution works by checking the typos invocation:
$ strace -s 64 -Tfe trace=execve pre-commit run --all-files typos
Unintended files are not longer passed to typos. 🎉
Ping @totoroot @domenkozar