Koihik / LuaFormatter

Code formatter for Lua
Apache License 2.0
715 stars 86 forks source link

Syntax error from long string inside table constructor brackets #291

Open hugomg opened 1 year ago

hugomg commented 1 year ago

LuaFormatter version 1.3.6 produces invalid output if the input program contains a [[ string inside a [ ] = table constructor.

t = { [ [[abc]] ] = 1}

When we format this, the spaces are removed and the result is a syntax error

t = {[[[abc]]] = 1}

The good news is that LuaFormatter already does the right thing for array brackets such as xs[ [[abc]] ]. Perhaps whatever logic is being used there should also be used for table constructors.

hugomg commented 1 year ago

For reference, I think the parts responsible for writing arrays and fields are these ones:

https://github.com/Koihik/LuaFormatter/blob/29afe1046ad015de96ffdb6d361a21882356e801/src/visitor/var.cpp#L54-L70

https://github.com/Koihik/LuaFormatter/blob/29afe1046ad015de96ffdb6d361a21882356e801/src/visitor/table.cpp#L199-L211