Skip to content

Commit

Permalink
Support lapply(x, seq)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bisaloo committed Jun 22, 2024
1 parent 69b4ad2 commit 396a239
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 3 additions & 2 deletions R/seq_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,10 @@ seq_linter <- function() {
]
")

map_funcs <- c("sapply", "lapply", "map")
map_funcs <- c("sapply", "lapply", "map")
seq_funcs <- xp_text_in_table(c("seq_len", "seq"))
sequence_xpath <- glue("
parent::expr[following-sibling::expr/SYMBOL[text() = 'seq_len']]
parent::expr[following-sibling::expr/SYMBOL[ {seq_funcs} ]]
/parent::expr/parent::expr[
expr/SYMBOL_FUNCTION_CALL[text() = 'unlist']
]"
Expand Down
6 changes: 6 additions & 0 deletions tests/testthat/test-seq_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ test_that("finds potential sequence() replacements", {
linter
)

expect_lint(
"unlist(lapply(x, seq))",
lint_msg,
linter
)

# Even for prefixed purrr:: calls
expect_lint(
"unlist(purrr::map(x, seq_len))",
Expand Down

0 comments on commit 396a239

Please sign in to comment.