Skip to content

Commit

Permalink
metadata+vectorization
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelChirico committed Nov 18, 2023
1 parent 79597e1 commit cc6df92
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/testthat/test-if_switch_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,33 @@ test_that("if_switch_linter handles further nested if/else correctly", {
)
})

test_that("multiple lints have right metadata", {
lint_msg <- rex::rex("Prefer switch() statements over repeated if/else equality tests")

expect_lint(
trim_some("{
if (x == 'a') {
do_a()
} else if (x == 'b') {
do_b()
} else if (x == 'c') {
do_c()
}
if (y == 'A') {
do_A()
} else if (y == 'B') {
do_B()
} else if (y == 'C') {
do_C()
}
}"),
list(
list(lint_msg, line_number = 2L),
list(lint_msg, line_number = 9L)
),
if_switch_linter()
)
})

# TODO(michaelchirico): be more explicit/deliberate about nested `{}` cases like
# if (x == 'a') 1 else { if (x == 'b') 2 else 3 }

Check warning on line 82 in tests/testthat/test-if_switch_linter.R

View workflow job for this annotation

GitHub Actions / lint

file=tests/testthat/test-if_switch_linter.R,line=82,col=5,[commented_code_linter] Commented code should be removed.

0 comments on commit cc6df92

Please sign in to comment.