Skip to content

Commit

Permalink
Merge branch 'main' into use-raw-strings
Browse files Browse the repository at this point in the history
  • Loading branch information
IndrajeetPatil authored Nov 30, 2024
2 parents e053166 + 59c3d34 commit 42131a8
Show file tree
Hide file tree
Showing 33 changed files with 234 additions and 191 deletions.
42 changes: 0 additions & 42 deletions .github/workflows/check-all-examples.yaml

This file was deleted.

48 changes: 48 additions & 0 deletions .github/workflows/check-no-warnings.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# execute all examples and tests with warnings turned into errors to look for new warnings
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

name: check-no-warnings

jobs:
check-no-warnings:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
pak-version: devel
extra-packages: |
any::devtools
local::.
- name: Run examples
run: |
options(crayon.enabled = TRUE, warn = 2L)
devtools::run_examples(fresh = TRUE, run_dontrun = TRUE, run_donttest = TRUE)
shell: Rscript {0}

- name: Run Tests
run: |
options(crayon.enabled = TRUE)
pkgload::load_all()
# this workaround needed to play nicely with parallel testing
# see: https://github.com/r-lib/testthat/issues/1912
test_script_paths <- testthat::find_test_scripts("tests/testthat")
test_with_warning_as_error <- function(path) {
withr::local_options(list(warn = 2L))
testthat::test_file(path, stop_on_failure = TRUE, stop_on_warning = TRUE)
}
purrr::walk(test_script_paths, test_with_warning_as_error)
shell: Rscript {0}
2 changes: 1 addition & 1 deletion .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:

- name: Deploy to GitHub pages 🚀
if: github.event_name != 'pull_request'
uses: JamesIves/[email protected].1
uses: JamesIves/[email protected].9
with:
clean: false
branch: gh-pages
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pre-commit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5.1.0
uses: actions/setup-python@v5.3.0
with:
python-version: "3.9"
architecture: "x64"
Expand Down
5 changes: 2 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ repos:
)$
- id: roxygenize
additional_dependencies:
- r-lib/pkgapi
- dplyr
- roxygen2
- rlang
Expand Down Expand Up @@ -102,7 +101,7 @@ repos:
)$
- id: pkgdown
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v5.0.0
hooks:
- id: check-added-large-files
args: ["--maxkb=200"]
Expand All @@ -120,7 +119,7 @@ repos:
tests/testthat/_snaps/.*|
)$
- repo: https://github.com/lorenzwalthert/gitignore-tidy
rev: 517cddbf1d8514ddaf43159686617ae65895dc99
rev: 0.1.2
hooks:
- id: tidy-gitignore
- repo: local
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Roxygen: list(markdown = TRUE, roclets = c( "rd", "namespace", "collate",
if (rlang::is_installed("pkgapi")) "pkgapi::api_roclet" else {
warning("Please install r-lib/pkgapi to make sure the file API is kept
up to date"); NULL}))
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
Language: en-US
Config/testthat/edition: 3
Config/testthat/parallel: true
Expand Down
16 changes: 9 additions & 7 deletions R/rules-indention.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,38 @@ indent_braces <- function(pd, indent_by) {
#'
#' Necessary for consistent indention of the function declaration header.
#' @param pd A parse table.
#' @inheritParams is_double_indent_function_declaration
#' @inheritParams is_single_indent_function_declaration
#' @seealso set_unindention_child update_indention_ref_fun_dec
#' @keywords internal
unindent_fun_dec <- function(pd, indent_by = 2L) {
if (is_function_declaration(pd)) {
idx_closing_brace <- which(pd$token == "')'")
fun_dec_head <- seq2(2L, idx_closing_brace)
if (is_double_indent_function_declaration(pd, indent_by = indent_by)) {
pd$indent[fun_dec_head] <- 2L * indent_by
if (is_single_indent_function_declaration(pd, indent_by = indent_by)) {
pd$indent[fun_dec_head] <- indent_by
pd$indent[idx_closing_brace] <- 0L
} else {
pd$indent[fun_dec_head] <- 0L
}
}
pd
}

#' Is the function declaration double indented?
#' Is the function declaration single indented?
#'
#' Assumes you already checked if it's a function with
#' `is_function_declaration`. It is double indented if the first token
#' `is_function_declaration`. It is single indented if the first token
#' after the first line break that is a `"SYMBOL_FORMALS"`.
#' @param pd A parse table.
#' @inheritParams tidyverse_style
#' @keywords internal
is_double_indent_function_declaration <- function(pd, indent_by = 2L) {
is_single_indent_function_declaration <- function(pd, indent_by = 2L) {
head_pd <- vec_slice(pd, -nrow(pd))
line_break_in_header <- which(head_pd$lag_newlines > 0L & head_pd$token == "SYMBOL_FORMALS")
if (length(line_break_in_header) > 0L) {
# indent results from applying the rules, spaces is the initial spaces
# (which is indention if a newline is ahead)
# The 2L factor is kept to convert double indent to single indent
pd$spaces[line_break_in_header[1L] - 1L] <= 2L * indent_by
} else {
FALSE
Expand Down Expand Up @@ -132,7 +134,7 @@ NULL
#'
#' @keywords internal
update_indention_ref_fun_dec <- function(pd_nested) {
if (is_function_declaration(pd_nested) && !is_double_indent_function_declaration(pd_nested)) {
if (is_function_declaration(pd_nested) && !is_single_indent_function_declaration(pd_nested)) {
seq <- seq2(3L, nrow(pd_nested) - 2L)
pd_nested$indention_ref_pos_id[seq] <- pd_nested$pos_id[2L]
}
Expand Down
32 changes: 20 additions & 12 deletions R/rules-line-breaks.R
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,21 @@ set_line_break_around_comma_and_or <- function(pd, strict) {
}

style_line_break_around_curly <- function(strict, pd) {
if (is_curly_expr(pd) && nrow(pd) > 2L) {
closing_before <- pd$token == "'}'"
opening_before <- (pd$token == "'{'")
to_break <- lag(opening_before, default = FALSE) | closing_before
pd$lag_newlines[to_break] <- ifelse(
pd$token[to_break] == "COMMENT",
pmin(1L, pd$lag_newlines[to_break]),
if (strict) 1L else pmax(1L, pd$lag_newlines[to_break])
)
if (is_curly_expr(pd)) {
n_row <- nrow(pd)
if (n_row > 2L) {
closing_before <- pd$token == "'}'"
opening_before <- (pd$token == "'{'")
to_break <- lag(opening_before, default = FALSE) | closing_before
pd$lag_newlines[to_break] <- ifelse(
pd$token[to_break] == "COMMENT",
pmin(1L, pd$lag_newlines[to_break]),
if (strict) 1L else pmax(1L, pd$lag_newlines[to_break])
)
} else if (n_row == 2L) {
# pd represents {}
pd$lag_newlines[2L] <- 0L
}
} else {
is_else <- pd$token == "ELSE"
if (any(pd$token_before[is_else] == "'}'")) {
Expand Down Expand Up @@ -230,15 +236,17 @@ remove_line_break_before_round_closing_after_curly <- function(pd) {

remove_line_breaks_in_fun_dec <- function(pd) {
if (is_function_declaration(pd)) {
is_double_indention <- is_double_indent_function_declaration(pd)
is_single_indention <- is_single_indent_function_declaration(pd)
round_after <- (
pd$token == "')'" | pd$token_before == "'('"
) &
pd$token_before != "COMMENT"
pd$lag_newlines[pd$lag_newlines > 1L] <- 1L
pd$lag_newlines[round_after] <- 0L
if (is_double_indention) {
if (is_single_indention) {
pd$lag_newlines[lag(pd$token == "'('")] <- 1L
pd$lag_newlines[round_after] <- 1L
} else {
pd$lag_newlines[round_after] <- 0L
}
}
pd
Expand Down
7 changes: 6 additions & 1 deletion R/rules-spaces.R
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,9 @@ add_space_after_for_if_while <- function(pd_flat) {

#' @rdname set_line_break_around_curly_curly
#' @keywords internal
set_space_in_curly_curly <- function(pd) {
set_space_in_curly <- function(pd) {
if (is_curly_expr(pd)) {
# curly-curly
after_inner_opening <- pd$token == "'{'" & pd$token_before == "'{'"
before_inner_closing <- lead(pd$token == "'}'" & pd$token_after == "'}'")
is_curly_curly_inner <- any(after_inner_opening, na.rm = TRUE) &&
Expand All @@ -193,6 +194,10 @@ set_space_in_curly_curly <- function(pd) {
pd$spaces[after_outer_opening] <- 0L
pd$spaces[before_outer_closing] <- 0L
}

# empty curly
after_is_empty_curly <- lead(pd$token == "'}'" & pd$token_before == "'{'")
pd$spaces[after_is_empty_curly] <- 0L
}
pd
}
Expand Down
4 changes: 2 additions & 2 deletions R/style-guides.R
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ tidyverse_style <- function(scope = "tokens",
},
set_space_between_levels = set_space_between_levels,
set_space_between_eq_sub_and_comma = set_space_between_eq_sub_and_comma,
set_space_in_curly_curly = set_space_in_curly_curly
set_space_in_curly = set_space_in_curly
)
}

Expand Down Expand Up @@ -209,7 +209,7 @@ tidyverse_style <- function(scope = "tokens",
start_comments_with_space = "COMMENT",
remove_space_after_unary_pm_nested = c("'+'", "'-'"),
spacing_before_comments = "COMMENT",
set_space_in_curly_curly = c("'{'", "'}'")
set_space_in_curly = c("'{'", "'}'")
),
indention = list(
# indent_braces = c("'('", "'['", "'{'", "')'", "']'", "'}'"),
Expand Down
5 changes: 3 additions & 2 deletions R/transform-code.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,9 @@ identify_raw_chunks <- function(lines,

if (filetype == "Rmd") {
starts <- grep(
"^[\t >]*```+\\s*\\{([Rr]( *[ ,].*)?)\\}\\s*$", lines,
perl = TRUE
"^[\t >]*```+\\s*\\{((r|webr-r|webr)( *[ ,].*)?)\\}\\s*$",
lines,
perl = TRUE, ignore.case = TRUE
)
ends <- grep("^[\t >]*```+\\s*$", lines, perl = TRUE)
ends <- purrr::imap_int(starts, ~ ends[which(ends > .x)[1L]]) %>%
Expand Down
4 changes: 0 additions & 4 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ bootswatch
BugReports
bXj
cancelling
cff
ci
cli
CMD
Expand All @@ -29,15 +28,13 @@ counterpair
coventions
cpp
cre
ctb
cyclocomp
cynkra
dec
dependabot
desc
devtools
dir
docsearch
dont
dontrun
dontshow
Expand Down Expand Up @@ -102,7 +99,6 @@ linters
lintr
lorenz
lorenzwalthert
macOS
magrittr
mav
md
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/set_line_break_around_curly_curly.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions tests/testthat/fun_dec/line_break_fun_dec-out.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ a <- function(x,
}

a <- function(
#
x,
y) {
#
x,
y
) {
x - 1
}
3 changes: 1 addition & 2 deletions tests/testthat/indention_multiple/edge_strict_mixed-out.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,4 @@
)))


function(x, y, z) {
}
function(x, y, z) {}
Loading

0 comments on commit 42131a8

Please sign in to comment.