Skip to content

Commit

Permalink
Merge branch 'main' into xml-utils
Browse files Browse the repository at this point in the history
  • Loading branch information
IndrajeetPatil authored Apr 14, 2024
2 parents db59e3a + d86738f commit 569f353
Show file tree
Hide file tree
Showing 362 changed files with 13,051 additions and 3,893 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
^\.Rproj\.user$
^\.idea$
^\.dev$
^\.devcontainer$
^\.lintr$
^\.lintr_new$
^wercker\.yml$
Expand Down
54 changes: 54 additions & 0 deletions .dev/lint_metadata_test.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# This script is designed to find linters that lack metadata tests.
# To do so, it forces Lint() to give the wrong information,
# runs the test suite, and finds linters that nevertheless pass all their tests.
library(testthat)

lint_file <- "R/lint.R"

original <- readLines(lint_file)
expected_line <- "line_number = as.integer(line_number)"
if (sum(grepl(expected_line, original, fixed = TRUE)) != 1L) {
stop(sprintf(
"Please update this workflow -- need exactly one hit for line '%s' in file '%s'.",
expected_line, lint_file
))
}
writeLines(
sub(expected_line, "line_number = as.integer(2^31 - 1)", original, fixed = TRUE),
lint_file
)
# Not useful in CI but good when running locally.
withr::defer({
writeLines(original, lint_file)
pkgload::load_all()
})

pkgload::load_all()

report <- test_dir(
"tests/testthat",
filter = "linter$",
stop_on_failure = FALSE,
reporter = SilentReporter$new()
)
names(report) <- gsub("^test-|\\.R$", "", vapply(report, `[[`, "file", FUN.VALUE = character(1L)))

# Hack the nested structure of the testthat report to identify which files have
# any failed test
failed <- report |>
vapply(
\(x) any(vapply(x$results, inherits, "expectation_failure", FUN.VALUE = logical(1L))),
logical(1L)
) |>
which() |>
names() |>
unique()

passed <- setdiff(
available_linters(tags = NULL)$linter,
failed
)

if (length(passed) > 0L) {
stop("Please add tests of lint metadata for the following linters: ", toString(passed))
}
54 changes: 54 additions & 0 deletions .dev/roxygen_test.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Test to ensure roxygenize() has been run on the current PR
library(tools)
library(roxygen2)

old_dir <- file.path(tempdir(), "man")
if (dir.exists(old_dir)) unlink(old_dir, recursive = TRUE)
file.copy("man", tempdir(), recursive = TRUE)
old_files <- list.files(old_dir, pattern = "\\.Rd$")
new_dir <- "man"
.Last <- function() unlink(old_dir, recursive = TRUE)

# Rd2txt() prints to its out= argument, so we'd have to compare file contents;
# plain parse_Rd() keeps srcref info that encodes the file path, which as.character() strips.
normalize_rd <- function(rd_file) as.character(parse_Rd(rd_file))

rd_equal <- function(f1, f2) isTRUE(all.equal(normalize_rd(f1), normalize_rd(f2)))

check_roxygenize_idempotent <- function(LOCALE) {
Sys.setlocale("LC_COLLATE", LOCALE)
roxygenize()

new_files <- list.files(new_dir, pattern = "\\.Rd$")

old_not_new <- setdiff(old_files, new_files)
if (length(old_not_new) > 0L) {
stop("Found saved .Rd files gone from a fresh run of roxygenize(): ", toString(old_not_new))
}

new_not_old <- setdiff(new_files, old_files)
if (length(new_not_old) > 0L) {
stop("Found new .Rd files from a fresh run of roxygenize(): ", toString(new_not_old))
}

for (file in new_files) {
old_file <- file.path(old_dir, file)
new_file <- file.path(new_dir, file)
if (rd_equal(old_file, new_file)) {
next
}
cat(sprintf("roxygenize() output differs from saved output for %s.\n", file))
cat("Here's the 'diff' comparison of the two files:\n")
cat(" [---]: saved output in man/ directory\n")
cat(" [+++]: roxygenize() output of R/ sources\n")
system2("diff", c("--unified", old_file, new_file))
stop("Failed in LOCALE=", LOCALE, ".", call. = FALSE)
}
}

# Run the check in a few locales to ensure there's no idempotency issues w.r.t. sorting, too
for (LOCALE in c("C", "en_US", "hu_HU", "ja_JP")) {
check_roxygenize_idempotent(LOCALE)
}

unlink(old_dir, recursive = TRUE)
14 changes: 14 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM rocker/r-base

RUN apt-get -qq update && \
apt-get install -y --no-install-recommends git libxml2-dev

COPY DESCRIPTION .

RUN Rscript -e ' \
install.packages("remotes"); \
remotes::install_deps(dependencies = c( \
"Imports", \
"Config/needs/development" \
)) \
'
3 changes: 3 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"build": { "dockerfile": "Dockerfile", "context": ".."}
}
2 changes: 1 addition & 1 deletion .github/CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ representative at an online or offline event.
## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported to the community leaders responsible for enforcement at james.f.hester@gmail.com.
reported to the community leaders responsible for enforcement at michaelchirico4@gmail.com.
All complaints will be reviewed and investigated promptly and fairly.

All community leaders are obligated to respect the privacy and security of the
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ jobs:
# use 4.1 to check with rtools40's older compiler
- {os: windows-latest, r: '4.1'}

# Use older ubuntu to maximise backward compatibility
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release', locale: 'en_US'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release', locale: 'zh_CN'}
- {os: ubuntu-latest, r: 'release', http-user-agent: 'release', locale: 'zh_CN'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}
- {os: ubuntu-latest, r: 'oldrel-2'}
Expand Down Expand Up @@ -72,7 +71,6 @@ jobs:
http-user-agent: ${{ matrix.config.http-user-agent }}
use-public-rspm: true

# `{patrick}` imports `{purrr}`, and so needs to be ignored on R < 3.5
- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: |
Expand Down
41 changes: 0 additions & 41 deletions .github/workflows/check-link-rot.yaml

This file was deleted.

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/github-pages-deploy-action@v4.4.3
uses: JamesIves/github-pages-deploy-action@v4.5.0
with:
clean: false
branch: gh-pages
Expand Down
38 changes: 38 additions & 0 deletions .github/workflows/repo-meta-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Various repo-level tests for code quality
on:
push:
branches: [main]
pull_request:
branches: [main]

name: repo-meta-tests

jobs:
repo-meta-tests:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v4

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

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: |
any::roxygen2
- name: Ensure lint metadata is tested
run: |
options(crayon.enabled = TRUE)
callr::rscript(".dev/lint_metadata_test.R")
shell: Rscript {0}

- name: Ensure roxygen content matches man directory
run: |
callr::rscript(".dev/roxygen_test.R")
shell: Rscript {0}
67 changes: 30 additions & 37 deletions .lintr
Original file line number Diff line number Diff line change
@@ -1,45 +1,38 @@
linters: linters_with_defaults(
any_duplicated_linter(),
any_is_na_linter(),
backport_linter("oldrel-4", except = c("R_user_dir", "str2lang", "str2expression", "deparse1", "...names")),
consecutive_assertion_linter(),
expect_comparison_linter(),
expect_identical_linter(),
expect_length_linter(),
expect_named_linter(),
expect_not_linter(),
expect_null_linter(),
expect_s3_class_linter(),
expect_s4_class_linter(),
expect_true_false_linter(),
expect_type_linter(),
fixed_regex_linter(),
for_loop_index_linter(),
if_not_else_linter(),
implicit_assignment_linter(),
implicit_integer_linter(),
keyword_quote_linter(),
lengths_linter(),
line_length_linter(120),
missing_argument_linter(),
nested_ifelse_linter(),
numeric_leading_zero_linter(),
outer_negation_linter(),
paste_linter(),
redundant_equals_linter(),
redundant_ifelse_linter(),
sort_linter(),
sprintf_linter(),
strings_as_factors_linter(),
undesirable_function_linter(c(Sys.setenv = NA_character_, mapply = NA_character_, structure = NA_character_)),
unnecessary_nested_if_linter(),
unnecessary_lambda_linter(),
linters: all_linters(
backport_linter("3.6.0", except = c("R_user_dir", "deparse1", "...names")),
line_length_linter(120L),
object_overwrite_linter(allow_names = c("line", "lines", "pipe", "symbols")),
todo_comment_linter(
except_regex = rex::rex(
"TODO(",
# GitHub issue number #1234, possibly from another repo org/repo#5678
maybe(one_or_more(character_class("a-zA-Z0-9-")), "/", one_or_more(character_class("a-zA-Z0-9._-"))),
"#", one_or_more(digit),
")"
)
),
undesirable_function_linter(modify_defaults(
defaults = default_undesirable_functions,
library = NULL,
options = NULL
)),
undesirable_operator_linter(modify_defaults(
defaults = default_undesirable_operators,
`:::` = NULL,
`<<-` = NULL
)),
unnecessary_concatenation_linter(allow_single_expression = FALSE),
yoda_test_linter()
absolute_path_linter = NULL,
library_call_linter = NULL,
nonportable_path_linter = NULL,
todo_comment_linter = NULL,
# TODO(#2327): Enable this.
unreachable_code_linter = NULL
)
exclusions: list(
"inst/doc/creating_linters.R" = 1,
"inst/example/bad.R",
"tests/testthat.R" = list(unused_import_linter = Inf),
"tests/testthat/default_linter_testcode.R",
"tests/testthat/dummy_packages",
"tests/testthat/dummy_projects",
Expand Down
2 changes: 1 addition & 1 deletion COPYING
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2014-2022, James Hester
Copyright (c) 2014-2024, James Hester

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand Down
Loading

0 comments on commit 569f353

Please sign in to comment.