Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crayon is a Suggested dependency #1671

Merged
merged 2 commits into from
Oct 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ Depends:
Imports:
backports,
codetools,
crayon,
cyclocomp,
digest,
glue,
Expand All @@ -37,6 +36,7 @@ Imports:
xmlparsedata (>= 1.0.5)
Suggests:
bookdown,
crayon,
httr (>= 1.2.1),
jsonlite,
mockery,
Expand Down
22 changes: 14 additions & 8 deletions R/methods.R
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
#' @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), ": ",
sep = ""
),
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),
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-unused_import_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down