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

Equals na comment #546

Merged
merged 16 commits into from
Nov 30, 2020
Merged

Equals na comment #546

merged 16 commits into from
Nov 30, 2020

Conversation

MichaelChirico
Copy link
Collaborator

Closes #545

Beyond just skipping usages which might be found in comments, I also took the opportunity to extend the logic of the linter:

  • NA == x is now matched (before, it was just x == NA; this came for free with the move to xpath)
  • x != NA is also matched. It would be trivial to extend this to other comparators (>|>=|<|<=), but I wasn't sure that would gel with the name of the linter (not equals is similar enough I think)
  • This will also now match multiline usages like x\n==\nNA (again, for free with the move to xpath).

I also added a helper function for extracting Lints from their xml nodes. This can likely be re-used in a few places.

@AshesITR
Copy link
Collaborator

The logs complain about mising xml_nodes_to_lint().
I don't see it in the commits.

Also note you'll probably need to use @include xml_nodes_to_lint.R in all the files that use the function in order to have roxygen compute the correct collate order.

R/equals_na_lintr.R Show resolved Hide resolved
AshesITR
AshesITR previously approved these changes Nov 27, 2020
Copy link
Collaborator

@AshesITR AshesITR left a comment

Choose a reason for hiding this comment

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

Thanks!

@MichaelChirico
Copy link
Collaborator Author

The failure on CI is due to the following:

lintr::expect_lint("\\", rex::rex("unexpected input"), lintr::equals_na_linter)
# Error in UseMethod("xml_find_all") : 
#   no applicable method for 'xml_find_all' applied to an object of class "NULL"

The issue is that equals_na_linter receives an object with length(source_file$parsed_content)=1 but !length(source_file$xml_parsed_content).

Is that expected behavior? Till now, I've assumed length(source_file$parsed_content) > 0 implies the XML content would be there.

In this case, since the code doesn't in fact parse:

parse(text = "\\")
# Error in parse(text = "\\") : <text>:1:1: unexpected input
# 1: \
#     ^

I am surprised source_file$parsed_content is nonempty.

@AshesITR
Copy link
Collaborator

This is due to #560.
The failing code produces an invalid XML but getParseData works on it.

@MichaelChirico
Copy link
Collaborator Author

MichaelChirico commented Nov 28, 2020

I see... that means we have to keep parsed_content around in order to make good error messages? Or can we NULL it out before passing it on to be linted?

If not, I think we'd have to do something like this in all XML-based linters:

# this is in several linters already, e.g. seq_linter, missing_argument_linter, namespace_linter
if (!length(source_file$parsed_content) || is.null(source_file$xml_parsed_content))

pretty awkward IMO!

@AshesITR
Copy link
Collaborator

I agree that this double check looks a bit weird.
Maybe we should open a separate issue to adjust the behaviour and all current checks of this kind?

@MichaelChirico MichaelChirico changed the title Equals na comment WIP: Equals na comment Nov 28, 2020
@MichaelChirico
Copy link
Collaborator Author

OK moved back to WIP, I'll update it once #609 is merged.

@MichaelChirico MichaelChirico changed the title WIP: Equals na comment Equals na comment Nov 28, 2020
@MichaelChirico
Copy link
Collaborator Author

OK this should be ready to go now. Passing locally.

@MichaelChirico
Copy link
Collaborator Author

TIL sQuote(x, '"') is an R 3.6 addition. fun. Will rewrite it in utils.

R/utils.R Outdated Show resolved Hide resolved
AshesITR
AshesITR previously approved these changes Nov 29, 2020
Copy link
Collaborator

@AshesITR AshesITR left a comment

Choose a reason for hiding this comment

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

Nice, thanks!

@MichaelChirico MichaelChirico merged commit 5128b40 into master Nov 30, 2020
@MichaelChirico MichaelChirico deleted the equals-na-comment branch November 30, 2020 00:09
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.

equals_na_linter finds lints within comments
2 participants