lua-fmt icon indicating copy to clipboard operation
lua-fmt copied to clipboard

Long if statements are broken oddly

Open AgentOttsel opened this issue 7 years ago • 4 comments

I'm not sure if this is a bug or a different code style from what I'm used to, but if I have a long if statement, like this one:

if firstCondition1 and secondCondition and thirdCondition and fourthCondition and fifthCondition and sixthCondition and seventhCondition then
    code()
end

...After formatting it, it looks like this. Notice the space before then and the extra indentation before seventhCondition.

if
    firstCondition1 and secondCondition and thirdCondition and fourthCondition and fifthCondition and sixthCondition and
        seventhCondition
 then
    code()
end

I think this would've been the ideal result. No space before then, and the long line being broken WITHOUT adding any extra indentation. As long as you start a line with an operator, it's pretty clear that it's continuing the line before it.

if
    firstCondition1 and secondCondition and thirdCondition and fourthCondition and fifthCondition and sixthCondition
    and seventhCondition
then
    code()
end

Thanks for your time!

AgentOttsel avatar Oct 15 '18 13:10 AgentOttsel

imo both look a little odd to me! can't think of a better solution though

qaisjp avatar Oct 15 '18 13:10 qaisjp

lately i've been breaking up my lua code to look like typescript:

if (
  firstCondition1
  and secondCondition
  and thirdCondition
  and fourthCondition
  and fifthCondition
  and sixthCondition
  and seventhCondition
) then
  code()
end

i'm working on a fork that will do this

Zamiell avatar Sep 27 '20 19:09 Zamiell

I think that looks great!

qaisjp avatar Nov 14 '20 17:11 qaisjp

Update: I gave up on my formatter and now I use use https://typescripttolua.github.io/ with Prettier, which is a million times better for a million different reasons.

Zamiell avatar Nov 14 '20 19:11 Zamiell