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

Comments in unusual locations of a table lead to syntax errors #318

Closed
idbrii opened this issue Dec 17, 2021 · 3 comments · Fixed by #326
Closed

Comments in unusual locations of a table lead to syntax errors #318

idbrii opened this issue Dec 17, 2021 · 3 comments · Fixed by #326
Labels
bug Something isn't working

Comments

@idbrii
Copy link

idbrii commented Dec 17, 2021

Similar to #23 and #307, comments inside a table definition makes stylua create invalid syntax:

local a = {
    b =  -- a comment breaks it
    {
        c = "d",
    },
}

becomes

local a = {
    b =  -- a comment breaks it{
        c = "d",
    },
}

Tested on v0.11.2

@JohnnyMorganz JohnnyMorganz added the bug Something isn't working label Dec 17, 2021
@JohnnyMorganz
Copy link
Owner

Hm, where would you stick the comment in this situation? I just quickly stuck it into prettier and I see that for JavaScript they just stick the comment before the b = line - probably the easiest place to put it

@idbrii
Copy link
Author

idbrii commented Dec 23, 2021

I would expect it to be on the same line because I'd expect comments to be mostly invisible to the prettifier and more in line with :

local a = {
    b = { -- a comment breaks it
        c = "d",
    },
}

But, yeah doing it on the same line also seems reasonable:

local a = {
    -- a comment breaks it
    b = {
        c = "d",
    },
}

Looks like luacheck comments are all start of line -- that's the main thing I'd expect to break if you moved the comment.

@JohnnyMorganz
Copy link
Owner

Yeah, I'll probably stick it on the line above, because that's the simplest way to do it currently.
Hopefully I'll get time today to sort it out and publish a new release

@JohnnyMorganz JohnnyMorganz changed the title Bug: Shouldn't collapse into previous line's comment Comments in unusual locations of a table lead to syntax errors Jan 1, 2022
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