mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 02:13:08 +00:00
Add formatting for MatchCase
(#6360)
## Summary This PR adds formatting support for `MatchCase` node with subs for the `Pattern` nodes. ## Test Plan Added test cases for case node handling with comments, newlines. resolves: #6299
This commit is contained in:
parent
8b24238d19
commit
c434bdd2bd
10 changed files with 256 additions and 29 deletions
|
@ -55,3 +55,56 @@ def foo():
|
|||
match inside_func: # comment
|
||||
case "bar":
|
||||
pass
|
||||
|
||||
|
||||
match newlines:
|
||||
|
||||
# case 1 leading comment
|
||||
|
||||
|
||||
case "top level case comment with newlines": # case dangling comment
|
||||
# pass leading comment
|
||||
pass
|
||||
# pass trailing comment
|
||||
|
||||
|
||||
# case 2 leading comment
|
||||
|
||||
|
||||
|
||||
case "case comment with newlines" if foo == 2: # second
|
||||
pass
|
||||
|
||||
case "one", "newline" if (foo := 1): # third
|
||||
pass
|
||||
|
||||
|
||||
case "two newlines":
|
||||
pass
|
||||
|
||||
|
||||
|
||||
case "three newlines":
|
||||
pass
|
||||
case _:
|
||||
pass
|
||||
|
||||
|
||||
match long_lines:
|
||||
case "this is a long line for if condition" if aaaaaaaaahhhhhhhh == 1 and bbbbbbaaaaaaaaaaa == 2: # comment
|
||||
pass
|
||||
|
||||
case "this is a long line for if condition with parentheses" if (aaaaaaaaahhhhhhhh == 1 and bbbbbbaaaaaaaaaaa == 2): # comment
|
||||
pass
|
||||
|
||||
case "named expressions aren't special" if foo := 1:
|
||||
pass
|
||||
|
||||
case "named expressions aren't that special" if (foo := 1):
|
||||
pass
|
||||
|
||||
case "but with already broken long lines" if (
|
||||
aaaaaaahhhhhhhhhhh == 1 and
|
||||
bbbbbbbbaaaaaahhhh == 2
|
||||
): # another comment
|
||||
pass
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue