r-lib / lintr

Static Code Analysis for R
https://lintr.r-lib.org
Other
1.16k stars 184 forks source link

New linter for tidyverse return style #1135

Open MichaelChirico opened 2 years ago

MichaelChirico commented 2 years ago

Here's another thing straight out of the style guide that we don't lint for, that styler fixes:

styler::style_text("
foo <- function(x) {
  if (x > 1) return(x)
  return(x - 1)
}
")
# foo <- function(x) {
#   if (x > 1) {
#     return(x)
#   }
#   return(x - 1)
# }

https://style.tidyverse.org/syntax.html#inline-statements

Function calls that affect control flow (like return(), stop() or continue) should always go in their own {} block:

MichaelChirico commented 7 months ago

I guess this should be a new parameter in return_linter()?

AshesITR commented 7 months ago

This seems to better suit brace_linter() since the advice is regarding placement of braces.