Skip to content

Commit

Permalink
need relative, not global descendant (#2250)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelChirico authored Oct 30, 2023
1 parent a6e20bb commit 1493c5e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion R/unnecessary_lambda_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ unnecessary_lambda_linter <- function() {
count(.//SYMBOL[self::* = preceding::SYMBOL_FORMALS[1]]) = 1
and count(.//SYMBOL_FUNCTION_CALL[text() != 'return']) = 1
and preceding-sibling::SYMBOL_FORMALS =
//expr[
.//expr[
position() = 2
and preceding-sibling::expr/SYMBOL_FUNCTION_CALL
and not(preceding-sibling::*[1][self::EQ_SUB])
Expand Down
10 changes: 10 additions & 0 deletions tests/testthat/test-unnecessary_lambda_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ test_that("unnecessary_lambda_linter skips allowed usages", {
expect_lint("lapply(l, function(x) foo(x) * 2)", NULL, linter)
expect_lint("lapply(l, function(x) foo(x) ^ 3)", NULL, linter)
expect_lint("lapply(l, function(x) foo(x) %% 4)", NULL, linter)

# Don't include other lambdas, #2249
expect_lint(
trim_some('{
lapply(x, function(e) sprintf("%o", e))
lapply(y, function(e) paste(strlpad(e, "0", width)))
}'),
NULL,
linter
)
})

test_that("unnecessary_lambda_linter blocks simple disallowed usage", {
Expand Down

0 comments on commit 1493c5e

Please sign in to comment.