Skip to content

keyword_quote_linter for unnecessary quoting - #2030

Merged
AshesITR merged 28 commits into
mainfrom
keyword_quote
Aug 8, 2023
Merged

AshesITR merged 28 commits into
mainfrom
keyword_quote

Conversation

@MichaelChirico

Copy link
Copy Markdown
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

codecov-commenter commented Aug 1, 2023 •

Copy link
Copy Markdown

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

MichaelChirico commented Aug 1, 2023 •

Copy link
Copy Markdown
Collaborator Author

Draft: review #2031 first

@MichaelChirico
MichaelChirico marked this pull request as draft August 1, 2023 22:19
Comment thread R/keyword_quote_linter.R Resolved
Comment thread R/keyword_quote_linter.R Resolved
Comment thread R/keyword_quote_linter.R Resolved
Comment thread R/keyword_quote_linter.R Resolved
Comment thread R/keyword_quote_linter.R Resolved
@MichaelChirico
MichaelChirico marked this pull request as ready for review August 7, 2023 19:06
Comment thread R/keyword_quote_linter.R Resolved
Comment thread R/keyword_quote_linter.R Resolved
Comment thread R/keyword_quote_linter.R Resolved
Comment thread R/keyword_quote_linter.R Resolved
@AshesITR

AshesITR commented Aug 8, 2023 •

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
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

AshesITR commented Aug 8, 2023

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
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

AshesITR commented Aug 8, 2023 •

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
Collaborator Author

Ohh I get you now. even better.

Comment thread NEWS.md Resolved
\description{
\code{length(levels(x))} is the same as \code{nlevels(x)}, but harder to read.
}
\examples{

Copy link
Copy Markdown
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
Copy Markdown
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
@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