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

Need relative, not global descendant in unnecessary_lambda_linter() #2250

Merged
merged 1 commit into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading