-
Notifications
You must be signed in to change notification settings - Fork 195
refactor function_left_parentheses_linter() to XPath #1267
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ecc4694
refactor function_left_parentheses_linter() to XPath
AshesITR 0c3c76f
document()
AshesITR 89c62bd
add missing .Rd from document()
AshesITR 03abc5b
Merge branch 'main' into xpath/function_left_parentheses
AshesITR a9d6100
Merge branch 'main' into xpath/function_left_parentheses
AshesITR File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| #' Function left parentheses linter | ||
| #' | ||
| #' 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 ( | ||
| ) | ||
| }) | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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?