Skip to content

Commit 9d58027

Browse files
Add utils to check for lint and error classes (#2681)
1 parent ed2473f commit 9d58027

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

R/extract.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ extract_r_source <- function(filename, lines, error = identity) {
99
output <- rep.int(NA_character_, length(lines))
1010

1111
chunks <- tryCatch(get_chunk_positions(pattern = pattern, lines = lines), error = error)
12-
if (inherits(chunks, "error") || inherits(chunks, "lint")) {
12+
if (is_error(chunks) || is_lint(chunks)) {
1313
assign("e", chunks, envir = parent.frame())
1414
# error, so return empty code
1515
return(output)

R/get_source_expressions.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ get_source_expressions <- function(filename, lines = NULL) {
8686
source_expression$content <- get_content(source_expression$lines)
8787
parsed_content <- get_source_expression(source_expression, error = function(e) lint_parse_error(e, source_expression))
8888

89-
if (inherits(e, "lint") && (is.na(e$line) || !nzchar(e$line) || e$message == "unexpected end of input")) {
89+
if (is_lint(e) && (is.na(e$line) || !nzchar(e$line) || e$message == "unexpected end of input")) {
9090
# Don't create expression list if it's unreliable (invalid encoding or unhandled parse error)
9191
expressions <- list()
9292
} else {
@@ -502,7 +502,7 @@ get_source_expression <- function(source_expression, error = identity) {
502502
error = error
503503
)
504504

505-
if (inherits(parsed_content, c("error", "lint"))) {
505+
if (is_error(parsed_content) || is_lint(parsed_content)) {
506506
assign("e", parsed_content, envir = parent.frame())
507507
parse_error <- TRUE
508508
}
@@ -513,7 +513,7 @@ get_source_expression <- function(source_expression, error = identity) {
513513
error = error
514514
)
515515

516-
if (inherits(parsed_content, c("error", "lint"))) {
516+
if (is_error(parsed_content) || is_lint(parsed_content)) {
517517
# Let parse errors take precedence over encoding problems
518518
if (!parse_error) assign("e", parsed_content, envir = parent.frame())
519519
return() # parsed_content is unreliable if encoding is invalid

R/lint.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ maybe_report_progress <- function(pb) {
696696
}
697697

698698
maybe_append_error_lint <- function(lints, error, lint_cache, filename) {
699-
if (inherits(error, "lint")) {
699+
if (is_lint(error)) {
700700
error$linter <- "error"
701701
lints[[length(lints) + 1L]] <- error
702702

R/utils.R

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,12 @@ get_r_string <- function(s, xpath = NULL) {
245245
}
246246

247247
is_linter <- function(x) inherits(x, "linter")
248+
is_lint <- function(x) inherits(x, "lint")
249+
250+
is_error <- function(x) inherits(x, "error")
248251

249252
is_tainted <- function(lines) {
250-
inherits(tryCatch(nchar(lines), error = identity), "error")
253+
is_error(tryCatch(nchar(lines), error = identity))
251254
}
252255

253256
#' Check that the entries in ... are valid

0 commit comments

Comments
 (0)