You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
lintr::lint('brace.R')
/private/tmp/brace.R:4:3: style: Opening curly braces should never go on their own line and should always be followed by a new line.
{ # default
^
Is there any option to turn off this failure for this case? This alternative I think is not very readable:
As an aside, camel_case_linter is no longer one of the defaults, so NULL-ing it out of your config doesn't do anything (assuming lintr >= 2.0.0). object_name_linter has taken over it's duties. To only admit snake-case or [c|C]amel-case you could use object_name_linter = object_name_linter(c("snake_case", "camelCase", "CamelCase"))
Another use case of this is passing a multi-line code block to a function:
fun <- function(text, code) {
message(text)
code
}
fun(
"This is very very very long text.",
{
message("This is the code.")
message("It's stupid, but proves my point.")
}
)
Correcting myself: 024ecf3 works great for the first issue, and allow_single_line = TRUE fixes the other one. (I'd argue that allow_single_line = TRUE should be default if it's required for code output by styler, but I can live with that. After all, I can replace {} with NULL).
Activity
russHyde commentedon Apr 30, 2020
The simplest fix would be to make your .lintr more lenient:
As an aside,
camel_case_linteris no longer one of the defaults, so NULL-ing it out of your config doesn't do anything (assuming lintr >= 2.0.0).object_name_linterhas taken over it's duties. To only admit snake-case or [c|C]amel-case you could useobject_name_linter = object_name_linter(c("snake_case", "camelCase", "CamelCase"))MichaelChirico commentedon Apr 30, 2020
this would be the other extreme though right, where that linting rule is simply shut off in all cases?
russHyde commentedon Apr 30, 2020
Yes. To achieve your use-case, I believe we'd have to modify
open_curly_linterto separate analysis of the preceding / following newlines.bersbersbers commentedon Apr 16, 2021
Another use case of this is passing a multi-line code block to a function:
Or is there a better way to format this code?
bersbersbers commentedon Jul 20, 2021
Another example using
styler:bersbersbers commentedon May 2, 2022
@AshesITR did you intentionally not include

(and)as exceptions in #1116? The code in #487 (comment) still issues three linter messages:AshesITR commentedon May 2, 2022
@bersbersbers I forgot. Made a quick-fix #1121
The closing-curly lint is correct IMO unless you set
allow_single_line = TRUE, right?bersbersbers commentedon May 2, 2022
bersbersbers commentedon May 2, 2022
Correcting myself: 024ecf3 works great for the first issue, and
allow_single_line = TRUEfixes the other one. (I'd argue thatallow_single_line = TRUEshould be default if it's required for code output bystyler, but I can live with that. After all, I can replace{}withNULL).bersbersbers commentedon May 16, 2022
Thanks, d52614e on main works great!