-
Notifications
You must be signed in to change notification settings - Fork 72
Open
Description
Hi stylers
Thank you for a very useful package. I think I have found 1 or perhaps 2 bugs:
- It appears that
style_text()
ignores custom style unless cache is disabled. - It appears that
style_file()
w/o cache has unintended side effects such that it can only work once with a custom style. To work again the session must be restarted
# Prepare transformers
rpolars_style = function() {
# derive from tidyverse
transformers = styler::tidyverse_style()
# reverse tranformer to make <- into =
transformers$token$force_assignment_op = function (pd) {
to_replace = pd$token == "LEFT_ASSIGN"
pd$token[to_replace] = "EQ_ASSIGN"
pd$text[to_replace] = "="
pd
}
transformers
}
# CACHE does not take into account transformers
styler::style_text("foo <- 42; bar = TRUE", transformers = rpolars_style()) # good
#> foo = 42
#> bar = TRUE
styler::style_text("foo <- 42; bar = TRUE", transformers = styler::tidyverse_style()) # bad
#> foo <- 42
#> bar = TRUE
styler::style_text("foo <- 42; bar = TRUE", transformers = rpolars_style()) # bad
#> foo <- 42
#> bar = TRUE
styler::cache_clear(ask = FALSE)
styler::cache_deactivate()
#> Deactivated cache.
styler::style_text("foo <- 42; bar = TRUE", transformers = rpolars_style()) # good
#> foo = 42
#> bar = TRUE
styler::style_text("foo <- 42; bar = TRUE", transformers = styler::tidyverse_style()) # good
#> foo <- 42
#> bar <- TRUE
styler::style_text("foo <- 42; bar = TRUE", transformers = rpolars_style()) # good
#> foo = 42
#> bar = TRUE
writeLines("foo <- 42; bar = TRUE", "deleteme.R")
readLines("deleteme.R")
#> [1] "foo <- 42; bar = TRUE"
styler::style_file("deleteme.R", transformers = rpolars_style()) # good
#> Styling 1 files:
#> deleteme.R ℹ
#> ────────────────────────────────────────
#> Status Count Legend
#> ✔ 0 File unchanged.
#> ℹ 1 File changed.
#> ✖ 0 Styling threw an error.
#> ────────────────────────────────────────
#> Please review the changes carefully!
readLines("deleteme.R")
#> [1] "foo = 42" "bar = TRUE"
styler::style_file("deleteme.R", transformers = styler::tidyverse_style()) # good
#> Styling 1 files:
#> deleteme.R ℹ
#> ────────────────────────────────────────
#> Status Count Legend
#> ✔ 0 File unchanged.
#> ℹ 1 File changed.
#> ✖ 0 Styling threw an error.
#> ────────────────────────────────────────
#> Please review the changes carefully!
readLines("deleteme.R")
#> [1] "foo <- 42" "bar <- TRUE"
styler::style_file("deleteme.R", transformers = rpolars_style()) # bad
#> Styling 1 files:
#> deleteme.R ✔
#> ────────────────────────────────────────
#> Status Count Legend
#> ✔ 1 File unchanged.
#> ℹ 0 File changed.
#> ✖ 0 Styling threw an error.
#> ────────────────────────────────────────
readLines("deleteme.R")
#> [1] "foo <- 42" "bar <- TRUE"
styler::cache_clear(ask = FALSE)
styler::cache_deactivate()
#> Deactivated cache.
styler::style_file("deleteme.R", transformers = rpolars_style()) # bad
#> Styling 1 files:
#> deleteme.R ✔
#> ────────────────────────────────────────
#> Status Count Legend
#> ✔ 1 File unchanged.
#> ℹ 0 File changed.
#> ✖ 0 Styling threw an error.
#> ────────────────────────────────────────
readLines("deleteme.R")
#> [1] "foo <- 42" "bar <- TRUE"
Created on 2023-12-11 with reprex v2.0.2
Metadata
Metadata
Assignees
Labels
No labels