Skip to content
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

keyword_quote_linter for unnecessary quoting #2030

Merged
merged 28 commits into from
Aug 8, 2023
Merged

keyword_quote_linter for unnecessary quoting #2030

merged 28 commits into from
Aug 8, 2023

Conversation

MichaelChirico
Copy link
Collaborator

Continuing on with #884.

There are a few customizations/options we could add, LMK if we should do those here or in follow-up issues.

@codecov-commenter
Copy link

codecov-commenter commented Aug 1, 2023

Codecov Report

Merging #2030 (e30fa49) into main (788bdca) will increase coverage by 0.00%.
The diff coverage is 100.00%.

❗ Current head e30fa49 differs from pull request most recent head df1114c. Consider uploading reports for the commit df1114c to get more accurate results

@@           Coverage Diff           @@
##             main    #2030   +/-   ##
=======================================
  Coverage   99.61%   99.62%           
=======================================
  Files         115      116    +1     
  Lines        4983     5049   +66     
=======================================
+ Hits         4964     5030   +66     
  Misses         19       19           
Files Changed Coverage Δ
R/keyword_quote_linter.R 100.00% <100.00%> (ø)

@MichaelChirico
Copy link
Collaborator Author

MichaelChirico commented Aug 1, 2023

Draft: review #2031 first

@MichaelChirico MichaelChirico marked this pull request as draft August 1, 2023 22:19
R/keyword_quote_linter.R Outdated Show resolved Hide resolved
R/keyword_quote_linter.R Show resolved Hide resolved
R/keyword_quote_linter.R Show resolved Hide resolved
R/keyword_quote_linter.R Outdated Show resolved Hide resolved
R/keyword_quote_linter.R Outdated Show resolved Hide resolved
@MichaelChirico MichaelChirico marked this pull request as ready for review August 7, 2023 19:06
R/keyword_quote_linter.R Outdated Show resolved Hide resolved
R/keyword_quote_linter.R Show resolved Hide resolved
R/keyword_quote_linter.R Outdated Show resolved Hide resolved
R/keyword_quote_linter.R Show resolved Hide resolved
@AshesITR
Copy link
Collaborator

AshesITR commented Aug 8, 2023

I was stumped and debugged.
Turns out the actual problem is xml_child() is not vectorized for nodesets:
image

The correct code should be

assignment_to_string <- vapply(
  assignment_expr, 
  function(x) xml_name(xml2::xml_child(x)) == "STR_CONST", 
  logical(1L)
)

@MichaelChirico
Copy link
Collaborator Author

Thanks for checking. Are you suggesting we shouldn't use xml_children()? Your workaround looks a lot clunkier given that the code already works as intended with xml_children()

@AshesITR
Copy link
Collaborator

AshesITR commented Aug 8, 2023

I'm suggesting to fix the comment.
It's actually not <= 1 but = 1 children guaranteed by the XPath, making xml_children() correct.
The empty case (0 elements) occurs when there are no matches for the XPath, where xml_children() also behaves correctly by returning xml_missing().

@MichaelChirico
Copy link
Collaborator Author

oh, but that's what I meant -- 1 if there's a match, 0 if not, so <= 1, and it works in both cases. Let me reword for clarity.

@AshesITR
Copy link
Collaborator

AshesITR commented Aug 8, 2023

The part about xml_child is wrong. It's simply not vectorized over nodesets so it would return the first child of the first match instead of the first child for each element in the resultset, and error if the resultset is empty.

@MichaelChirico
Copy link
Collaborator Author

Ohh I get you now. even better.

NEWS.md Outdated Show resolved Hide resolved
@@ -8,6 +8,20 @@ length_levels_linter()
}
\description{
\code{length(levels(x))} is the same as \code{nlevels(x)}, but harder to read.
}
\examples{
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder how that slipped...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I must have forgotten to roxygenize() after adding the examples in the other PR...

@AshesITR AshesITR merged commit 0a961fb into main Aug 8, 2023
21 checks passed
@MichaelChirico MichaelChirico deleted the keyword_quote branch August 8, 2023 20:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants