Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Collate:
'extract.R'
'extraction_operator_linter.R'
'fixed_regex_linter.R'
'function_left_parentheses.R'
'function_left_parentheses_linter.R'
'get_source_expressions.R'
'ids_with_token.R'
'ifelse_censor_linter.R'
Expand Down
50 changes: 0 additions & 50 deletions R/function_left_parentheses.R

This file was deleted.

32 changes: 32 additions & 0 deletions R/function_left_parentheses_linter.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#' Function left parentheses linter
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i guess it didn't pick up the rename... a shame for the got history...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could do an interactive rebase to split the rename from the modifications?

#'
#' Check that all left parentheses in a function call do not have spaces before them.
#'
#' @evalRd rd_tags("function_left_parentheses_linter")
#' @seealso
#' [linters] for a complete list of linters available in lintr. \cr
#' <https://style.tidyverse.org/syntax.html#parentheses>
#' @export
function_left_parentheses_linter <- function() { # nolint: object_length.
xpath <- "
//FUNCTION[@col2 != following-sibling::OP-LEFT-PAREN/@col1 - 1] |
//expr[SYMBOL_FUNCTION_CALL and @col2 != following-sibling::OP-LEFT-PAREN/@col1 - 1]
"

Linter(function(source_expression) {
if (!is_lint_level(source_expression, "expression")) {
return(list())
}

xml <- source_expression$xml_parsed_content
bad_exprs <- xml2::xml_find_all(xml, xpath)

xml_nodes_to_lints(
bad_exprs,
source_expression = source_expression,
lint_message = "Remove spaces before the left parenthesis in a function call.",
range_start_xpath = "number(./@col2 + 1)", # start after function / fun
range_end_xpath = "number(./following-sibling::OP-LEFT-PAREN/@col1 - 1)" # end before (
)
})
}
2 changes: 1 addition & 1 deletion man/function_left_parentheses_linter.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions tests/testthat/test-function_left_parentheses_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,15 @@ test_that("returns the correct linting", {
expect_lint("base::print(blah, f (1))", msg, linter)
expect_lint("`+` (1, 1)", msg, linter)
expect_lint("test <- function (x) { }", msg, linter)

expect_lint(
"blah (1)",
list(message = msg, column_number = 5L, ranges = list(c(5L, 6L))),
linter
)
expect_lint(
"test <- function (x) { }",
list(message = msg, column_number = 17L, ranges = list(c(17L, 18L))),
linter
)
})