Skip to content
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

Unnecessary lambda linter misses multi-line cases #1567

Closed
MichaelChirico opened this issue Sep 28, 2022 · 1 comment · Fixed by #2193
Closed

Unnecessary lambda linter misses multi-line cases #1567

MichaelChirico opened this issue Sep 28, 2022 · 1 comment · Fixed by #2193
Labels
false-negative code that should lint, but doesn't

Comments

@MichaelChirico
Copy link
Collaborator

Follow-up to #1541 to catch more cases

@MichaelChirico MichaelChirico added the false-negative code that should lint, but doesn't label Sep 28, 2022
@MichaelChirico
Copy link
Collaborator Author

Adding new test cases here so that we can avoid commented_code_linter() in the sources. These all currently fail (0 lints instead of 1), bug is fixed by addressing these.

 test_that("cases with braces are caught", {
   linter <- unnecessary_lambda_linter()
   expect_lint(
     "lapply(x, function(xi) { print(xi) })",
     "xxx",
     linter
   )
   
   expect_lint(
     trim_some("
       lapply(x, function(xi) {
         print(xi)
       })
     "),
     "xxx",
     linter
   )
   
   expect_lint(
     "lapply(x, function(xi) { return(print(xi)) })",
     "xxx",
     linter
   )
   
   expect_lint(
     trim_some("
       lapply(x, function(xi) {
         print(xi)
       })
     "),
     "xxx",
     linter
   )
   
   expect_lint(
     trim_some("
       lapply(x, function(xi) {
         return(print(xi))
       })
     "),
     "xxx",
     linter
   )
 })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
false-negative code that should lint, but doesn't
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant