Skip to content

Use XPath for T_and_F_symbol_linter and fix false positives - #759

Merged
MichaelChirico merged 7 commits into
masterfrom
fix/657-t-and-f-symbol
Feb 18, 2021
Merged

MichaelChirico merged 7 commits into
masterfrom
fix/657-t-and-f-symbol

Conversation

@AshesITR

Copy link
Copy Markdown
Collaborator

fixes #657

  • implement fix
  • add regression test
  • add NEWS bullet

Migrating to XPath makes adding other exceptions easier as well.
Had to add the argument offset to xml_nodes_to_lint to keep the column numbers unchanged.

@AshesITR

AshesITR commented Feb 15, 2021 •

Copy link
Copy Markdown
Collaborator Author

The exclusions-test also suffered from a #657 related false positive.
One of the eight lints was for the F in F = T.

That said: Maybe T_and_F_symbol_linter should throw a lint for assigning to T or F with a different message?
e.g.

Don't use {T/F} as a variable name, as it can break code relying on {T/F} being {TRUE/FALSE}.

WDYT?

@MichaelChirico

Copy link
Copy Markdown
Collaborator

Don't use {T/F} as a variable name, as it can break code relying on {T/F} being {TRUE/FALSE}.

I agree with this (and have run into this issue before). FWIW, using T/F as variables is against the style guide due to conflicts with base::T/base::F (and the T case is specifically called out):

https://style.tidyverse.org/syntax.html#object-names

Comment thread R/T_and_F_symbol_linter.R Resolved
Comment thread R/T_and_F_symbol_linter.R Resolved
Comment thread R/T_and_F_symbol_linter.R Resolved
Comment thread R/utils.R
xml_nodes_to_lint <- function(xml, source_file, message, linter,
type = c("style", "warning", "error")) {
type = c("style", "warning", "error"),
offset = 0L) {

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.

nice extension! eventually i think we can refactor a lot of the XPath lints to use this helper. Basically as long as message is static (e.g. this isn't the case for seq_linter) I think this can be used.

@AshesITR AshesITR Feb 16, 2021 •

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.

Maybe we can even vectorize on xml and message?
The T and F symbol linter needs a wrapper at the call site that just generates the proper message.

All call sites lapply() over some nodeset, and the function name actually suggests nodes and not a node.

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.

Let's tuck this away to revisit for now

@AshesITR
AshesITR force-pushed the fix/657-t-and-f-symbol branch from 16dfbd5 to e29e501 Compare February 17, 2021 19:40
@AshesITR

Copy link
Copy Markdown
Collaborator Author

r-release CI failures are due to #761.

@MichaelChirico
MichaelChirico merged commit 25b2e1d into master Feb 18, 2021
@MichaelChirico
MichaelChirico deleted the fix/657-t-and-f-symbol branch February 18, 2021 07:55
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.

incorrectly tagged lint "Use FALSE instead of the symbol F"

2 participants