Skip to content

Commit dcc71fc

Browse files
Merge pull request #174 from lorenzwalthert/issue-173
- style should fail if styling any file fails (#174).
2 parents 51e692e + f8d0061 commit dcc71fc

File tree

7 files changed

+17
-5
lines changed

7 files changed

+17
-5
lines changed

.pre-commit-config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ repos:
3434
.*\.sh|
3535
.*\.RData
3636
)$
37-
- id: lintr
3837
- id: readme-rmd-rendered
3938
- id: parsable-R
4039
- id: no-browser-statement

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Initial CRAN release. See https://lorenzwalthert.github.io/precommit/.
77
- Roxygen hook cache only includes files that are part of the index and
88
will hence be able to use the cache in cases it was previously invalidated
99
without need (#171).
10+
- styler hook should fail if styling any file fails (#174).
1011

1112

1213
# precommit v0.0.0.9048

inst/WORDLIST

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ cmd
1111
CMD
1212
codemeta
1313
conda
14+
conditionMessage
1415
config
1516
cp
1617
cran
@@ -26,6 +27,7 @@ docType
2627
emph
2728
env
2829
EOF
30+
eval
2931
exlucded
3032
fs
3133
getOption
@@ -114,6 +116,7 @@ Sys
114116
testthat
115117
tidyverse
116118
travis
119+
tryCatch
117120
ubuntu
118121
Uninstallation
119122
Upvote

inst/bin/style-files

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,14 @@ if (packageVersion("styler") < "1.3.2") {
2020
"`install.packages('styler')`. This will get you big speed-ups."
2121
)
2222
} else {
23-
styler::style_file(
24-
arguments$files,
25-
style = eval(parse(text = paste(arguments$style_pkg, "::", arguments$style_fun)))
23+
style <- eval(parse(text = paste(arguments$style_pkg, "::", arguments$style_fun)))
24+
tryCatch(
25+
{
26+
styler::style_file(
27+
arguments$files,
28+
style = style
29+
)
30+
},
31+
warning = function(w) stop(conditionMessage(w), call. = FALSE)
2632
)
2733
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1+ )

tests/testthat/test-all.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
# success
55
run_test("style-files", suffix = "-success.R")
66
# fail
7-
run_test("style-files", suffix = "-fail.R", error_msg = NA)
7+
run_test("style-files", suffix = "-fail-changed.R", error_msg = NA)
8+
9+
run_test("style-files", suffix = "-fail-parse.R", error_msg = "unexpected")
810

911
# success with cmd args
1012
run_test("style-files",

0 commit comments

Comments
 (0)