-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Fix switch indentation for list patterns #75953
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -262,6 +262,11 @@ private static void AddBracketIndentationOperation(List<IndentBlockOperation> li | |
// Brackets in list patterns are formatted like blocks, so align close bracket with open bracket | ||
AddIndentBlockOperation(list, bracketPair.openBracket.GetNextToken(includeZeroWidth: true), bracketPair.closeBracket.GetPreviousToken(includeZeroWidth: true)); | ||
|
||
if (IsSwitchExpressionPattern(node)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this needs a 'why' explanation as to why we don't want to execute teh rest of the code if we hit such a thing. |
||
{ | ||
return; | ||
} | ||
|
||
// If we have: | ||
// | ||
// return Goo([ //<-- determining indentation here. | ||
|
@@ -279,6 +284,11 @@ private static void AddBracketIndentationOperation(List<IndentBlockOperation> li | |
} | ||
} | ||
|
||
private static bool IsSwitchExpressionPattern(SyntaxNode node) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: i would personally inline this. It's only called in one place, and has very simple logic. If you do want to keep this as a helper method, that's ok. -- "nits" are ideas/gentle-suggestions. But i'm deferring to your judgement here on what you prefer. |
||
{ | ||
return node.Parent is SwitchExpressionArmSyntax arm && arm.Pattern == node; | ||
} | ||
|
||
private static void AddAlignmentBlockOperationRelativeToFirstTokenOnBaseTokenLine(List<IndentBlockOperation> list, (SyntaxToken openBrace, SyntaxToken closeBrace) bracePair) | ||
{ | ||
var option = IndentBlockOption.RelativeToFirstTokenOnBaseTokenLine; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you please use 'raw string literals' for test cases. There is a code refactoring to fix this up btw.