Skip to content

Commit

Permalink
Search for config files in any parent directories
Browse files Browse the repository at this point in the history
Rather than just looking for a package directory, this allows you to use
one .lintr configuration for all of your projects by placing it in a
common parent directory.

It should also fix discovery of lintr configuation in tests as well (I
believe)

Fixes #238
Fixes #345
  • Loading branch information
jimhester committed Sep 27, 2019
1 parent 103550b commit 1a7114b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# lintr 1.0.3.9000 #
* lintr now looks up its configuration in any parent directories as well as the package directory (#238, #345)
* `object_usage_linter()` has been changed to better detect lexical scoping of global variables (#27, #336, #91, #382)
* `object_usage_linter()` now respects `utils::globalVariables()`, so it can be used to avoid false positive warnings due to non-standard evaluation (#352)
* `seq_linter` is now one of the default linters (#316).
Expand Down
21 changes: 21 additions & 0 deletions R/lint.R
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,27 @@ find_package <- function(path = getwd()) {
normalizePath(prev_path)
}

is_root <- function(path) {
identical(path, dirname(path))
}

has_config <- function(path, config) {
file.exists(file.path(path, config))
}

find_config2 <- function(path) {
config <- basename(getOption("lintr.linter_file"))
path <- normalizePath(path, mustWork = FALSE)

while (!has_config(path, config)) {
path <- dirname(path)
if (is_root(path)) {
return(character())
}
}
return(file.path(path, config))
}

pkg_name <- function(path = find_package()) {
if (is.null(path)) {
return(NULL)
Expand Down
5 changes: 2 additions & 3 deletions R/settings.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,8 @@ find_config <- function(filename) {
return(linter_config)
}

## next check for a file in the project directory
project <- find_package(path)
linter_config <- file.path(project, linter_file)
## next check for a file higher directories
linter_config <- find_config2(path)
if (isTRUE(file.exists(linter_config))) {
return(linter_config)
}
Expand Down

0 comments on commit 1a7114b

Please sign in to comment.