Skip to content

Commit 515d50b

Browse files
Merge pull request #885 from lorenzwalthert/issue-884
Better handling of emtpy string input
2 parents be6449c + 027c8a0 commit 515d50b

File tree

11 files changed

+33
-13
lines changed

11 files changed

+33
-13
lines changed

.pre-commit-config.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ default_stages: [commit]
44

55
repos:
66
- repo: https://github.com/lorenzwalthert/precommit
7-
rev: v0.1.3.9139
7+
rev: v0.2.2.9006
88
hooks:
99
- id: style-files
1010
args: [--style_pkg=styler, --style_fun=tidyverse_style]
@@ -52,7 +52,8 @@ repos:
5252
exclude: >
5353
(?x)^(
5454
tests/testthat/public-api/xyzaddin/addin_region-.*|
55-
tests/testmanual/addins/r-invalid\.R|
55+
tests/.*invalid.*|
56+
tests/testthat/rmd/no-tidy-out\.Rmd|
5657
tests/testthat/escaping/basic-escape-out\.R|
5758
tests/testthat/indention_operators/.*pipe.*|
5859
tests/testthat/line_breaks_and_other/.*pipe.*|
@@ -78,7 +79,7 @@ repos:
7879
tests/testthat/.*\.R(md)?
7980
)$
8081
- repo: https://github.com/pre-commit/pre-commit-hooks
81-
rev: v4.0.1
82+
rev: v4.1.0
8283
hooks:
8384
- id: check-added-large-files
8485
args: ['--maxkb=200']

NEWS.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,18 @@
3232

3333
* Piped function without brackets `substitute(x %>% y)` don't get `()` added
3434
anymore, as this can change outcome of the code (#876).
35+
* Add vignette on distributing style guide (#846, #861).
3536
* Alignment detection respects stylerignore (#850).
37+
* `Warning: Unknown or uninitialised column:` was fixed (#885).
3638
* Unaligned expressions with quoted key (e.g. `c("x" = 2)`) are now correctly
3739
detected (#881).
38-
* Add vignette on distributing style guide (#846, #861).
3940
* ensure a trailing blank line also if the input is cached (#867).
4041
* Preserve trailing blank line in roxygen examples to simplify concatenation of examples (#880).
4142
* Fix argument name `filetype` in Example for `style_dir()` (#855).
4243
* An error is now thrown on styling if input unicode characters can't be
4344
correctly parsed for Windows and R < 4.2 (#883).
4445

46+
4547
**Infrastructure**
4648

4749
* Remove dependency on {xfun} (#866).

R/roxygen-examples.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ style_roxygen_code_example_segment <- function(one_dont,
7070
base_indention) {
7171
if (length(one_dont) < 1L) {
7272
return(character())
73+
} else if (identical(one_dont, "\n")) {
74+
return(character(1L))
7375
}
7476
dont_seqs <- find_dont_seqs(one_dont)
7577
split_segments <- split_roxygen_segments(one_dont, unlist(dont_seqs))

R/transform-files.R

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -270,13 +270,17 @@ parse_transform_serialize_r <- function(text,
270270
#' @keywords internal
271271
#' @seealso specify_transformers_drop
272272
transformers_drop <- function(text, transformers) {
273-
is_colon <- text == ";"
274-
if (any(is_colon)) {
275-
# ; can only be parsed when on the same line as other token, not the case
276-
# here since text is output of compute_parse_data_nested.
277-
text <- c(text[!is_colon], "1;")
273+
if (length(text) > 0) {
274+
is_colon <- text == ";"
275+
if (any(is_colon)) {
276+
# ; can only be parsed when on the same line as other token, not the case
277+
# here since text is output of compute_parse_data_nested.
278+
text <- c(text[!is_colon], "1;")
279+
}
280+
token <- unique(tokenize(text)$token)
281+
} else {
282+
token <- character()
278283
}
279-
token <- unique(tokenize(text)$token)
280284
for (scope in c("line_break", "space", "token", "indention")) {
281285
rules <- transformers$transformers_drop[[scope]]
282286
for (rule in names(rules)) {
File renamed without changes.

tests/testthat/test-public_api.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,12 @@ test_that("styler can style Rmarkdown file", {
165165

166166
test_that("styler handles malformed Rmd file and invalid R code in chunk", {
167167
capture_output(expect_warning(
168-
style_file(testthat_file("public-api", "xyzfile_rmd", "random4.Rmd"), strict = FALSE),
168+
style_file(testthat_file("public-api", "xyzfile_rmd", "invalid4.Rmd"), strict = FALSE),
169169
"3: "
170170
))
171171

172172
capture_output(expect_warning(
173-
style_file(testthat_file("public-api", "xyzfile_rmd", "random7.Rmd"), strict = FALSE),
173+
style_file(testthat_file("public-api", "xyzfile_rmd", "invalid7.Rmd"), strict = FALSE),
174174
"Malformed file"
175175
))
176176
})

tests/testthat/test-rmd.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ test_that("can style .Rmd files", {
2222
write_tree = FALSE
2323
), NA)
2424

25-
expect_warning(test_collection("rmd", "no-tidy",
25+
expect_warning(test_collection("rmd", "invalid",
2626
transformer = transform_mixed,
2727
transformer_fun = style_text,
2828
filetype = "Rmd",

0 commit comments

Comments
 (0)