-
Notifications
You must be signed in to change notification settings - Fork 187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
use_lintr
adds .lintr to .Rbuildignore
#2396
base: main
Are you sure you want to change the base?
Changes from 7 commits
5d0f734
fdb2307
ee7c47c
7f538d0
fb9e003
8f9bb6f
81c7761
09a888a
25ada69
06f031a
dec9a9d
c54980d
6cb1b49
24624b9
302782e
bd56690
1226e0c
88acd40
9e9611b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#' Use lintr in your project | ||
#' | ||
#' Create a minimal lintr config file as a starting point for customization | ||
#' Create a minimal lintr config file as a starting point for customization and add it to the .Rbuildignore | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should be |
||
#' | ||
#' @param path Path to project root, where a `.lintr` file should be created. | ||
#' If the `.lintr` file already exists, an error will be thrown. | ||
|
@@ -25,7 +25,7 @@ | |
#' lintr::lint_dir() | ||
#' } | ||
use_lintr <- function(path = ".", type = c("tidyverse", "full")) { | ||
config_file <- normalizePath(file.path(path, lintr_option("linter_file")), mustWork = FALSE) | ||
config_file <- normalizePath(file.path(path, lintr_option("linter_file")), mustWork = FALSE, winslash = "/") | ||
AshesITR marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (file.exists(config_file)) { | ||
stop("Found an existing configuration file at '", config_file, "'.") | ||
} | ||
|
@@ -43,5 +43,25 @@ use_lintr <- function(path = ".", type = c("tidyverse", "full")) { | |
) | ||
) | ||
write.dcf(the_config, config_file, width = Inf) | ||
|
||
# Check if config_file is in package i.e. lintr_option("linter_file") != "../.lintr" | ||
pkg_path <- normalizePath(path, mustWork = FALSE, winslash = "/") | ||
if (file.exists("DESCRIPTION") && startsWith(config_file, prefix = pkg_path)) { | ||
# Skip a extra character for the leading `/` | ||
rel_path <- substring(config_file, first = nchar(pkg_path) + 2L, last = nchar(config_file)) | ||
AshesITR marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ignore_path <- file.path(pkg_path, ".Rbuildignore") | ||
if (!file.exists(ignore_path)) file.create(ignore_path) | ||
MEO265 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# Follow the same procedure as base R to see if the file is already ignored | ||
tryCatch({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand this part. |
||
ignore <- trimws(readLines(ignore_path, warn = FALSE)) | ||
}, warning = function(e) cat(file = ignore_path, "\n", append = TRUE) | ||
) | ||
ignore <- ignore[nzchar(ignore)] | ||
if (!any(vapply(ignore, function(x) grepl(rel_path, pattern = x, perl = TRUE, ignore.case = TRUE), logical(1L)))) { | ||
MEO265 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
cat(file = ignore_path, rex::rex(start, rel_path, end), sep = "\n", append = TRUE) | ||
message("Adding ", rel_path, " to .Rbuildignore") | ||
} | ||
} | ||
|
||
invisible(config_file) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Superfluous change