-
Notifications
You must be signed in to change notification settings - Fork 195
Ignore symbols used for subsetting in object_name_linter
#765
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
Conversation
|
The XPath is similar to T_and_F_symbol linter, but it uses the |
| # assignments | ||
| "//SYMBOL[", | ||
| " not(preceding-sibling::OP-DOLLAR)", | ||
| " and ancestor::expr[", |
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 have a feeling ancestor may be too aggressive without more conditions. Running the comparison script now to try and confirm.
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.
Sounds good. I tested "//parent::expr" before, which produced false positives (detecting symbols on the other side of assigments).
"ancestor" was the only axis that passed all the tests.
|
Attaching some comparison results: |
|
The lints absent in this PR look good. All of them are either a generic defined in the package or a dollar-subset expression.
Found a new false positive: shouldn't lint because |
|
Updated XPath to exclude parts of |
| expect_lint("good_name[1L][badName] <- badName2", NULL, linter) | ||
| expect_lint("good_name[[badName]] <- badName2", NULL, linter) | ||
| expect_lint("good_name[[1L]][[badName]] <- badName2", NULL, linter) | ||
| expect_lint("good_name[[fun(badName)]] <- badName2", NULL, linter) |
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.
This case necessitates the ancestor axis for the not() expression.
|
Currently rerunning on all the packages with new lints from your sample, @MichaelChirico. |
|
I checked against the follwing packages and found no erroneous added nor removed lints. List of tested Packagesassertthat bravo broom callr canvasXpress catdap cli clipr ClusterBootstrap CorrectedFDR cpp11 crayon crochet DBI DEEVD desc devtools dfoptim Dodge epsiwal etma evaluate fcros forcats generics ggplot2 gramEvol gtable HiddenMarkov highr HLSM hms htmlwidgets httr idr ineq knitr labeling leontief LogrankA malani mgcv modelr msBP munsell noncompliance paramtest peakRAM pillar pkgbuild pkgload plyr PPQplan processx progress ps R6 rappdirs RColorBrewer Rcpp RcppArmadillo RcppEigen readr readxl rematch2 remotes reprex Rgb rmarkdown rprojroot rstudioapi rvest scales selectr seqmon SetRank shiny shinyAce space sra stringr tidyselect tidyverse uFTIR VecStatGraphs2D viridisLite waldo withr yarr |
| " or preceding-sibling::RIGHT_ASSIGN", | ||
| " or following-sibling::EQ_ASSIGN", | ||
| " ]", | ||
| " and not(ancestor::expr[", |
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.
as it's written, this is a totally different expression -- is there some relationship between the LEFT_ASSIGN (etc) ancestor and the OP-LEFT-BRACKET ancestor? I'm wondering if it's safer to express both conditions at once (it might not be).
Anyway I am running on a sample of 500 packages now, let's see what comes out.
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.
The problem with combining it the conditions need to be nested, i.e. there may be no such ancestor before reaching the (first) assignment ancestor.
I couldn't get it to work in a single condition but if you habe an idea for a different one, I'm happy to try it.
The tests are pretty comprehensive now. The only missing bits are nested expressions with on-the-fly assignments, but I checked a few of these interactively, e.g. fun(BAD <- 42).
|
On the large sample of packages, still turning up a lot of new-not-old and old-not-new lints. Probably too big to attach here... took a random sample of 500 from each: |
|
Manually inspected main_not_pr.txt. I found one class of false negatives that need fixing: Manually inspected pr_not_main.txt I found no false positives. I'll go ahead and try to fix the false negatives and add tests for them. |
MichaelChirico
left a comment
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.
Good stuff. Glad the comparison script has been so helpful to draw out edge cases. LGTM now.
fixes #582