Skip to content

Commit c814159

Browse files
authored
add PIPE to infix_metadata (#1793)
1 parent fc76887 commit c814159

File tree

4 files changed

+36
-2
lines changed

4 files changed

+36
-2
lines changed

NEWS.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@
6767

6868
* `implicit_integer_linter()` gains parameter `allow_colon` to skip lints on expressions like `1:10` (#1155, @MichaelChirico)
6969

70+
* `infix_spaces_linter()` supports the native R pipe `|>` (#1793, @AshesITR)
71+
7072
* `unneeded_concatenation_linter()` no longer lints on `c(...)` (i.e., passing `...` in a function call)
7173
when `allow_single_expression = FALSE` (#1696, @MichaelChirico)
7274

@@ -101,7 +103,7 @@
101103

102104
* `routine_registration_linter()` for identifying native routines that don't use registration (`useDynLib` in the `NAMESPACE`; @MichaelChirico)
103105

104-
* `indentation_linter()` for checking that the indentation conforms to 2-space Tidyverse-style (@AshesITR and @dgkf, #1411).
106+
* `indentation_linter()` for checking that the indentation conforms to 2-space Tidyverse-style (@AshesITR and @dgkf, #1411, #1792).
105107

106108

107109
## Notes

R/infix_spaces_linter.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ infix_metadata <- data.frame(stringsAsFactors = FALSE, matrix(byrow = TRUE, ncol
2525
"EQ_ASSIGN", "=",
2626
"EQ_SUB", "=", # in calls: foo(x = 1)
2727
"EQ_FORMALS", "=", # in definitions: function(x = 1)
28+
"PIPE", "|>",
2829
"SPECIAL", "%%",
2930
"OP-SLASH", "/",
3031
"OP-STAR", "*",
@@ -57,7 +58,7 @@ infix_metadata$unary <- infix_metadata$xml_tag %in% c("OP-PLUS", "OP-MINUS", "OP
5758
# high-precedence operators are ignored by this linter; see
5859
# https://style.tidyverse.org/syntax.html#infix-operators
5960
infix_metadata$low_precedence <- infix_metadata$string_value %in% c(
60-
"+", "-", "~", ">", ">=", "<", "<=", "==", "!=", "&", "&&", "|", "||", "<-", "->", "=", "%%", "/", "*"
61+
"+", "-", "~", ">", ">=", "<", "<=", "==", "!=", "&", "&&", "|", "||", "<-", "->", "=", "%%", "/", "*", "|>"
6162
)
6263
# comparators come up in several lints
6364
infix_metadata$comparator <- infix_metadata$string_value %in% c("<", "<=", ">", ">=", "==", "!=")

tests/testthat/test-indentation_linter.R

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,3 +667,26 @@ test_that("consecutive same-level lints are suppressed", {
667667
indentation_linter()
668668
)
669669
})
670+
671+
test_that("native pipe is supported", {
672+
skip_if_not_r_version("4.1")
673+
linter <- indentation_linter()
674+
675+
expect_lint(
676+
trim_some("
677+
a |>
678+
foo()
679+
"),
680+
NULL,
681+
linter
682+
)
683+
684+
expect_lint(
685+
trim_some("
686+
b <- a |>
687+
foo()
688+
"),
689+
NULL,
690+
linter
691+
)
692+
})

tests/testthat/test-infix_spaces_linter.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,11 @@ test_that("Rules around missing arguments are respected", {
177177
expect_lint("switch(a =, b = 2)", lint_msg, linter)
178178
expect_lint("alist(missing_arg =)", lint_msg, linter)
179179
})
180+
181+
test_that("native pipe is supported", {
182+
skip_if_not_r_version("4.1")
183+
linter <- infix_spaces_linter()
184+
185+
expect_lint("a |> foo()", NULL, linter)
186+
expect_lint("a|>foo()", rex::rex("Put spaces around all infix operators."), linter)
187+
})

0 commit comments

Comments
 (0)