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

Incorrect comment formatting when formatting Member Expressions with trailing comments #509

Closed
AllanJeremy opened this issue Jul 26, 2022 · 0 comments · Fixed by #511
Closed
Labels
bug Something isn't working

Comments

@AllanJeremy
Copy link

Summary

  • Stylua version : 0.14.1.
  • Description: Formatting a single member expression with trailing comments fails

Details

When formatting code that contains member expressions with trailing CommentLine comments, if we have a single member expression, then the member expression is pulled into the previous line thus producing invalid lua (and commenting out the member expression).

Steps to reproduce

Unformatted code

local foo = bar -- comment after bar
        .fizz -- comment after fizz

Formatted code ❌

local foo = bar -- comment after bar.fizz -- comment after fizz

Expected output

local foo = bar -- comment after bar
        .fizz -- comment after fizz

Bonus

Code that works

When we have multiple member expressions, then the comment positions are preserved

Input code

local foo = bar -- comment after bar
        .fizz -- comment after fizz
        .buzz

Formatted code ✅

local foo = bar -- comment after bar
        .fizz -- comment after fizz
        .buzz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants