lintr icon indicating copy to clipboard operation
lintr copied to clipboard

`lint_dir` doesn't vectorize properly.

Open scottmmjackson opened this issue 3 years ago • 4 comments

I can't really provide a good reprex since it relies on having a specific filesystem constructed.

Note that there's no vectorization test: https://github.com/r-lib/lintr/blob/master/tests/testthat/test-dir_linters.R

Note below: <project-dir> has been clipped and redacted.

> lintr::lint_dir(c("R", "test/R"))
.........................
Error in .rs.normalizePath(marker$file, mustWork = TRUE) : 
  path[1]="/Users/<project-dir>/R//Users/<project-dir>/R/build_report.R": No such file or directory
In addition: Warning messages:
1: In while (!has_config(path, config)) { :
  the condition has length > 1 and only the first element will be used
2: In while (!has_config(path, config)) { :
  the condition has length > 1 and only the first element will be used

It looks like either lint_dir needs to be explicitly non-vectorized and stop() if given a char vector over length 1 in the path argument, or it needs to vectorize arguments and handle multiple directories.

scottmmjackson avatar Apr 25 '22 13:04 scottmmjackson

Thanks for reporting this. Using a vector input requires relative_path = FALSE. See also the implementation of lint_package(), which handles the relative path feature consistently.

AshesITR avatar Apr 25 '22 15:04 AshesITR

Reproduced on latest master as well as the 2.0.1 release from CRAN.

scottmmjackson avatar Apr 25 '22 16:04 scottmmjackson

@AshesITR thanks for that! I tried setting that and it did stop that bug from occurring.

However, upon adding that, the .lintr config is no longer getting picked up.

From the same working directory, unvectorized picks up the .lintr in cwd but vectorized ignores it and applies just the defaults.

scottmmjackson avatar Apr 25 '22 16:04 scottmmjackson

Is it a viable option to use lint_dir(".", exclude = list("other", "dirs", "in", ".", "or", "tests/not-R"))? The directory exclusion feature would allow you to exclude entire directories of other R sources.

AshesITR avatar May 22 '22 12:05 AshesITR