Skip to content

Commit

Permalink
Allow passing newline terminated strings directly to lint()
Browse files Browse the repository at this point in the history
  • Loading branch information
jimhester committed Oct 25, 2016
1 parent 11d6454 commit e275050
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions R/lint.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ NULL
#' @name lint_file
lint <- function(filename, linters = NULL, cache = FALSE, ..., parse_settings = TRUE) {

inline_data <- rex::re_matches(filename, rex::rex(newline))
if (inline_data) {
content <- filename
filename <- tempfile()
on.exit(unlink(filename))
cat(file = filename, content, sep = "\n")
}
source_expressions <- get_source_expressions(filename)

if (isTRUE(parse_settings)) {
read_settings(filename)
on.exit(clear_settings, add = TRUE)
Expand All @@ -36,8 +45,6 @@ lint <- function(filename, linters = NULL, cache = FALSE, ..., parse_settings =
names(linters) <- name
}

source_expressions <- get_source_expressions(filename)

lints <- list()
itr <- 0

Expand Down Expand Up @@ -92,7 +99,15 @@ lint <- function(filename, linters = NULL, cache = FALSE, ..., parse_settings =
save_cache(lint_cache, filename)
}

exclude(lints, ...)
res <- exclude(lints, ...)

# simplify filename if inline
if (inline_data) {
for (i in seq_along(res)) {
res[[i]][["filename"]] <- "<text>"
}
}
res
}

reorder_lints <- function(lints) {
Expand Down

0 comments on commit e275050

Please sign in to comment.