From 9d190eca9369d5865046874abd09f9b2b69a0119 Mon Sep 17 00:00:00 2001 From: olivroy Date: Wed, 7 Aug 2024 09:04:53 -0400 Subject: [PATCH] refactor in `build_line_ref()` --- R/methods.R | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/R/methods.R b/R/methods.R index e6bf8ed64..0f42b185a 100644 --- a/R/methods.R +++ b/R/methods.R @@ -8,28 +8,9 @@ format.lint <- function(x, ..., width = getOption("lintr.format_width")) { ) emph <- cli::style_bold - has_hyperlink_support <- cli::ansi_has_hyperlink_support() - if (has_hyperlink_support) { - fmt_start <- "{.path " - fmt_end <- "}" - fmt_f <- cli::format_inline - } else { - fmt_start <- "" - fmt_end <- "" - fmt_f <- paste0 - } - + line_ref <- build_line_ref(x) annotated_msg <- paste0( - emph( - fmt_f( - fmt_start, - x$filename, ":", - as.character(x$line_number), ":", - as.character(x$column_number), - fmt_end - ), - ": " - ), + emph(line_ref, ": "), color(x$type, ": ", sep = ""), "[", x$linter, "] ", emph(x$message) @@ -48,6 +29,22 @@ format.lint <- function(x, ..., width = getOption("lintr.format_width")) { ) } +build_line_ref <- function(x) { + line_ref <- paste0( + x$filename, ":", + as.character(x$line_number), ":", + as.character(x$column_number) + ) + + create_clickable_link <- cli::ansi_has_hyperlink_support() + if (create_clickable_link) { + line_ref <- paste0("{.path ", line_ref, "}") + line_ref <- cli::format_inline(line_ref) + } + + line_ref +} + #' @export print.lint <- function(x, ...) { cat(format(x, ...))