-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Replacing black and blue? #813
Comments
I'm really interested in this and definitely consider it to be within scope. Would love to chat about how it would work and how we'd push it forward :) To-date, I've focused on making Ruff a Black-compatible linter and code transformation tool, but I'd like it to expand to an all-in-one code formatter (ideally, though, in a way that's totally opt-in and incrementally adoptable, so users could continue to use Black as a formatter and Ruff as a linter). I think coupling a linter (with autofix capabilities) with an auto-formatter can make both tools more effective and efficient. Philosophically, I'm comfortable enabling a higher level of configuration than is supported by The biggest fundamental blocker to starting on auto-formatting is that we may need a CST rather than an AST. (The lexer outputs comments, so if we don't care about preserving whitespace in code, and view auto-formatting as a function of (AST + comments) => (source code), we may not actually need a CST? I haven't done enough research to understand the requirements here.) |
More information than just AST + comments will likely be needed. Black preserves empty lines between statements (up to 1 or 2 depending on where), extra parentheses with certain specific exceptions, the distinction between normal and raw strings ( But maybe an AST-like type with just that extra information would still be nicer than a CST? There’s also |
This would be excellent; all users would need would be Ruff and a type checker |
Yeah, I'd like to see what minimal set of extensions we'd need to the AST and parser to support Black-compatible formatting. Part of me wonders if we could generate any extra metadata by taking the AST and augmenting it through a second pass over the token stream... For example, we could collect comments and empty lines. We could also tag strings as normal or raw (though that's not captured in the token stream -- we'd have to look at the actual source), and so on. (We could move to LibCST and generate code from a CST representation, but I'm really hesitant since the parser is so much slower and the representation is indeed more complex.) |
For more inspiration, there's also tokenize-rt, which implements round-tripping for Python's |
Do you have thoughts about
ruff
eventually subsuming and replacingblack
or blue? I'm one of the maintainers ofblue
(because we have different opinions about a few things), and it's been pretty difficult to both keep our monkey patching of black up to date, and rely on flake8'spyproject.toml
support across multiple different major versions offlake8
.I'm thinking about alternatives, and this looks like a nice framework which could be a good starting point, so I'd like to get your thoughts about this project's direction. Would something like this be in or out of scope?
The text was updated successfully, but these errors were encountered: