Skip to content

Commit 105d814

Browse files
Merge branch 'main' into assume-glue
2 parents 32206cb + 2b62a3a commit 105d814

6 files changed

+27
-27
lines changed

R/function_argument_linter.R

+3-3
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@
4646
#' - <https://design.tidyverse.org/required-no-defaults.html>
4747
#' @export
4848
function_argument_linter <- function() {
49-
xpath <- paste(collapse = " | ", glue::glue("
50-
//{c('FUNCTION', 'OP-LAMBDA')}
49+
xpath <- "
50+
(//FUNCTION | //OP-LAMBDA)
5151
/following-sibling::EQ_FORMALS[1]
5252
/following-sibling::SYMBOL_FORMALS[
5353
text() != '...'
5454
and not(following-sibling::*[not(self::COMMENT)][1][self::EQ_FORMALS])
5555
]
56-
"))
56+
"
5757

5858
Linter(function(source_expression) {
5959
if (!is_lint_level(source_expression, "expression")) {

R/indentation_linter.R

+4-3
Original file line numberDiff line numberDiff line change
@@ -175,15 +175,16 @@ indentation_linter <- function(indent = 2L, hanging_indent_style = c("tidy", "al
175175
")"
176176
)
177177

178+
global_nodes <- function(nodes) paste0("//", nodes, collapse = "|")
178179
xp_indent_changes <- paste(
179180
c(
180181
glue::glue("//{paren_tokens_left}[not(@line1 = following-sibling::expr[
181182
@line2 > @line1 and
182183
({xp_or(paste0('descendant::', paren_tokens_left, '[', xp_last_on_line, ']'))})
183184
]/@line1)]"),
184-
glue::glue("//{infix_tokens}[{xp_last_on_line}{infix_condition}]"),
185-
glue::glue("//{no_paren_keywords}[{xp_last_on_line}]"),
186-
glue::glue("//{keyword_tokens}/following-sibling::OP-RIGHT-PAREN[
185+
glue::glue("({ global_nodes(infix_tokens) })[{xp_last_on_line}{infix_condition}]"),
186+
glue::glue("({ global_nodes(no_paren_keywords) })[{xp_last_on_line}]"),
187+
glue::glue("({ global_nodes(keyword_tokens) })/following-sibling::OP-RIGHT-PAREN[
187188
{xp_last_on_line} and
188189
not(following-sibling::expr[1][OP-LEFT-BRACE])
189190
]")

R/infix_spaces_linter.R

+3-2
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ infix_spaces_linter <- function(exclude_operators = NULL, allow_multiple_spaces
147147
# NB: parent::*[count(expr | SYMBOL_SUB)) > 1] for the unary case, e.g. x[-1]
148148
# SYMBOL_SUB for case with missing argument like alist(a =)
149149
# NB: the last not() disables lints inside box::use() declarations
150-
xpath <- paste(collapse = "|", glue::glue("//{infix_tokens}[
150+
global_xpath <- paste0("//", infix_tokens, collapse = "|")
151+
xpath <- glue::glue("({global_xpath})[
151152
parent::*[count(expr | SYMBOL_SUB) > 1]
152153
and (
153154
(
@@ -166,7 +167,7 @@ infix_spaces_linter <- function(exclude_operators = NULL, allow_multiple_spaces
166167
]
167168
]
168169
)
169-
]"))
170+
]")
170171

171172
Linter(function(source_expression) {
172173
if (!is_lint_level(source_expression, "expression")) {

R/pipe_continuation_linter.R

+8-10
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,17 @@ pipe_continuation_linter <- function() {
5353
# Where a single-line pipeline is nested inside a larger expression
5454
# e.g. inside a function definition), the outer expression can span multiple lines
5555
# without throwing a lint.
56-
57-
pipe_conditions <- "
56+
preceding_pipe <- "preceding-sibling::expr[1]/descendant::*[self::SPECIAL[text() = '%>%'] or self::PIPE]"
57+
xpath <- glue::glue("
58+
(//PIPE | //SPECIAL[text() = '%>%'])[
5859
parent::expr[@line1 < @line2]
59-
and preceding-sibling::expr/descendant-or-self::*[self::SPECIAL[text() = '%>%'] or self::PIPE]
60+
and {preceding_pipe}
6061
and (
61-
preceding-sibling::expr/descendant-or-self::expr/@line2
62-
= following-sibling::expr/descendant-or-self::expr/@line1
63-
or @line1 = preceding-sibling::expr/descendant-or-self::*[self::SPECIAL[text() = '%>%'] or self::PIPE]/@line1
62+
preceding-sibling::expr[1]/descendant-or-self::expr/@line2
63+
= following-sibling::expr[1]/descendant-or-self::expr/@line1
64+
or @line1 = {preceding_pipe}/@line1
6465
)
65-
"
66-
xpath <- glue::glue("
67-
//SPECIAL[text() = '%>%' and {pipe_conditions} ]
68-
| //PIPE[ {pipe_conditions} ]
66+
]
6967
")
7068

7169
Linter(function(source_expression) {

R/redundant_equals_linter.R

+6-5
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,12 @@
3636
#' - [outer_negation_linter()]
3737
#' @export
3838
redundant_equals_linter <- function() {
39-
xpath <- paste0(
40-
c("//EQ", "//NE"),
41-
"/parent::expr/expr[NUM_CONST[text() = 'TRUE' or text() = 'FALSE']]/parent::expr",
42-
collapse = " | "
43-
)
39+
xpath <- "
40+
(//EQ | //NE)
41+
/parent::expr
42+
/expr[NUM_CONST[text() = 'TRUE' or text() = 'FALSE']]
43+
/parent::expr
44+
"
4445

4546
Linter(function(source_expression) {
4647
if (!is_lint_level(source_expression, "expression")) {

R/vector_logic_linter.R

+3-4
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ vector_logic_linter <- function() {
6060
# <expr> ... </expr>
6161
# </expr>
6262
# we _don't_ want to match anything on the second expr, hence this
63-
xpath_parts <- glue::glue("
64-
//{ c('AND', 'OR') }[
63+
xpath <- "
64+
(//AND | //OR)[
6565
ancestor::expr[
6666
not(preceding-sibling::OP-RIGHT-PAREN)
6767
and preceding-sibling::*[
@@ -75,8 +75,7 @@ vector_logic_linter <- function() {
7575
or preceding-sibling::OP-LEFT-BRACKET
7676
])
7777
]
78-
")
79-
xpath <- paste(xpath_parts, collapse = " | ")
78+
"
8079

8180
Linter(function(source_expression) {
8281
if (!is_lint_level(source_expression, "expression")) {

0 commit comments

Comments
 (0)