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

[ts] wrong indentation when pressing enter on a very eagerly wrapped assignment line #186

Closed
mtaran-google opened this issue Jul 20, 2018 · 3 comments

Comments

@mtaran-google
Copy link
Contributor

const foo = 
    new FooRequest()

if you press enter at the end of the last line, cursor goes to column 4, when it should go to column 8 since it's wrapping again

@marijnh
Copy link
Member

marijnh commented Jul 21, 2018

That's not how the indentation currently works—it'll indent once per statement, not for every newline in the statement. I'm not quite sure how the behavior you are expecting would work.

@mtaran-google
Copy link
Contributor Author

I think we'd discussed a similar issue in #124 (though we use one formatter for Java and a different one for C++/JS/TS). Both of the following are produced by the formatter depending on external constraints (e.g. how close the 80 column ruler is):

const foo = new Bar()
                .baz()
                .quux();

const foo =
    new Bar()
        .baz()
        .quux();

In both cases, the rule is that the wrapped element gets a +4 indent relative to the column that started the element at the same syntactic level. There are two such syntactic levels here, the outer one is the assignment statement and the inner one on the right is the new...() expression. Only one indent should be added inside the expression (as you said), but also one indent may be added when a line break occurs at the level of the statement, since in the second example the RHS expression hasn't started yet.

@marijnh
Copy link
Member

marijnh commented Jul 24, 2018

This appears to be different from #124. I've added a special case for wrapped method calls under a new expression in attached patch.

But I want to make a note that this is the last extra indentation behavior I'm prepared to add. Of course I'll continue to respond to reports of obviously bad indentation, but given that no real requirements were provided for the indentation, and this is turning into 'the tool must do whatever some other tool happens to do', I can't keep adding new behavior (indentation is relatively tricky to get right, so this is turning into a bit of a time drain).

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