Skip to content

paren_brace_linter false positive within regex strings: "(match_group){quantifier}" #441

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

Closed
russHyde opened this issue Dec 20, 2019 · 7 comments · Fixed by #620
Closed
Labels
bug an unexpected problem or unintended behavior

Comments

@russHyde
Copy link
Collaborator

paren_brace_linter flags the "){" within regex definition below:

#' Checks if a file has a .tar or .tar.bz2 extension
#'
#' @noRd
.is_tar_file <- function(x) {
  grepl(pattern = ".*\\.tar(\\.bz2){0,1}", x)
}

Should paren_brace_linter be made more strict - so that it doesn't consider strings?

@russHyde russHyde added the bug an unexpected problem or unintended behavior label Jan 6, 2020
@linusjf
Copy link

linusjf commented Jan 27, 2020

grepl("(iss){2}", "Mississippi")

@russHyde
Copy link
Collaborator Author

russHyde commented Jan 27, 2020

This seems to be a more general issue with using regex-based linters.

For example, the following throws with equals_na_linter, despite the NA comprison code actually being in a string, or a comment

dont_lint_me <- "xyz == NA shouldn't occur in an R script"

x <- NA
dont_lint_me_either <- is.na(x) # use is.na instead of x == NA

Similarly no_tab_linter throws on this:

multi_line_tabbed_string <- "lorem ipsum
<tab>blah de blah"

@linusjf
Copy link

linusjf commented Jan 31, 2020

This can be mitigated by allowing the # nolint comment to specify the linter to be turned off.
eg,
#nolint paren_brace_linter

@bersbersbers
Copy link

bersbersbers commented Feb 23, 2021

It seems this did not make it into a release: it was fixed on Dec 4, 2020, and there was a 2.0.1 release on Dec 5, 2020: https://github.com/jimhester/lintr/releases/tag/v2.0.1

However, 2.0.1 on CRAN is from Feb 19, 2020: https://cran.r-project.org/web/packages/lintr/index.html

@russHyde
Copy link
Collaborator Author

russHyde commented Feb 23, 2021

I believe the commit that was tagged as v2.0.1 came from Feb 2020 (01e57c2). It's simply that the released 2.0.1 version didn't get tagged on github at the time that it was released. (That is, in December 2020 @AshesITR ensured that the CRAN-destined v2.0.1 commit from Feb 2020 was tagged with the git tag "v2.0.1")

@bersbersbers
Copy link

Sounds convincing, but that means there hasn't been a release in over a year. Would you recommend installing from GitHub master rather than from CRAN?

@russHyde
Copy link
Collaborator Author

If having this paren-brace issue solved is necessary, then use the github master. I always use the github master in continuous integration. Locally, I use multiple R environments: using the CRAN-lintr when working on stuff other than lintr.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants