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

Indention with multiple tokens starting (but not ending) on same line #485

Closed
lorenzwalthert opened this issue Mar 15, 2019 · 1 comment
Closed

Comments

@lorenzwalthert
Copy link
Collaborator

Multiple tokens that cause indention on the same line with at least one token causing indention over more than one line are problematic if the unindention they cause is not on the same line. This is because some lines might not be indented at all which looks odd in practice.

text <- c(
  "a <- 3",
  "b <- 5",
  "c <- purrr::map(a|",
  "b,",
  "a = 1,",
  "c = 2",
  ")"
)
styler::style_text(text)
#> a <- 3
#> b <- 5
#> c <- purrr::map(a |
#>   b,
#> a = 1,
#> c = 2
#> )

Created on 2019-03-15 by the reprex package (v0.2.1)

In the example above, the opening brace does not cause indention because | will. But the scope of the indention of | ends on the next line, leaving the remainder unindented, although it is within an expression that needs indention.

Easy fix: Don't allow multiple indention tokens on the same line if their indention scope does not end on the same line but then break the line.

purrr::map(
  a | 
    b, 
  a = 1, 
  c = 2
)

The same with braces, i.e. the following is not nice:

{{
  x
}
}

But the easy fix is to move the second { one line down. Similar to #428, but just that this issue also covers indention of tokens other than braces, but when you look at the examples in #428, I think it becomes evident that the brace case is much more common. This issue is probably also blocked by #357.

@lorenzwalthert
Copy link
Collaborator Author

lorenzwalthert commented Aug 15, 2022

Probably fixed at least for some cases with #975:

library(styler)
text <- c(
  "a <- 3",
  "b <- 5",
  "c <- purrr::map(a|",
  "b,",
  "a = 1,",
  "c = 2",
  ")"
)
style_text(text)
#> a <- 3
#> b <- 5
#> c <- purrr::map(
#>   a |
#>     b,
#>   a = 1,
#>   c = 2
#> )

Created on 2022-08-15 by the reprex package (v2.0.1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant