Skip to content

New function_return_linter() - #1569

Merged
AshesITR merged 6 commits into
mainfrom
return
Sep 30, 2022
Merged

AshesITR merged 6 commits into
mainfrom
return

Conversation

@MichaelChirico

Copy link
Copy Markdown
Collaborator

Part of #884

Comment thread NEWS.md Resolved
@IndrajeetPatil IndrajeetPatil added this to the 3.0.2 milestone Sep 30, 2022
@AshesITR

Copy link
Copy Markdown
Collaborator

Wondering whether we should centralize this to return_linter instead of making this a separate linter. WDYT?

@MichaelChirico

Copy link
Copy Markdown
Collaborator Author

Good point -- do we have any other linters in the package yet under this umbrella?

Smaller point -- what about function_return_linter(), is that too much?

@MichaelChirico

Copy link
Copy Markdown
Collaborator Author

Just glancing over the list, I also see we could put this under assignment_linter as well. But I the emphasis here is much more on the return() side, so sticking with that.

@IndrajeetPatil IndrajeetPatil changed the title New return_assignment_linter New function_return_linter() Sep 30, 2022
Comment on lines +37 to +45
expect_lint(
trim_some("
foo <- function(x) {
return(x <<- x + 1)
}
"),
lint_msg,
linter
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also add this one for the sake of completeness?

library(lintr)

lint(
  text = "foo <- function(x) {
        return(x + 1 ->> x)
      }
    ",
  linters = function_return_linter()
)
#> <text>:2:16: warning: [function_return_linter] Move the assignment outside of the return() clause, or skip assignment altogether.
#>         return(x + 1 ->> x)
#>                ^~~~~~~~~~~

Created on 2022-09-30 with reprex v2.0.2

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants