-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into collapse-args
- Loading branch information
Showing
43 changed files
with
2,177 additions
and
1,803 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: format | ||
|
||
on: | ||
push: | ||
branches: [main, master] | ||
pull_request: | ||
branches: [main, master] | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.head_ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
ci: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Install `air` | ||
run: curl -LsSf https://github.com/posit-dev/air/releases/latest/download/air-installer.sh | sh | ||
- name: Check for changes | ||
run: air format . --check | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,62 @@ | ||
# Check that project is a package ------------------------- | ||
|
||
.check_is_package <- function(path) { | ||
if (!.dir_is_package(path)) { | ||
cli::cli_abort("{.code altdoc} only works in packages.") | ||
} | ||
if (!.dir_is_package(path)) { | ||
cli::cli_abort("{.code altdoc} only works in packages.") | ||
} | ||
} | ||
|
||
.check_dependency <- function(library_name) { | ||
requireNamespace(library_name, quietly = TRUE) | ||
requireNamespace(library_name, quietly = TRUE) | ||
} | ||
|
||
.assert_dependency <- function(library_name, install = FALSE) { | ||
flag <- .check_dependency(library_name) | ||
msg <- sprintf("This functionality requires the `%s` package.", library_name) | ||
if (!isTRUE(flag)) { | ||
if (isTRUE(install)) { | ||
msg <- sprintf("This functionality requires the `%s` package. Do you want to install it?", library_name) | ||
if (isTRUE(utils::askYesNo(msg, default = TRUE))) { | ||
utils::install.packages(library_name) | ||
return(invisible()) | ||
} | ||
flag <- .check_dependency(library_name) | ||
msg <- sprintf( | ||
"This functionality requires the `%s` package.", | ||
library_name | ||
) | ||
if (!isTRUE(flag)) { | ||
if (isTRUE(install)) { | ||
msg <- sprintf( | ||
"This functionality requires the `%s` package. Do you want to install it?", | ||
library_name | ||
) | ||
if (isTRUE(utils::askYesNo(msg, default = TRUE))) { | ||
utils::install.packages(library_name) | ||
return(invisible()) | ||
} | ||
} | ||
stop(msg, call. = FALSE) | ||
} | ||
stop(msg, call. = FALSE) | ||
} | ||
} | ||
|
||
|
||
# check if there is only 1 level-one structure | ||
.check_md_structure <- function(file_path) { | ||
if (!fs::file_exists(file_path)) { | ||
return(invisible()) | ||
} | ||
|
||
content <- .readlines(file_path) | ||
idx <- grep("^```", content) | ||
|
||
# backticks are incorrectly paired. We don't know what to do. | ||
if (length(idx) %% 2 != 0) { | ||
return(invisible()) | ||
} | ||
|
||
# drop code blocks | ||
backtick_pairs <- rev(split(idx, ceiling(seq_along(idx) / 2))) | ||
for (p in backtick_pairs) { | ||
content[p[1]:p[2]] <- NA | ||
} | ||
content <- stats::na.omit(content) | ||
|
||
# too many level 1 header | ||
if (isTRUE(sum(grepl("^# ", content)) > 1)) { | ||
bn <- basename(file_path) | ||
cli::cli_alert_danger("Too many level 1 headings in `{bn}`. {.code altdoc} assumes that the only level 1 heading is the title of the document. All other subheadings should be at least level 2, starting with: {.code ##}") | ||
} | ||
if (!fs::file_exists(file_path)) { | ||
return(invisible()) | ||
} | ||
|
||
content <- .readlines(file_path) | ||
idx <- grep("^```", content) | ||
|
||
# backticks are incorrectly paired. We don't know what to do. | ||
if (length(idx) %% 2 != 0) { | ||
return(invisible()) | ||
} | ||
|
||
# drop code blocks | ||
backtick_pairs <- rev(split(idx, ceiling(seq_along(idx) / 2))) | ||
for (p in backtick_pairs) { | ||
content[p[1]:p[2]] <- NA | ||
} | ||
content <- stats::na.omit(content) | ||
|
||
# too many level 1 header | ||
if (isTRUE(sum(grepl("^# ", content)) > 1)) { | ||
bn <- basename(file_path) | ||
cli::cli_alert_danger( | ||
"Too many level 1 headings in `{bn}`. {.code altdoc} assumes that the only level 1 heading is the title of the document. All other subheadings should be at least level 2, starting with: {.code ##}" | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.