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

Skip basename() call when finding configs #2514

Merged
merged 6 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion R/settings_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
16 changes: 16 additions & 0 deletions tests/testthat/test-settings.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Loading