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

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

Open
AgentOttsel opened this issue Oct 15, 2018 · 2 comments

Comments

@AgentOttsel
Copy link

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
    }
)
@Arpple
Copy link

Arpple commented Oct 17, 2018

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 🤔

@AgentOttsel
Copy link
Author

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 added a commit to AgentOttsel/lua-fmt that referenced this issue Nov 28, 2018
Credits to Arpple for providing the code that fixed this issue: trixnz#35 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants