lintr icon indicating copy to clipboard operation
lintr copied to clipboard

False positive in nonportable_path_linter

Open MichaelChirico opened this issue 3 years ago • 3 comments

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"
#              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~

MichaelChirico avatar Jun 04 '22 02:06 MichaelChirico

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 avatar Jul 16 '22 15:07 IndrajeetPatil

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)

IndrajeetPatil avatar Jul 16 '22 15:07 IndrajeetPatil

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.

bahadzie avatar Feb 26 '24 14:02 bahadzie