Skip to content
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

Make sure empty block doesn't break on method declaration #360

Merged
merged 2 commits into from
Jul 23, 2021

Conversation

belav
Copy link
Owner

@belav belav commented Jul 19, 2021

closes #133

Copy link
Collaborator

@shocklateboy92 shocklateboy92 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Just splashing the pattern matching kool-aid all over you as always 👉

{
return syntaxToken.LeadingTrivia.Any(
o =>
o.Kind() != SyntaxKind.WhitespaceTrivia
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor point, but can you use pattern watching with enums here?

o.Kind() is not WhitespaceTrivia or EndOfLineTrivia

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, for some reason I have it in my head that it doesn't work with Kind()

@@ -21,6 +21,19 @@ public static Doc PrintWithConditionalSpace(BlockSyntax node, string groupId)

private static Doc Print(BlockSyntax node, string? groupId)
{
if (
node.Statements.Count == 0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mabybe I'm getting carried away with pattern matching, but would something like this be valid?

node is { Statements: { Count: 0 }, Parent: MethodDeclarationSyntax {} }

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does work but it seems harder to understand, but maybe that's because of how CSharpier formats it.

            if (
                node is { Statements: { Count: 0 }, Parent: MethodDeclarationSyntax }
                && !Token.HasComments(node.CloseBraceToken)
            ) {

If it was formatted this way it could be easier to understand

           if (
                node is
                {
                    Statements: { Count: 0 }, 
                    Parent: MethodDeclarationSyntax
                }
                && !Token.HasComments(node.CloseBraceToken)
            ) {

It could also be that I'm still somewhat new to reading this type of pattern matching.

@belav
Copy link
Owner Author

belav commented Jul 23, 2021

I'm merging this because the generic class stuff has a similar edge case to fix and I don't want to introduce conflicts. and apparently all I had to do was rebase on master after this was merged to fix it.

@belav belav merged commit 79491cd into master Jul 23, 2021
@belav belav deleted the empty-method-breaking branch July 23, 2021 01:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Empty Method should keep braces on same line
2 participants