Skip to content

Commit 3f34715

Browse files
Merge branch 'main' into strict-examples
2 parents 27a07d5 + fa9d9f4 commit 3f34715

30 files changed

+186
-145
lines changed

.github/workflows/pkgdown.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939

4040
- name: Deploy to GitHub pages 🚀
4141
if: github.event_name != 'pull_request'
42-
uses: JamesIves/[email protected].1
42+
uses: JamesIves/[email protected].9
4343
with:
4444
clean: false
4545
branch: gh-pages

.github/workflows/pre-commit.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
with:
2626
fetch-depth: 0
2727
- name: Set up Python
28-
uses: actions/setup-python@v5.1.0
28+
uses: actions/setup-python@v5.3.0
2929
with:
3030
python-version: "3.9"
3131
architecture: "x64"

.pre-commit-config.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ repos:
3434
)$
3535
- id: roxygenize
3636
additional_dependencies:
37-
- r-lib/pkgapi
3837
- dplyr
3938
- roxygen2
4039
- rlang
@@ -102,7 +101,7 @@ repos:
102101
)$
103102
- id: pkgdown
104103
- repo: https://github.com/pre-commit/pre-commit-hooks
105-
rev: v4.6.0
104+
rev: v5.0.0
106105
hooks:
107106
- id: check-added-large-files
108107
args: ["--maxkb=200"]
@@ -120,7 +119,7 @@ repos:
120119
tests/testthat/_snaps/.*|
121120
)$
122121
- repo: https://github.com/lorenzwalthert/gitignore-tidy
123-
rev: 517cddbf1d8514ddaf43159686617ae65895dc99
122+
rev: 0.1.2
124123
hooks:
125124
- id: tidy-gitignore
126125
- repo: local

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Roxygen: list(markdown = TRUE, roclets = c( "rd", "namespace", "collate",
5252
if (rlang::is_installed("pkgapi")) "pkgapi::api_roclet" else {
5353
warning("Please install r-lib/pkgapi to make sure the file API is kept
5454
up to date"); NULL}))
55-
RoxygenNote: 7.3.1
55+
RoxygenNote: 7.3.2
5656
Language: en-US
5757
Config/testthat/edition: 3
5858
Config/testthat/parallel: true

R/rules-indention.R

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,36 +15,38 @@ indent_braces <- function(pd, indent_by) {
1515
#'
1616
#' Necessary for consistent indention of the function declaration header.
1717
#' @param pd A parse table.
18-
#' @inheritParams is_double_indent_function_declaration
18+
#' @inheritParams is_single_indent_function_declaration
1919
#' @seealso set_unindention_child update_indention_ref_fun_dec
2020
#' @keywords internal
2121
unindent_fun_dec <- function(pd, indent_by = 2L) {
2222
if (is_function_declaration(pd)) {
2323
idx_closing_brace <- which(pd$token == "')'")
2424
fun_dec_head <- seq2(2L, idx_closing_brace)
25-
if (is_double_indent_function_declaration(pd, indent_by = indent_by)) {
26-
pd$indent[fun_dec_head] <- 2L * indent_by
25+
if (is_single_indent_function_declaration(pd, indent_by = indent_by)) {
26+
pd$indent[fun_dec_head] <- indent_by
27+
pd$indent[idx_closing_brace] <- 0L
2728
} else {
2829
pd$indent[fun_dec_head] <- 0L
2930
}
3031
}
3132
pd
3233
}
3334

34-
#' Is the function declaration double indented?
35+
#' Is the function declaration single indented?
3536
#'
3637
#' Assumes you already checked if it's a function with
37-
#' `is_function_declaration`. It is double indented if the first token
38+
#' `is_function_declaration`. It is single indented if the first token
3839
#' after the first line break that is a `"SYMBOL_FORMALS"`.
3940
#' @param pd A parse table.
4041
#' @inheritParams tidyverse_style
4142
#' @keywords internal
42-
is_double_indent_function_declaration <- function(pd, indent_by = 2L) {
43+
is_single_indent_function_declaration <- function(pd, indent_by = 2L) {
4344
head_pd <- vec_slice(pd, -nrow(pd))
4445
line_break_in_header <- which(head_pd$lag_newlines > 0L & head_pd$token == "SYMBOL_FORMALS")
4546
if (length(line_break_in_header) > 0L) {
4647
# indent results from applying the rules, spaces is the initial spaces
4748
# (which is indention if a newline is ahead)
49+
# The 2L factor is kept to convert double indent to single indent
4850
pd$spaces[line_break_in_header[1L] - 1L] <= 2L * indent_by
4951
} else {
5052
FALSE
@@ -132,7 +134,7 @@ NULL
132134
#'
133135
#' @keywords internal
134136
update_indention_ref_fun_dec <- function(pd_nested) {
135-
if (is_function_declaration(pd_nested) && !is_double_indent_function_declaration(pd_nested)) {
137+
if (is_function_declaration(pd_nested) && !is_single_indent_function_declaration(pd_nested)) {
136138
seq <- seq2(3L, nrow(pd_nested) - 2L)
137139
pd_nested$indention_ref_pos_id[seq] <- pd_nested$pos_id[2L]
138140
}

R/rules-line-breaks.R

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -149,15 +149,21 @@ set_line_break_around_comma_and_or <- function(pd, strict) {
149149
}
150150

151151
style_line_break_around_curly <- function(strict, pd) {
152-
if (is_curly_expr(pd) && nrow(pd) > 2L) {
153-
closing_before <- pd$token == "'}'"
154-
opening_before <- (pd$token == "'{'")
155-
to_break <- lag(opening_before, default = FALSE) | closing_before
156-
pd$lag_newlines[to_break] <- ifelse(
157-
pd$token[to_break] == "COMMENT",
158-
pmin(1L, pd$lag_newlines[to_break]),
159-
if (strict) 1L else pmax(1L, pd$lag_newlines[to_break])
160-
)
152+
if (is_curly_expr(pd)) {
153+
n_row <- nrow(pd)
154+
if (n_row > 2L) {
155+
closing_before <- pd$token == "'}'"
156+
opening_before <- (pd$token == "'{'")
157+
to_break <- lag(opening_before, default = FALSE) | closing_before
158+
pd$lag_newlines[to_break] <- ifelse(
159+
pd$token[to_break] == "COMMENT",
160+
pmin(1L, pd$lag_newlines[to_break]),
161+
if (strict) 1L else pmax(1L, pd$lag_newlines[to_break])
162+
)
163+
} else if (n_row == 2L) {
164+
# pd represents {}
165+
pd$lag_newlines[2L] <- 0L
166+
}
161167
} else {
162168
is_else <- pd$token == "ELSE"
163169
if (any(pd$token_before[is_else] == "'}'")) {
@@ -230,15 +236,17 @@ remove_line_break_before_round_closing_after_curly <- function(pd) {
230236

231237
remove_line_breaks_in_fun_dec <- function(pd) {
232238
if (is_function_declaration(pd)) {
233-
is_double_indention <- is_double_indent_function_declaration(pd)
239+
is_single_indention <- is_single_indent_function_declaration(pd)
234240
round_after <- (
235241
pd$token == "')'" | pd$token_before == "'('"
236242
) &
237243
pd$token_before != "COMMENT"
238244
pd$lag_newlines[pd$lag_newlines > 1L] <- 1L
239-
pd$lag_newlines[round_after] <- 0L
240-
if (is_double_indention) {
245+
if (is_single_indention) {
241246
pd$lag_newlines[lag(pd$token == "'('")] <- 1L
247+
pd$lag_newlines[round_after] <- 1L
248+
} else {
249+
pd$lag_newlines[round_after] <- 0L
242250
}
243251
}
244252
pd

R/rules-spaces.R

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,9 @@ add_space_after_for_if_while <- function(pd_flat) {
174174

175175
#' @rdname set_line_break_around_curly_curly
176176
#' @keywords internal
177-
set_space_in_curly_curly <- function(pd) {
177+
set_space_in_curly <- function(pd) {
178178
if (is_curly_expr(pd)) {
179+
# curly-curly
179180
after_inner_opening <- pd$token == "'{'" & pd$token_before == "'{'"
180181
before_inner_closing <- lead(pd$token == "'}'" & pd$token_after == "'}'")
181182
is_curly_curly_inner <- any(after_inner_opening, na.rm = TRUE) &&
@@ -193,6 +194,10 @@ set_space_in_curly_curly <- function(pd) {
193194
pd$spaces[after_outer_opening] <- 0L
194195
pd$spaces[before_outer_closing] <- 0L
195196
}
197+
198+
# empty curly
199+
after_is_empty_curly <- lead(pd$token == "'}'" & pd$token_before == "'{'")
200+
pd$spaces[after_is_empty_curly] <- 0L
196201
}
197202
pd
198203
}

R/style-guides.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ tidyverse_style <- function(scope = "tokens",
122122
},
123123
set_space_between_levels = set_space_between_levels,
124124
set_space_between_eq_sub_and_comma = set_space_between_eq_sub_and_comma,
125-
set_space_in_curly_curly = set_space_in_curly_curly
125+
set_space_in_curly = set_space_in_curly
126126
)
127127
}
128128

@@ -209,7 +209,7 @@ tidyverse_style <- function(scope = "tokens",
209209
start_comments_with_space = "COMMENT",
210210
remove_space_after_unary_pm_nested = c("'+'", "'-'"),
211211
spacing_before_comments = "COMMENT",
212-
set_space_in_curly_curly = c("'{'", "'}'")
212+
set_space_in_curly = c("'{'", "'}'")
213213
),
214214
indention = list(
215215
# indent_braces = c("'('", "'['", "'{'", "')'", "']'", "'}'"),

R/transform-code.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,9 @@ identify_raw_chunks <- function(lines,
100100

101101
if (filetype == "Rmd") {
102102
starts <- grep(
103-
"^[\t >]*```+\\s*\\{([Rr]( *[ ,].*)?)\\}\\s*$", lines,
104-
perl = TRUE
103+
"^[\t >]*```+\\s*\\{((r|webr-r|webr)( *[ ,].*)?)\\}\\s*$",
104+
lines,
105+
perl = TRUE, ignore.case = TRUE
105106
)
106107
ends <- grep("^[\t >]*```+\\s*$", lines, perl = TRUE)
107108
ends <- purrr::imap_int(starts, ~ ends[which(ends > .x)[1L]]) %>%

man/is_double_indent_function_declaration.Rd renamed to man/is_single_indent_function_declaration.Rd

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)