diff --git a/NEWS.md b/NEWS.md index 201df2826..9aed3f804 100644 --- a/NEWS.md +++ b/NEWS.md @@ -20,6 +20,7 @@ * `object_name_linter()` no longer errors when user-supplied `regexes=` have capture groups (#2188, @MichaelChirico). * `.lintr` config validation correctly accepts regular expressions which only compile under `perl = TRUE` (#2375, @MichaelChirico). These have always been valid (since `rex::re_matches()`, which powers the lint exclusion logic, also uses this setting), but the new up-front validation in v3.1.1 incorrectly used `perl = FALSE`. +* `.lintr` configs set by option `lintr.linter_file` or environment variable `R_LINTR_LINTER_FILE` can point to subdirectories (#2512, @MichaelChirico). ## Changes to default linters diff --git a/R/settings_utils.R b/R/settings_utils.R index a04ef5b55..9489ea24e 100644 --- a/R/settings_utils.R +++ b/R/settings_utils.R @@ -75,7 +75,7 @@ find_config <- function(filename) { # may exist in subsequent directories are ignored file_locations <- c( # Local (incl. parent) directories - find_local_config(path, basename(linter_file)), + find_local_config(path, linter_file), # User directory # cf: rstudio@bc9b6a5 SessionRSConnect.R#L32 file.path(Sys.getenv("HOME", unset = "~"), linter_file), diff --git a/tests/testthat/test-settings.R b/tests/testthat/test-settings.R index f9350c6a0..ffd166b25 100644 --- a/tests/testthat/test-settings.R +++ b/tests/testthat/test-settings.R @@ -282,3 +282,19 @@ test_that("perl-only regular expressions are accepted in config", { writeLines("a <- 1", "aaa.R") expect_silent(lint("aaa.R")) }) + +test_that("settings can be put in a sub-directory", { + withr::local_dir(withr::local_tempdir()) + + dir.create(".settings") + .lintr <- ".settings/.lintr.R" + writeLines("linters <- list(line_length_linter(10))", .lintr) + + dir.create("R") + writeLines("abcdefghijklmnopqrstuvwxyz=1", "R/a.R") + + writeLines(c("Package: foo", "Version: 0.1"), "DESCRIPTION") + + withr::local_options(lintr.linter_file = .lintr) + expect_length(lint_package(), 1L) +})