-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
📋 Formatter: Syntax Formatting #4798
Comments
|
It seems to be used in |
If someone's interested in familiarizing themselves with the formatter API, then the following are probably good starters:
Let me know if you're interested. For testing. We have tests that automatically compare our output with black's output. You can run them with What's worth testing:
|
Is the goal here to reach parity with black? |
The goal is to be black-compatible except for pathological cases. |
Okay. Depending on how strictly you want to be having the exact same output as black, this could potentially be tested with differential fuzzing. If that's desirable, please let me know and I can write a harness for this 🙂 Otherwise, I will likely swing back around once this reaches a steady state and add an idempotency fuzzer. |
I would dearly love at least the option to choose a different default quote character. At least on US keyboards, double quotes are ergonomically inferior. It's the number one reason why blue exists. |
We still plan to make the quote style and indentation style configurable, though the exact settings scheme etc. haven’t been designed yet. |
See #1904 for an in-depth discussion around the goal. The purpose of this task is to track the implementation work |
Some other good first issues could be
|
Hello, I'm interested in the formatter and while having a look at the code I did the raise formatter code. I'm not sure it's good but I can open a PR if you want. I took inspiration from the return formatter. |
Feel free to open a PR. On which node where you working? |
Sorry I edited my comment, it was the StmtRaise node. |
Any chance we can open an issue for |
Sure: #5826 |
## Summary Adds `global` and `nonlocal` formatting, without the "deviation from black" outlined in the linked issue, which I'll do separately. See: #4798. ## Test Plan Added a fixture in the Ruff-specific directory since the Black fixtures don't seem to cover this.
I'm closing this one. There's still some work left to be done but we'll track this as part of #6203 |
This task coordinates the work on implementing formatting for the Python syntax.
Please create an issue and comment that you intend to work on before starting a new syntax. This allows us to better coordinate the work.
Module
Module
(includesTypeIgnore
) #4800Interactive
Expression
FormatModExpression
#5689FunctionType
Statements
Arguments
, andArg
) #4799ClassDef
#4955Return
(Implement StmtReturn #4960)Delete
#5287Assign
(basic implementation done, missing is wrapping the left hand side like black which is hard)AugAssign
Format StmtAugAssign #5655AnnAssign
#5662For
/AsyncFor
#5288While
#4806If
Statement #4956With
/AsyncWith
(includesWithItem
) #5368Match
(includesMatchCase
andPatterns
) #5834raise
statement #5595Try
/TryStar
(includesExceptHandler
) #5245Assert
(Formatassert
statement #5168)Import
Format import statements #5493ImportFrom
(includesAlias
) Format import statements #5493Global
Addglobal
andnonlocal
formatting #6170 (deviation from black: break over multiple lines if it exceeds the line-width Line too long: Multi-line global psf/black#1357)Nonlocal
Addglobal
andnonlocal
formatting #6170 (deviation from black: break over multiple lines if it exceeds the line-width Line too long: Multi-line global psf/black#1357)Expr
Format StmtExpr #4788Pass
(Implement StmtPass #4959)Break
Continue
TypeAlias
#5929 (Add formatting of type parameters in class and function definitions #6161, Add formatting of type alias statements #6162)Expressions
BoolOp
#4962NamedExpr
Format assignment expressions (FormatExprNamedExpr
) #5613BinOp
(hard) #4896UnaryOp
#5216Lambda
#5826IfExp
Format ExprIfExp (ternary operator) #5597Dict
#5206Set
SetComp
(depends onListComp
) #5674DictComp
(depends onListComp
) #5778GeneratorExp
(depends onListComp
) #5676Await
Yield
/YieldFrom
(good first issue) #5916Compare
#5242Call
(Format call expressions (without call chaining) #5341, Formatter: Attribute and call chains "fluent interface" #5343)FormattedValue
andJoinedStr
) #5913Constant
(Add basic Constant formatting #4954)Attribute
#5257 (Formatter: Attribute and call chains "fluent interface" #5343)Subscript
#5286Starred
#5650Name
#4802List
(Format binary expressions #4862)Tuple
(Format ExprTuple #4963)Slice
(Format Slice Expressions #5047)Improvements
Cross-cutting
JoinNodesBuilder
#4801SuiteStatement
#5326Bugs
See open issues
Notes
#4730 removed the prototype from @charliermarsh. It's worth taking a look at it when implementing new formatting because it already formatted a lot of syntaxes correctly.
The text was updated successfully, but these errors were encountered: