diff --git a/R/extract.R b/R/extract.R index c9aa57b70..edd12a456 100644 --- a/R/extract.R +++ b/R/extract.R @@ -9,7 +9,7 @@ extract_r_source <- function(filename, lines, error = identity) { output <- rep.int(NA_character_, length(lines)) chunks <- tryCatch(get_chunk_positions(pattern = pattern, lines = lines), error = error) - if (inherits(chunks, "error") || inherits(chunks, "lint")) { + if (is_error(chunks) || is_lint(chunks)) { assign("e", chunks, envir = parent.frame()) # error, so return empty code return(output) diff --git a/R/get_source_expressions.R b/R/get_source_expressions.R index ec8a4d406..3f1817023 100644 --- a/R/get_source_expressions.R +++ b/R/get_source_expressions.R @@ -86,7 +86,7 @@ get_source_expressions <- function(filename, lines = NULL) { source_expression$content <- get_content(source_expression$lines) parsed_content <- get_source_expression(source_expression, error = function(e) lint_parse_error(e, source_expression)) - if (inherits(e, "lint") && (is.na(e$line) || !nzchar(e$line) || e$message == "unexpected end of input")) { + if (is_lint(e) && (is.na(e$line) || !nzchar(e$line) || e$message == "unexpected end of input")) { # Don't create expression list if it's unreliable (invalid encoding or unhandled parse error) expressions <- list() } else { @@ -502,7 +502,7 @@ get_source_expression <- function(source_expression, error = identity) { error = error ) - if (inherits(parsed_content, c("error", "lint"))) { + if (is_error(parsed_content) || is_lint(parsed_content)) { assign("e", parsed_content, envir = parent.frame()) parse_error <- TRUE } @@ -513,7 +513,7 @@ get_source_expression <- function(source_expression, error = identity) { error = error ) - if (inherits(parsed_content, c("error", "lint"))) { + if (is_error(parsed_content) || is_lint(parsed_content)) { # Let parse errors take precedence over encoding problems if (!parse_error) assign("e", parsed_content, envir = parent.frame()) return() # parsed_content is unreliable if encoding is invalid diff --git a/R/lint.R b/R/lint.R index 042fbeaca..1961acb05 100644 --- a/R/lint.R +++ b/R/lint.R @@ -696,7 +696,7 @@ maybe_report_progress <- function(pb) { } maybe_append_error_lint <- function(lints, error, lint_cache, filename) { - if (inherits(error, "lint")) { + if (is_lint(error)) { error$linter <- "error" lints[[length(lints) + 1L]] <- error diff --git a/R/utils.R b/R/utils.R index d23fc8902..acdf2c521 100644 --- a/R/utils.R +++ b/R/utils.R @@ -245,9 +245,12 @@ get_r_string <- function(s, xpath = NULL) { } is_linter <- function(x) inherits(x, "linter") +is_lint <- function(x) inherits(x, "lint") + +is_error <- function(x) inherits(x, "error") is_tainted <- function(lines) { - inherits(tryCatch(nchar(lines), error = identity), "error") + is_error(tryCatch(nchar(lines), error = identity)) } #' Check that the entries in ... are valid