This release includes the Beta version of the Ruff formatter — an extremely fast, Black-compatible Python formatter.
Try it today with ruff format.
Changes
Preview features
[pylint] Implement non-...
Question: Black has Darker for formatting just the code in a diff. Does Ruff have something similar? I want to start using it in my CI pipelines, but I don’t too much noise when changing just a small part of a large module.
Genuine question, do you have a reason for not just formatting the entire codebase in a single commit and adding that commit to the a .git-blame-ignore-revs file for maintaining a still useful ability to blame through your history?
Anyone in a decent size company that wants to start improving their code formatting without going through the steps to get permission to change “everyone else’s code”.
Similarly, it bothers me that Black doesn’t support range formatting (Darker is an independent project). They’ve basically told everyone to format the whole file or leave.
As many people are working on the same codebase simultaneously, reformatting the whole thing will create many conflicts
There are still some places where Black’s formatting in undesired (especially in DS/ML code where you may find data structures formatted as a matrix) and we’d want to exclude those either via configuration, or with the # fmt: off/on comment directives, but I’ll only see those when I review them in a PR. If I reformat the entire project in one commit it will be harder to spot.
As Black is evolving so may the formatting, or maybe we’ll change some default configuration in the future (like string normalization) and then I’d have to reformat the whole thing again.
Works, yes. But I’m talking about formatting that just looks wrong with black. Try format something like a long enough numpy matrix, pandas dataframe, or just a list of lists, and you’ll see how black just makes things unreadable.
Question: Black has Darker for formatting just the code in a diff. Does Ruff have something similar? I want to start using it in my CI pipelines, but I don’t too much noise when changing just a small part of a large module.
I asked a similar question on Twitter. Check their GitHub, they’re developing “range formatting”, maybe they are also doing the diff thing
Genuine question, do you have a reason for not just formatting the entire codebase in a single commit and adding that commit to the a .git-blame-ignore-revs file for maintaining a still useful ability to blame through your history?
Anyone in a decent size company that wants to start improving their code formatting without going through the steps to get permission to change “everyone else’s code”.
Similarly, it bothers me that Black doesn’t support range formatting (Darker is an independent project). They’ve basically told everyone to format the whole file or leave.
Which is totally understandable, if you know how Black works. The Darker authors themselves cite “good reasons” why black doesn’t in their README.
There are several reasons:
# fmt: off/on
comment directives, but I’ll only see those when I review them in a PR. If I reformat the entire project in one commit it will be harder to spot.Surely, no one would do a change like adding
black
to an existing project without checking that everything still works afterwards?Works, yes. But I’m talking about formatting that just looks wrong with black. Try format something like a long enough numpy matrix, pandas dataframe, or just a list of lists, and you’ll see how black just makes things unreadable.