diff --git a/DESCRIPTION b/DESCRIPTION index a92a33b8f..90fd0aeb2 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -25,7 +25,6 @@ Depends: Imports: backports, codetools, - crayon, cyclocomp, digest, glue, @@ -37,6 +36,7 @@ Imports: xmlparsedata (>= 1.0.5) Suggests: bookdown, + crayon, httr (>= 1.2.1), jsonlite, mockery, diff --git a/R/methods.R b/R/methods.R index 32841ca93..1ba902eba 100644 --- a/R/methods.R +++ b/R/methods.R @@ -1,15 +1,21 @@ #' @export print.lint <- function(x, ...) { - color <- switch(x$type, - "warning" = crayon::magenta, - "error" = crayon::red, - "style" = crayon::blue, - crayon::bold - ) + if (requireNamespace("crayon", quietly = TRUE)) { + color <- switch(x$type, + warning = crayon::magenta, + error = crayon::red, + style = crayon::blue, + crayon::bold + ) + emph <- crayon::bold + } else { + color <- identity + emph <- identity + } cat( sep = "", - crayon::bold( + emph( x$filename, ":", as.character(x$line_number), ":", as.character(x$column_number), ": ", @@ -17,7 +23,7 @@ print.lint <- function(x, ...) { ), color(x$type, ": ", sep = ""), "[", x$linter, "] ", - crayon::bold(x$message), "\n", + emph(x$message), "\n", # swap tabs for spaces for #528 (sorry Richard Hendricks) chartr("\t", " ", x$line), "\n", highlight_string(x$message, x$column_number, x$ranges), diff --git a/tests/testthat/test-unused_import_linter.R b/tests/testthat/test-unused_import_linter.R index 4c396a3d2..444abe458 100644 --- a/tests/testthat/test-unused_import_linter.R +++ b/tests/testthat/test-unused_import_linter.R @@ -33,6 +33,7 @@ test_that("unused_import_linter lints as expected", { }) test_that("unused_import_linter handles message vectorization", { + skip_if_not_installed("crayon") expect_lint( trim_some(" library(crayon)