r-lib / lintr

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

False positive in return_linter(return_style="explicit") when the formals are complex #2616

Open MichaelChirico opened 3 months ago

MichaelChirico commented 3 months ago
lint(linters=return_linter(return_style="explicit"), R"(
foo <- function(y,
                x = {
                  y <- sqrt(y)
                  y + 1
                }) {
  return(x + y)
})")
# <text>:5:19: warning: [return_linter] All functions must have an explicit return().
#                   y + 1
#                   ^

The XPath for finding the function body needs to be adjusted a bit I reckon.