Skip to content

Commit 94ae4d0

Browse files
Deprecate extraction_operator_linter()
closes #1485
1 parent 3fd90ba commit 94ae4d0

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

NEWS.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
+ Helper `with_defaults()`.
1313
* `all_linters()` has signature `all_linters(..., packages)` rather than `all_linters(packages, ...)` (#2332, @MichaelChirico). This forces `packages=` to be supplied by name and will break users who rely on supplying `packages=` positionally, of which we found none searching GitHub.
1414
* Adjusted various lint messages for consistency in readability (#1330, @MichaelChirico). In general, we favor lint messages to be phrased like "Action, reason" to but the "what" piece of the message front-and-center. This may be a breaking change for code that tests the specific phrasing of lints.
15+
* `extraction_operator_linter()` is deprecated. Although switching from `$` to `[[` has microoptimization benefits, it can lead to non-idiomatic code in many contexts (e.g. R6 classes, Shiny applications, etc.) (@IndrajeetPatil).
1516

1617
## Bug fixes
1718

R/extraction_operator_linter.R

+7
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@
5151
#' @seealso [linters] for a complete list of linters available in lintr.
5252
#' @export
5353
extraction_operator_linter <- function() {
54+
lintr_deprecated(
55+
what = "extraction_operator_linter",
56+
version = "3.2.0",
57+
type = "Linter",
58+
signal = "warning"
59+
)
60+
5461
constant_nodes_in_brackets <- paste0("self::", c("expr", "OP-PLUS", "NUM_CONST", "STR_CONST"))
5562
xpath <- glue("
5663
//OP-DOLLAR[not(preceding-sibling::expr[1]/SYMBOL[text() = 'self' or text() = '.self'])]

tests/testthat/test-extraction_operator_linter.R

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1+
test_that("extraction_operator_linter generates deprecation warning", {
2+
expect_warning(
3+
extraction_operator_linter(),
4+
rex::rex("Linter extraction_operator_linter was deprecated")
5+
)
6+
})
7+
18
test_that("extraction_operator_linter skips allowed usages", {
2-
linter <- extraction_operator_linter()
9+
expect_warning({
10+
linter <- extraction_operator_linter()
11+
})
312

413
expect_lint("x[[1]]", NULL, linter)
514
expect_lint("x[-1]", NULL, linter)
@@ -10,7 +19,9 @@ test_that("extraction_operator_linter skips allowed usages", {
1019
})
1120

1221
test_that("extraction_operator_linter blocks disallowed usages", {
13-
linter <- extraction_operator_linter()
22+
expect_warning({
23+
linter <- extraction_operator_linter()
24+
})
1425
msg_b <- rex::escape("Use `[[` instead of `[` to extract an element.")
1526
msg_d <- rex::escape("Use `[[` instead of `$` to extract an element.")
1627

0 commit comments

Comments
 (0)