Replies: 3 comments
-
You could change the line length in the Ruff configuration and use your editor to only format the modified ranges. The CLI currently doesn't support formatting modified lines only (Ruff has no git integration). You'd have to build your own script that feeds the modified ranges from git (or whatever version control system you use) to
I don't think I can answer this for you. There are too many organisational factors that influence this decision. But it's probably what I would be doing. Accept the one time churn. You can mitigate it by adding the commit to |
Beta Was this translation helpful? Give feedback.
This comment was marked as spam.
This comment was marked as spam.
-
|
if the goal is "reformat only the lines I actually touched", pipx install '''darker[ruff]'''
darker --formatter ruff --revision main src/set the new the failure mode to watch is config-vs-rule: ruff has to be configured with the new line length (otherwise it has nothing different to reformat to), but you don'''t want CI to fail on legacy long lines. so during the migration window: [tool.ruff]
line-length = 88
[tool.ruff.lint]
# don'''t flag legacy long lines while we'''re migrating
ignore = ["E501"]drop the ignore once the codebase has caught up. ruff'''s formatter alone (without darker) doesn'''t look at E501 — it just reflows what it'''s given — so you can keep the formatter strict ( if you don'''t want a third-party tool, the bare-metal git-diff version: git diff --name-only --diff-filter=AM main -- '''*.py''' | xargs -r ruff format --line-length 88run it as a pre-commit hook on the touched files only. same idea, no darker, but it formats the whole changed file (not just the changed lines) — which is fine in practice because the only files that get reformatted are the ones you'''re editing anyway. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
In a few of our repos the line length is set at 110. However, I am thinking of reducing it so that diffs are easier to read on smaller screens. I'd rather not do this for every file all at once, and even for a whole file at once. Ideally when I make a functional change to a block of code I would reformat it to be the new line length. But ruff will format lines back to 110 if possible, which is not wanted.
Is there an easy way to do what I'm looking for with ruff? Or is this something that I should do all at once?
Beta Was this translation helpful? Give feedback.
All reactions