Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: black compatibility mode #13697

Closed
cramertj opened this issue Oct 9, 2024 · 2 comments
Closed

Feature request: black compatibility mode #13697

cramertj opened this issue Oct 9, 2024 · 2 comments
Labels
formatter Related to the formatter question Asking for support or clarification

Comments

@cramertj
Copy link

cramertj commented Oct 9, 2024

Ruff's website says:

The formatter is designed to be a drop-in replacement for Black.

Specifically, the formatter is intended to emit near-identical output when run over Black-formatted code.

However, there is an extensive list of differences between the output of the two formatters. On my project, I was not able to configure ruff and black in such a way that the two would result in the same output, or even allow the output of the other to go unchanged. The diffs I saw can be seen here.

If black-compatibility or gradual migration from black is a goal, it would be very helpful to offer a mode which allows the output of black to go unchanged. Without this, transitioning between the two formatters requires synchronized changes to both the formatter and the code being formatted.

I understand this may be a non-goal, but I figured it was worth raising here since the website explicitly lists Black compatibility as a goal/feature.

@zanieb
Copy link
Member

zanieb commented Oct 10, 2024

Is the right side of the diff there Ruff's output? If so, I think most of those are pretty clear improvements to the format. I understand it's tough to use both formatters at once though.

We are targeting Black compatibility, but it's very hard to reach 100% compatibility due to architectural differences. During the initial implementation, we spent time trying to close the gap from 99% -> 100% (e.g., #6343). I'm not sure how feasible it is to get closer. In the long term, we will probably diverge further from Black as we want to improve the produced format. Unfortunately, it's very hard to maintain multiple "modes" of the formatter, which is part of why we support a limited number of settings. I think this is a significant burden to a compatible mode as well.

cc @MichaReiser

@zanieb zanieb added the formatter Related to the formatter label Oct 10, 2024
@MichaReiser MichaReiser added the question Asking for support or clarification label Oct 10, 2024
@MichaReiser
Copy link
Member

We have goal to match Black closely so that migrating from black to ruff results in none or only very few code changes.

Achieving 100% compatibility is a non goal. It would require us to re-implement bugs in black or make our formatting worse just for compatibility.

transitioning between the two formatters requires synchronized changes to both the formatter and the code being formatted.

I recommend you against switching between formatters and instead advise you to commit to one (Black or Ruff).

@MichaReiser MichaReiser closed this as not planned Won't fix, can't repro, duplicate, stale Oct 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
formatter Related to the formatter question Asking for support or clarification
Projects
None yet
Development

No branches or pull requests

3 participants