Skip to content

Commit

Permalink
Merge branch 'main' into empty-ass
Browse files Browse the repository at this point in the history
  • Loading branch information
IndrajeetPatil authored Oct 8, 2022
2 parents 3463a34 + bda3739 commit 1cbdf8a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* `object_usage_linter()` gains `skip_with` argument to skip code in `with()` expressions.
To be consistent with `R CMD check`, it defaults to `TRUE` (#941, #1458, @IndrajeetPatil).

* `spaces_inside_linter()` allows terminal missing keyword arguments (e.g. `alist(arg = )`; #540, @MichaelChirico)

## New and improved features

* New `get_r_string()` helper to get the R-equivalent value of a string, especially useful for R-4-style raw strings.
Expand Down
4 changes: 3 additions & 1 deletion R/spaces_inside_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ spaces_inside_linter <- function() {
and @start != preceding-sibling::*[1]/@end + 1
and @line1 = preceding-sibling::*[1]/@line2
"
right_xpath <- glue::glue("//OP-RIGHT-BRACKET[{right_xpath_condition}] | //OP-RIGHT-PAREN[{right_xpath_condition}]")
right_xpath <- glue::glue("
//OP-RIGHT-BRACKET[{right_xpath_condition}]
| //OP-RIGHT-PAREN[{right_xpath_condition} and not(preceding-sibling::*[1][self::EQ_SUB])]")

Linter(function(source_expression) {
if (!is_lint_level(source_expression, "file")) {
Expand Down
11 changes: 11 additions & 0 deletions tests/testthat/test-infix_spaces_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,14 @@ test_that("multi-line, multi-expression case is caught", {
infix_spaces_linter()
)
})

test_that("Rules around missing arguments are respected", {
linter <- infix_spaces_linter()
lint_msg <- rex::rex("Put spaces around all infix operators.")

expect_lint("switch(a = , b = 2)", NULL, linter)
expect_lint("alist(missing_arg = )", NULL, linter)

expect_lint("switch(a =, b = 2)", lint_msg, linter)
expect_lint("alist(missing_arg =)", lint_msg, linter)
})
4 changes: 4 additions & 0 deletions tests/testthat/test-spaces_inside_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,7 @@ test_that("mutli-line expressions have good markers", {
spaces_inside_linter()
)
})

test_that("terminal missing keyword arguments are OK", {
expect_lint("alist(missing_arg = )", NULL, spaces_inside_linter())
})

0 comments on commit 1cbdf8a

Please sign in to comment.