Skip to content

Conversation

IndrajeetPatil
Copy link
Collaborator

Closes #1396

R/seq_linter.R Outdated
and (
expr[expr[(expr|self::*)[SYMBOL_FUNCTION_CALL[ {xp_text_in_table(bad_funcs)} ]]]]
or
expr[SYMBOL='.N']
Copy link
Collaborator

Choose a reason for hiding this comment

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

oh, I didn't know this works!

usually we'd do

SYMBOL[text() = '.N']

let me check the docs to ensure there's nothing subtle about this XPath usage

Copy link
Collaborator

Choose a reason for hiding this comment

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

nice! looks like this is legit:

If one object to be compared is a node-set and the other is a string, then the comparison will be true if and only if there is a node in the node-set such that the result of performing the comparison on the string-value of the node and the other string is true.

https://www.w3.org/TR/1999/REC-xpath-19991116/#section-Expressions

Its for != where things are a bit trickier:

https://stackoverflow.com/a/4629660/3576984

)

# `.N` is a symbol, so the message should not print it as a function
expect_error(expect_lint(
Copy link
Collaborator

@MichaelChirico MichaelChirico Jun 16, 2022

Choose a reason for hiding this comment

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

I would just improve the regex in the first test rather than add a second test

)

# `dplyr::n()` takes no arguments, so the message shouldn't have `n(...)`
expect_error(expect_lint(
Copy link
Collaborator

Choose a reason for hiding this comment

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

not necessary, already implied by the first test

Copy link
Collaborator

Choose a reason for hiding this comment

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

(btw I think testthat offers expect_failure() for expecting failed expectations, and expect_success for the reverse)

@IndrajeetPatil
Copy link
Collaborator Author

@MichaelChirico Thanks! I've improved the regex and removed the redundant tests.

@MichaelChirico
Copy link
Collaborator

Thanks for your work! 🙌

@AshesITR AshesITR merged commit 152405b into r-lib:main Jun 16, 2022
@IndrajeetPatil IndrajeetPatil deleted the 1396_extend_seq_linter branch June 16, 2022 20:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

seq_linter should lint on 1:n() [dplyr] and 1:.N [data.table]
3 participants