Skip to content

Commit

Permalink
Bugfix: Save cache in the requested directory (r-lib#213)
Browse files Browse the repository at this point in the history
  • Loading branch information
fangly committed Mar 8, 2017
1 parent d2924dd commit ece1e7d
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 13 deletions.
2 changes: 1 addition & 1 deletion R/cache.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' Clear the lintr cache
#'
#' @param file filename whose cache to clear. If you pass \code{NULL} it will
#' @param file filename whose cache to clear. If you pass \code{NULL}, it will
#' delete all of the caches.
#' @param path directory to store caches. Reads option 'lintr.cache_directory'
#' as the default.
Expand Down
2 changes: 1 addition & 1 deletion R/expect_lint.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#' \item named-vector check if the lint's field matches the named field.
#' \item list-vectors check if the given lint matches (use if more than one lint is returned for the content)
#' }
#' @param ... one or more linters to use for the check
#' @param ... arguments passed to \code{\link{lint}} including e.g. the linters or cache to use.
#' @param file if not \code{NULL} read content from a file rather than from \code{content}
expect_lint <- function(content, checks, ..., file = NULL) {

Expand Down
6 changes: 3 additions & 3 deletions R/lint.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ NULL
#' @param filename the given filename to lint.
#' @param linters a list of linter functions to apply see \code{\link{linters}}
#' for a full list of default and available linters.
#' @param cache toggle caching of lint results, if passed a character vector
#' uses that file as the cache.
#' @param cache given a logical, toggle caching of lint results. If passed a
#' character string, store the cache in this directory.
#' @param ... additional arguments passed to \code{\link{exclude}}.
#' @param parse_settings whether to try and parse the settings
#' @export
Expand Down Expand Up @@ -96,7 +96,7 @@ lint <- function(filename, linters = NULL, cache = FALSE, ..., parse_settings =

if (isTRUE(cache)) {
cache_file(lint_cache, filename, linters, lints)
save_cache(lint_cache, filename)
save_cache(lint_cache, filename, cache_dir)
}

res <- exclude(lints, ...)
Expand Down
3 changes: 1 addition & 2 deletions man/clear_cache.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/expect_lint.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions man/lint_file.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions tests/testthat/test-cache.R
Original file line number Diff line number Diff line change
Expand Up @@ -307,3 +307,15 @@ test_that("it returns the correct line if it is after the current line", {

expect_equal(find_new_line(3, "test3", t1), 3)
})


test_that("lint() uses the provided cache directory", {
dir <- "temp_lintr_cache"
unlink(dir, recursive = TRUE)
expect_false(dir.exists(dir))
expect_lint("a <- 1", NULL, assignment_linter, cache=dir) # create the cache
expect_true(dir.exists(dir))
expect_lint("a <- 1", NULL, assignment_linter, cache=dir) # read the cache
expect_true(dir.exists(dir))
unlink(dir, recursive = TRUE)
})

0 comments on commit ece1e7d

Please sign in to comment.