Skip to content

Commit

Permalink
refactor in build_line_ref()
Browse files Browse the repository at this point in the history
  • Loading branch information
olivroy committed Aug 7, 2024
1 parent 7df28fa commit 9d190ec
Showing 1 changed file with 18 additions and 21 deletions.
39 changes: 18 additions & 21 deletions R/methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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, ...))
Expand Down

0 comments on commit 9d190ec

Please sign in to comment.