Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an exception for box::use() to infix spaces linter #1105

Merged
merged 5 commits into from
Apr 27, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

## New features, bug fixes, improvements

* Add exception for `box::use()` declarations to infix spaces linter (#1087, @klmr)
* Writes comments to GitHub repo when running in Jenkins CI (#488, @fdlk)
* Updated R CMD GitHub Actions workflow to check for R 3.6 on Ubuntu, instead of R 3.3, and for R 4.0 on Windows, instead of R 3.6 (#803, @ dragosmg)
* Added a secondary, more restrictive lint workflow - `lint-changed-files` - for newly written / modified code (#641, @dragosmg)
Expand Down
9 changes: 9 additions & 0 deletions R/infix_spaces_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ infix_spaces_linter <- function(exclude_operators = NULL, allow_multiple_spaces
# NB: preceding-sibling::* and not preceding-sibling::expr because
# of the foo(a=1) case, where the tree is <SYMBOL_SUB><EQ_SUB><expr>
# NB: position() > 1 for the unary case, e.g. x[-1]
# NB: the last not() disables lints inside box::use() declarations
xpath <- glue::glue("//*[
({xp_or(paste0('self::', infix_tokens))})
and position() > 1
Expand All @@ -108,6 +109,14 @@ infix_spaces_linter <- function(exclude_operators = NULL, allow_multiple_spaces
and following-sibling::*[1]/@col1 {op} @col2 + 2
)
)
and not(
self::OP-SLASH[
ancestor::expr/preceding-sibling::OP-LEFT-PAREN/preceding-sibling::expr[
./SYMBOL_PACKAGE[text() = 'box'] and
./SYMBOL_FUNCTION_CALL[text() = 'use']
]
]
)
]")

bad_expr <- xml2::xml_find_all(xml, xpath)
Expand Down
19 changes: 19 additions & 0 deletions tests/testthat/test-infix_spaces_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,22 @@ test_that("infix_spaces_linter can allow >1 spaces optionally", {
infix_spaces_linter(allow_multiple_spaces = FALSE)
)
})

test_that("exception for box::use()", {
linter <- infix_spaces_linter()

expect_lint("box::use(a/b)", NULL, linter)
expect_lint("box::use(./a/b)", NULL, linter)
expect_lint(
trim_some("
box::use(
a,
a/b,
../a,
alias = a/b/c[xyz = abc, ...],
)
"),
NULL,
linter
)
})