Open skairunner opened 1 month ago
Hi! Would you be able to do this using the args
key in your .pre-commit-config.yaml
file? E.g. something like
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.7
hooks:
- id: ruff
name: Run ruff
args: ["--range=1:2-3:4"]
Unfortunately not -- that would hardcode all pre-commits to use that specific range. I was thinking that it would be ideal if ruff could somehow receive the line numbers edited in the git commit and pass those along to ruff formatter, per-file. So it would basically only format the lines that were touched by the commit rather than all files touched.
But I don't know if that's supported within the pre-commit framework.
Ahh I see, thanks for explaining
Yeah, this requires pre-commit support and possibly support for passing multiple ranges https://github.com/astral-sh/ruff/issues/12800
Ruff introduced a new parameter
--range
that allows the formatter to only check the specified range. This would be useful to allow migrating from black to ruff formatting without causing whole-file diffs whenever a file is touched for the first time.Quote from docs:
Is there a way to have range support within the pre-commit framework?