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

Strange indentation when assigning a function with a table argument to a variable

Open AgentOttsel opened this issue 7 years ago • 2 comments

If I have a variable and assign the result of a function that receives a table to it, like this:

instance = MyClass.new({
    stuff
})

...The formatted code looks like this. It's confusing to me how MyClass.new( has the same indentation level as the table that it's receiving:

instance =
    MyClass.new(
    {
        arguments
    }
)

I believe this would be the ideal result:

instance = MyClass.new(
    {
        arguments
    }
)

AgentOttsel avatar Oct 15 '18 13:10 AgentOttsel

I suspect this part and after adding more check to be like this

const canBreakLine = node.init.some(n =>
    n != null &&
    n.type !== 'TableConstructorExpression' &&
    n.type !== 'FunctionDeclaration' &&
    n.type !== 'CallExpression'
);

the result is as you expect

instance = MyClass.new(
    {
        arguments
    }
)

adding checkCallExpression is just come from hard debugging and I don't understand how it's actually works 🤔

Arpple avatar Oct 17 '18 11:10 Arpple

Ooh, nicely done, @Arpple! Do you wanna open a pull request for that? Since you're not sure how it works, maybe we should get @trixnz's opinion first, though.

AgentOttsel avatar Oct 17 '18 14:10 AgentOttsel