@@ -64,36 +64,38 @@ test_that("unnecessary_lambda_linter doesn't apply to keyword args", {
6464})
6565
6666test_that(" purrr-style anonymous functions are also caught" , {
67+ linter <- unnecessary_lambda_linter()
68+
6769 # TODO(michaelchirico): this is just purrr::flatten(x). We should write another
6870 # linter to encourage that usage.
69- expect_lint(" purrr::map(x, ~.x)" , NULL , unnecessary_lambda_linter() )
70- expect_lint(" purrr::map_df(x, ~lm(y, .x))" , NULL , unnecessary_lambda_linter() )
71- expect_lint(" map_dbl(x, ~foo(bar = .x))" , NULL , unnecessary_lambda_linter() )
71+ expect_lint(" purrr::map(x, ~.x)" , NULL , linter )
72+ expect_lint(" purrr::map_df(x, ~lm(y, .x))" , NULL , linter )
73+ expect_lint(" map_dbl(x, ~foo(bar = .x))" , NULL , linter )
7274
7375 expect_lint(
7476 " purrr::map(x, ~foo(.x))" ,
7577 rex :: rex(" Pass foo directly as a symbol to map()" ),
76- unnecessary_lambda_linter()
78+ linter
7779 )
7880 expect_lint(
7981 " purrr::map_int(x, ~foo(.x, y))" ,
8082 rex :: rex(" Pass foo directly as a symbol to map_int()" ),
81- unnecessary_lambda_linter()
83+ linter
8284 )
8385 expect_lint(
8486 " purrr::map_vec(x, ~foo(.x, y))" ,
8587 rex :: rex(" Pass foo directly as a symbol to map_vec()" ),
86- unnecessary_lambda_linter()
88+ linter
8789 )
8890})
8991
9092test_that(" cases with braces are caught" , {
9193 linter <- unnecessary_lambda_linter()
92- print_msg <- rex :: rex(" Pass print directly as a symbol to lapply()" )
94+ lint_msg <- rex :: rex(" Pass print directly as a symbol to lapply()" )
9395
9496 expect_lint(
9597 " lapply(x, function(xi) { print(xi) })" ,
96- print_msg ,
98+ lint_msg ,
9799 linter
98100 )
99101
@@ -103,7 +105,7 @@ test_that("cases with braces are caught", {
103105 print(xi)
104106 })
105107 " ),
106- print_msg ,
108+ lint_msg ,
107109 linter
108110 )
109111
0 commit comments