Open scambier opened 9 months ago
Thanks for reporting! I especially appreciate your specific and in-depth examples 🙂
Single-line ifs are tricky to handle since it's pretty different from the standard Lua grammar. I'll have to add these examples as test cases and make sure the formatter handles them correctly.
For anyone else that might want to take a stab at this, the logic for formatting single-line if statements is here in the visitIfStatement
method of formatter.ts
, specifically the section inside if (node.oneLine) {
.
Thanks for this program. And-- I was about to report a bug with the autoformatter joining commands onto a comment line before them, but I found this bug and I realize everywhere I see this happening in a current program it's adjacent to an if() line, so it sounds like the same root cause. It's odd that having an if() line would cause two different lines to join together... this can at least be another test suite case...
Example:
if (wound) hp-=1
--now check if dead
if hp <= 0 then
print("dead")
end
autoformats to this:
if (wound) hp -= 1
--now check if dead if hp <= 0 then
print("dead")
end
Under certain conditions, when using the single-line
if()
shorthand, the formatter incorrectly removes the line return right afterExamples:
A more convoluted example
is formatted to
Note the
-- water
comment that got merged with the line right after