Skip to content

Commit

Permalink
skip c() unless >1 argument is used
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelChirico committed Jul 25, 2023
1 parent 25d24c0 commit a5170bf
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# lintr (development version)

## Bug fixes

* `inner_combine_linter()` no longer throws on length-1 calls to `c()` like `c(exp(2))` or `c(log(3))` (#2017, @MichaelChirico). Such usage is discouraged by `unnecessary_concatenation_linter()`, but `inner_combine_linter()` _per se_ does not apply.

# lintr 3.1.0

## Deprecations & Breaking Changes
Expand Down
2 changes: 1 addition & 1 deletion R/inner_combine_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ inner_combine_linter <- function() {
)
xpath <- glue::glue("
//SYMBOL_FUNCTION_CALL[text() = 'c']
/parent::expr
/parent::expr[count(following-sibling::expr) > 1]
/following-sibling::expr[1][ {c_expr_cond} ]
/parent::expr
")
Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/test-inner_combine_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ test_that("inner_combine_linter is order-agnostic for matching arguments", {
)
})

test_that("c() with ...length()=1 is OK", {
expect_lint("c(exp())", NULL, inner_combine_linter())
})

skip_if_not_installed("tibble")
patrick::with_parameters_test_that(
"inner_combine_linter skips allowed usages:",
Expand Down

0 comments on commit a5170bf

Please sign in to comment.