lintr
lintr copied to clipboard
False positive in nonportable_path_linter
As seen in https://github.com/microsoft/LightGBM/pull/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"
# ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
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)
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)
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.