Skip to content

{ gets bumped in compound while statement --> open curly violation #966

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

Closed
MichaelChirico opened this issue Jul 25, 2022 · 2 comments · Fixed by #967
Closed

{ gets bumped in compound while statement --> open curly violation #966

MichaelChirico opened this issue Jul 25, 2022 · 2 comments · Fixed by #967

Comments

@MichaelChirico
Copy link
Contributor

styler::style_text('
while ({
  bad <- grepl("_", z)
  any(bad)
}) {
  TRUE
}
')
# while (
#   {
#     bad <- grepl("_", z)
#     any(bad)
#   })
# {
#   TRUE
# }

The { is bumped but the style rules dictate { should be on the line with ):

{ should be the last character on the line. Related code (e.g., an if clause, a function declaration, a trailing comma, …) must be on the same line as the opening brace.

AFAIK clauses like ({ ... }) are generally fine, so I'm also not sure why ( and { were separated...

@lorenzwalthert
Copy link
Collaborator

We solved it for functioncalls like tryCatch() and testthat(). If the curly expression is the last, ({ is allowed, with closing }) on same line:

styler::style_text('tryCatch({
  code
})

tryCatch({
  code
  }, 
  x = 2
)')
#> tryCatch({
#>   code
#> })
#> 
#> tryCatch(
#>   {
#>     code
#>   },
#>   x = 2
#> )

Created on 2022-07-26 by the reprex package (v2.0.1)

@lorenzwalthert
Copy link
Collaborator

Reference: #543

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

Successfully merging a pull request may close this issue.

2 participants