-
Notifications
You must be signed in to change notification settings - Fork 883
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鈥檒l 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鈥檛 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: