Skip to content

Commit 2af8943

Browse files
Add option for suppressing styler communication
1 parent 3b94f31 commit 2af8943

File tree

4 files changed

+28
-16
lines changed

4 files changed

+28
-16
lines changed

R/addins.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,9 @@ get_addins_style_transformer <- function() {
153153

154154
communicate_addins_style_transformers <- function() {
155155
style_name <- get_addins_style_transformer_name()
156-
cat("Using style transformers `", style_name, "`\n", sep = "")
156+
if (getOption("styler.communicate", TRUE)) {
157+
cat("Using style transformers `", style_name, "`\n", sep = "")
158+
}
157159
}
158160

159161
#' Style a file as if it was an .R file

R/communicate.R

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
#' @inheritParams can_verify_roundtrip
88
#' @keywords internal
99
communicate_warning <- function(changed, transformers) {
10-
if (any(changed, na.rm = TRUE) && !can_verify_roundtrip(transformers)) {
10+
if (any(changed, na.rm = TRUE) &&
11+
!can_verify_roundtrip(transformers) &&
12+
getOption("styler.communicate", TRUE)
13+
) {
1114
cat("Please review the changes carefully!", fill = TRUE)
1215
}
1316
}
@@ -19,12 +22,14 @@ communicate_warning <- function(changed, transformers) {
1922
#' @param ruler_width Integer used to determine the width of the ruler.
2023
#' @keywords internal
2124
communicate_summary <- function(changed, ruler_width) {
22-
cli::cat_rule(width = max(40, ruler_width))
23-
cat("Status\tCount\tLegend \n")
24-
cli::cat_bullet("\t", sum(!changed, na.rm = TRUE), "\tFile unchanged.", bullet = "tick")
25-
cli::cat_bullet("\t", sum(changed, na.rm = TRUE), "\tFile changed.", bullet = "info")
26-
cli::cat_bullet(bullet = "cross", "\t", sum(is.na(changed)), "\tStyling threw an error.")
27-
cli::cat_rule(width = max(40, ruler_width))
25+
if (getOption("styler.communicate", TRUE)) {
26+
cli::cat_rule(width = max(40, ruler_width))
27+
cat("Status\tCount\tLegend \n")
28+
cli::cat_bullet("\t", sum(!changed, na.rm = TRUE), "\tFile unchanged.", bullet = "tick")
29+
cli::cat_bullet("\t", sum(changed, na.rm = TRUE), "\tFile changed.", bullet = "info")
30+
cli::cat_bullet(bullet = "cross", "\t", sum(is.na(changed)), "\tStyling threw an error.")
31+
cli::cat_rule(width = max(40, ruler_width))
32+
}
2833
}
2934

3035
#' @importFrom rlang abort

R/transform-files.R

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ transform_files <- function(files, transformers, include_roxygen_examples, dry)
1515
transformer <- make_transformer(transformers, include_roxygen_examples)
1616
max_char <- min(max(nchar(files), 0), getOption("width"))
1717
len_files <- length(files)
18-
if (len_files > 0L) {
18+
if (len_files > 0L && getOption("styler.communicate", TRUE)) {
1919
cat("Styling ", len_files, " files:\n")
2020
}
2121

@@ -51,16 +51,20 @@ transform_file <- function(path,
5151
max_char_after_message_path <- nchar(message_before) + max_char_path + 1
5252
n_spaces_before_message_after <-
5353
max_char_after_message_path - char_after_path
54-
cat(
55-
message_before, path,
56-
rep_char(" ", max(0L, n_spaces_before_message_after)),
57-
append = FALSE
58-
)
54+
if (getOption("styler.communicate", TRUE)) {
55+
cat(
56+
message_before, path,
57+
rep_char(" ", max(0L, n_spaces_before_message_after)),
58+
append = FALSE
59+
)
60+
}
5961
changed <- transform_code(path, fun = fun, ..., dry = dry)
6062

6163
bullet <- ifelse(is.na(changed), "warning", ifelse(changed, "info", "tick"))
6264

63-
cli::cat_bullet(bullet = bullet)
65+
if (getOption("styler.communicate", TRUE)) {
66+
cli::cat_bullet(bullet = bullet)
67+
}
6468
invisible(changed)
6569
}
6670

R/zzz.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
styler.cache_name = styler_version,
77
styler.addins_style_transformer = "styler::tidyverse_style()",
88
styler.ignore_start = "# styler: off",
9-
styler.ignore_stop = "# styler: on"
9+
styler.ignore_stop = "# styler: on",
10+
styler.communicate = TRUE
1011
)
1112
toset <- !(names(op.styler) %in% names(op))
1213
if (any(toset)) options(op.styler[toset])

0 commit comments

Comments
 (0)