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

False positive in nonportable_path_linter #1356

Open
MichaelChirico opened this issue Jun 4, 2022 · 3 comments
Open

False positive in nonportable_path_linter #1356

MichaelChirico opened this issue Jun 4, 2022 · 3 comments
Labels
false-positive code that shouldn't lint, but does

Comments

@MichaelChirico
Copy link
Collaborator

MichaelChirico commented Jun 4, 2022

As seen in microsoft/LightGBM#5249

grepl(
  pattern = "[Ordinal/Name Pointer] Table"
  , x = objdump_results
  , fixed = TRUE
)
# <text>:2:14: warning: Use file.path() to construct portable file paths.
#   pattern = "[Ordinal/Name Pointer] Table"
#              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
@MichaelChirico MichaelChirico added the false-positive code that shouldn't lint, but does label Jun 4, 2022
@IndrajeetPatil
Copy link
Collaborator

A more minimal test case example:

lintr::lint(
  text = "grepl('[a/b] c', x, fixed = TRUE)",
  linters = lintr::nonportable_path_linter()
)
#> <text>:1:8: warning: [nonportable_path_linter] Use file.path() to construct portable file paths.
#> grepl('[a/b] c', x, fixed = TRUE)
#>        ^~~~~~~

Created on 2022-07-16 by the reprex package (v2.0.1)

@IndrajeetPatil
Copy link
Collaborator

Root cause of the problem, since this should return FALSE here:

lintr:::is_path("[a/b] c")
#> [1] TRUE

Created on 2022-07-16 by the reprex package (v2.0.1)

This regex needs to be modified 🙈

lintr:::path_regex
#> (?:(?:(?:^/(?![[:space:]/]))|(?:^~(?:[A-Za-z0-9_\-.])*(?:/)*(?![[:space:]'"]))|(?:^[[:alpha:]]:(?:[/\\])?(?![[:space:]/\\]))|(?:^\\\\(?:(?:[A-Za-z0-9_\-.])+(?:\\)?)?(?![[:space:]\\'"])))|(?:^(?!(?:['"]|(?:(?:^/(?![[:space:]/]))|(?:^~(?:[A-Za-z0-9_\-.])*(?:/)*(?![[:space:]'"]))|(?:^[[:alpha:]]:(?:[/\\])?(?![[:space:]/\\]))|(?:^\\\\(?:(?:[A-Za-z0-9_\-.])+(?:\\)?)?(?![[:space:]\\'"])))|(?:[[:alpha:]])+://)))(?:(?:(?:(?:(?:[[:alnum:]]|
#> |[!#$%&'()+,\-.;=@\[\]\^_`{}~]))+(?:/|\\))|(?:\.(?:\.)?$))(?!['"])))

Created on 2022-07-16 by the reprex package (v2.0.1)

@bahadzie
Copy link
Contributor

Hi. I've hit a similar false positive using grepl. Is this something I can help out with? I'm relatively new to R but I'm willing to give it a shot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
false-positive code that shouldn't lint, but does
Projects
None yet
Development

No branches or pull requests

3 participants