-
Notifications
You must be signed in to change notification settings - Fork 186
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 more_nolint_directives
- Loading branch information
Showing
14 changed files
with
228 additions
and
118 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,65 @@ | ||
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples | ||
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help | ||
# | ||
# NOTE: This workflow only directly installs "hard" dependencies, i.e. Depends, | ||
# Imports, and LinkingTo dependencies. Notably, Suggests dependencies are never | ||
# installed, with the exception of testthat, knitr, and rmarkdown. The cache is | ||
# never used to avoid accidentally restoring a cache containing a suggested | ||
# dependency. | ||
# | ||
# Customization for `{lintr}` | ||
# | ||
# The following soft dependencies are not optional for testing: | ||
# `{patrick}`, `{rex}`, `{withr}` | ||
on: | ||
push: | ||
branches: [main, master] | ||
pull_request: | ||
branches: [main, master] | ||
|
||
name: R-CMD-check-hard | ||
|
||
jobs: | ||
R-CMD-check: | ||
runs-on: ${{ matrix.config.os }} | ||
|
||
name: ${{ matrix.config.os }} (${{ matrix.config.r }}) | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
config: | ||
- { os: ubuntu-latest, r: "release" } | ||
|
||
env: | ||
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} | ||
R_KEEP_PKG_SOURCE: yes | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- uses: r-lib/actions/setup-pandoc@v2 | ||
|
||
- uses: r-lib/actions/setup-r@v2 | ||
with: | ||
r-version: ${{ matrix.config.r }} | ||
http-user-agent: ${{ matrix.config.http-user-agent }} | ||
use-public-rspm: true | ||
|
||
- uses: r-lib/actions/setup-r-dependencies@v2 | ||
with: | ||
pak-version: devel | ||
dependencies: '"hard"' | ||
cache: false | ||
extra-packages: | | ||
any::rcmdcheck | ||
any::testthat | ||
any::knitr | ||
any::rmarkdown | ||
any::patrick | ||
any::withr | ||
needs: check | ||
|
||
- uses: r-lib/actions/check-r-package@v2 | ||
with: | ||
upload-snapshots: true |
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
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
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 |
---|---|---|
@@ -0,0 +1,113 @@ | ||
has_description <- function(path) { | ||
desc_info <- file.info(file.path(path, "DESCRIPTION")) | ||
!is.na(desc_info$size) && desc_info$size > 0.0 && !desc_info$isdir | ||
} | ||
|
||
find_package <- function(path) { | ||
depth <- 2L | ||
while (!has_description(path)) { | ||
path <- dirname(path) | ||
if (is_root(path) || depth <= 0L) { | ||
return(NULL) | ||
} | ||
depth <- depth - 1L | ||
} | ||
path | ||
} | ||
|
||
find_rproj_or_package <- function(path) { | ||
path <- normalizePath(path, mustWork = FALSE) | ||
|
||
depth <- 2L | ||
while (!(has_description(path) || has_rproj(path))) { | ||
path <- dirname(path) | ||
if (is_root(path) || depth <= 0L) { | ||
return(NULL) | ||
} | ||
depth <- depth - 1L | ||
} | ||
path | ||
} | ||
|
||
has_rproj <- function(path) { | ||
length(head(Sys.glob(file.path(path, "*.Rproj")), n = 1L)) == 1L | ||
} | ||
|
||
find_rproj_at <- function(path) { | ||
head(Sys.glob(file.path(path, "*.Rproj")), n = 1L) | ||
} | ||
|
||
is_root <- function(path) { | ||
identical(path, dirname(path)) | ||
} | ||
|
||
is_directory <- function(filename) { | ||
is_dir <- file.info(filename)$isdir | ||
|
||
!is.na(is_dir) && is_dir | ||
} | ||
|
||
has_config <- function(path, config) { | ||
file.exists(file.path(path, config)) | ||
} | ||
|
||
find_config <- function(filename) { | ||
if (is.null(filename)) { | ||
return(NULL) | ||
} | ||
linter_file <- getOption("lintr.linter_file") | ||
|
||
## if users changed lintr.linter_file, return immediately. | ||
if (is_absolute_path(linter_file) && file.exists(linter_file)) { | ||
return(linter_file) | ||
} | ||
|
||
path <- if (is_directory(filename)) { | ||
filename | ||
} else { | ||
dirname(filename) | ||
} | ||
|
||
## check for a file in the current directory | ||
linter_config <- file.path(path, linter_file) | ||
if (isTRUE(file.exists(linter_config))) { | ||
return(linter_config) | ||
} | ||
|
||
## next check for a file higher directories | ||
linter_config <- find_config2(path) | ||
if (isTRUE(file.exists(linter_config))) { | ||
return(linter_config) | ||
} | ||
|
||
## next check for a file in the user directory | ||
# cf: rstudio@bc9b6a5 SessionRSConnect.R#L32 | ||
home_dir <- Sys.getenv("HOME", unset = "~") | ||
linter_config <- file.path(home_dir, linter_file) | ||
if (isTRUE(file.exists(linter_config))) { | ||
return(linter_config) | ||
} | ||
|
||
NULL | ||
} | ||
|
||
find_config2 <- function(path) { | ||
config <- basename(getOption("lintr.linter_file")) | ||
path <- normalizePath(path, mustWork = FALSE) | ||
|
||
while (!has_config(path, config)) { | ||
path <- dirname(path) | ||
if (is_root(path)) { | ||
return(character()) | ||
} | ||
} | ||
return(file.path(path, config)) | ||
} | ||
|
||
pkg_name <- function(path = find_package()) { | ||
if (is.null(path)) { | ||
return(NULL) | ||
} else { | ||
read.dcf(file.path(path, "DESCRIPTION"), fields = "Package")[1L] | ||
} | ||
} |
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
Oops, something went wrong.