Skip to content

Commit c4aaccc

Browse files
make styler-perm the default
1 parent 54c593b commit c4aaccc

File tree

4 files changed

+49
-14
lines changed

4 files changed

+49
-14
lines changed

inst/hooks/exported/style-files.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ library(styler)
2525
args <- commandArgs(trailingOnly = TRUE)
2626
non_file_args <- args[!grepl("^[^-][^-]", args)]
2727
keys <- setdiff(
28-
gsub("(^--[0-9A-Za-z_]+).*", "\\1", non_file_args),
29-
c("--style_pkg", "--style_fun", "--no-warn-cache", "--cache-root")
28+
gsub("(^--[0-9A-Za-z_-]+).*", "\\1", non_file_args),
29+
c("--style_pkg", "--style_fun", "--cache-root", "--no-warn-cache")
3030
)
3131
if (length(keys) > 0) {
3232
bare_keys <- gsub("^--", "", keys)

tests/testthat/test-hooks.R

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,34 @@ run_test("use-tidy-description", "DESCRIPTION", suffix = "")
88
### style-files ####
99

1010
# success
11-
run_test("style-files", suffix = "-success.R")
11+
run_test("style-files",
12+
suffix = "-success.R", cmd_args = c('--cache-root=styler')
13+
)
1214
# fail
13-
run_test("style-files", suffix = "-fail-changed.R", error_msg = NA)
15+
run_test("style-files",
16+
suffix = "-fail-changed.R", cmd_args = c('--cache-root=styler'),
17+
error_msg = NA)
1418

15-
run_test("style-files", suffix = "-fail-parse.R", error_msg = "unexpected")
19+
run_test("style-files", suffix = "-fail-parse.R", cmd_args = c('--cache-root=styler'),
20+
error_msg = "unexpected")
1621

1722
# success with cmd args
1823
run_test("style-files",
1924
file_name = "style-files-cmd",
2025
suffix = "-success.R",
21-
cmd_args = c("--style_pkg=styler", "--style_fun=tidyverse_style")
26+
cmd_args = c("--style_pkg=styler", "--style_fun=tidyverse_style", '--cache-root=styler')
2227
)
2328

2429
run_test("style-files",
2530
file_name = "style-files-cmd",
2631
suffix = "-success.R",
27-
cmd_args = c("--scope=spaces")
32+
cmd_args = c("--scope=spaces", '--cache-root=styler')
2833
)
2934

3035
run_test("style-files",
3136
file_name = "style-files-cmd",
3237
suffix = "-success.R",
33-
cmd_args = c('--scope="I(\'spaces\')"')
38+
cmd_args = c('--scope="I(\'spaces\')"', '--cache-root=styler')
3439
)
3540

3641
run_test("style-files",
@@ -39,7 +44,8 @@ run_test("style-files",
3944
cmd_args = c(
4045
'--scope="I(\'spaces\')"',
4146
"--base_indention=0",
42-
"--include_roxygen_examples=TRUE"
47+
"--include_roxygen_examples=TRUE",
48+
'--cache-root=styler'
4349
)
4450
)
4551

@@ -50,35 +56,38 @@ run_test("style-files",
5056
'--scope="I(\'spaces\')"',
5157
"--base_indention=0",
5258
"--include_roxygen_examples=TRUE",
53-
'--reindention="specify_reindention(\'#\')"'
59+
'--reindention="specify_reindention(\'#\')"',
60+
'--cache-root=styler'
5461
)
5562
)
5663

5764
run_test("style-files",
5865
file_name = "style-files",
5966
suffix = "-base-indention-success.R",
60-
cmd_args = c("--base_indention=4")
67+
cmd_args = c("--base_indention=4", '--cache-root=styler')
6168
)
6269

6370
run_test("style-files",
6471
file_name = "style-files",
6572
suffix = "-roxygen-success.R",
66-
cmd_args = c("--include_roxygen_examples=FALSE")
73+
cmd_args = c("--include_roxygen_examples=FALSE", '--cache-root=styler')
6774
)
6875

6976
# fail with cmd args
7077
run_test("style-files",
7178
file_name = "style-files-cmd",
7279
suffix = "-success.R",
7380
error_msg = "scope must be one",
74-
cmd_args = c("--scope=space")
81+
cmd_args = c("--scope=space", '--cache-root=styler')
7582
)
7683

7784
run_test("style-files",
7885
file_name = "style-files-cmd",
7986
suffix = "-fail.R",
8087
error_msg = NA,
81-
cmd_args = c("--style_pkg=styler", "--style_fun=tidyverse_style")
88+
cmd_args = c(
89+
"--style_pkg=styler", "--style_fun=tidyverse_style", '--cache-root=styler'
90+
)
8291
)
8392

8493
### . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ..

tests/testthat/test-zzz.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
test_that("tests don't write to styler-perm", {
2+
skip_on_cran()
3+
expect_false(fs::file_exists(
4+
fs::path(R.cache::getCacheRootPath(), "styler-perm")
5+
)
6+
)
7+
})

vignettes/available-hooks.Rmd

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,25 @@ In addition, the hook takes the following arguments that are not passed to
8686
* If no permanent `{R.cache}` cache exists, the hook emits a warning which you
8787
can silence with `--no-warn-cache`.
8888

89+
```
90+
id: style-files
91+
args: [--no-warn-cache]
92+
```
93+
94+
95+
* Argument `cache_root` is passed to `options()` to set `"styler.cache_root"`.
96+
Default value: `"styler-perm"`. The argument
97+
determines the sub-directory under the {R.cache} cache directory that {styler}
98+
uses. If you want {styler} to auto-clean up caches older than 6 days, set this
99+
to `styler`. For more information, see
100+
`help("caching", package = "styler")`.
101+
102+
```
103+
id: style-files
104+
args: [--cache-root=styler]
105+
```
106+
107+
89108
This hook modifies files unless you specify `--dry=fail` (requires
90109
`{styler} > 1.3.2`).
91110

0 commit comments

Comments
 (0)