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

Fix enum case with rawValue includes trailing comment #1176

Conversation

art-divin
Copy link
Collaborator

@art-divin art-divin commented Jul 3, 2023

Context

When SyntaxTreeCollector visits EnumDeclSyntax, EnumDeclSyntax is being parsed from EnumCase extension (file EnumCase+SwiftSyntax.swift).

In there there's a logic which extracts the rawValue from the EnumDeclSyntax by assigning equal sign to nil:

var value = node.rawValue?.withEqual(nil).description.trimmed

Problem Statement

Using node.rawValue does not eliminate contents of trailing trivia:

po node.rawValue?.withEqual(nil)
...
     value : IntegerLiteralExprSyntax
      - unexpectedBeforeDigits : nil
       digits : integerLiteral("0")
        - text : "0"
         leadingTrivia : []
          - pieces : 0 elements
         trailingTrivia : [spaces(1), lineComment("// some comment")]
           pieces : 2 elements
             0 : spaces(1)
              - spaces : 1
             1 : lineComment("// some comment")
              - lineComment : "// some comment"
         tokenKind : TokenKind
          - integerLiteral : "0"
...

By adding withTrailingTrivia(.zero). it is possible to eliminate comments before and after defined rawValue.

Notes

Resolves #1154

@art-divin art-divin merged commit a4ce0f8 into krzysztofzablocki:master Jul 3, 2023
@rocketnik
Copy link

💜Thank you

@art-divin art-divin self-assigned this Jul 23, 2023
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.

Enum with rawValue parses comment
2 participants