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

mistranformation with comments on hanging then statements #164

Closed
matthargett opened this issue May 21, 2021 · 2 comments · Fixed by #168
Closed

mistranformation with comments on hanging then statements #164

matthargett opened this issue May 21, 2021 · 2 comments · Fixed by #168
Labels
bug Something isn't working

Comments

@matthargett
Copy link

Here's a diff after running latest master, which makes the codebase in question no longer parse:

@@ -317,16 +290,12 @@ local function readToken(lexer, prev)
                then
                        pos += 1
                        continue
-               elseif
-                       code == 10 -- \n
-               then
+               elseif code == 10 -- \n then
                        pos += 1
                        lexer.line += 1
                        lexer.lineStart = pos - 1
                        continue
-               elseif
-                       code == 13 -- \r
-               then
+               elseif code == 13 -- \r then
                        if charCodeAt(body, pos + 1) == 10 then
                                pos += 2
                        else
@JohnnyMorganz JohnnyMorganz added the bug Something isn't working label May 21, 2021
@matthargett
Copy link
Author

Another example that may be the same root cause:

@@ -129,9 +129,7 @@ function Map.__newindex(table_, key, value)
 end

 local function coerceToMap(mapLike: Map<any, any> | Table<any, any>): Map<any, any>
-       return instanceOf(mapLike, Map)
-               and mapLike -- ROBLOX: order is preservered
-               or Map.new(Object.entries(mapLike)) -- ROBLOX: order is not preserved
+       return instanceOf(mapLike, Map) and mapLike -- ROBLOX: order is preservered or Map.new(Object.entries(mapLike)) -- ROBLOX: order is not preserved
 end

This is much worse, because the code parses and passes selene correctly, but then unit tests fail. More subtle, and therefore more dangeous to use StyLua in a codebase with <92% code coverage.

@JohnnyMorganz
Copy link
Owner

Similar issue:

if -- comment
	foo
then
end

if 
	foo
	-- comment
then
end

turns to

if  -- commentfoo then
end

if foo-- comment
 then
end

and likewise for while condition do statements of a similar format

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