Skip to content
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

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions R/use_lintr.R
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be add it to .Rbuildignore, without a "the". Same in other places.

#'
#' @param path Path to project root, where a `.lintr` file should be created.
#' If the `.lintr` file already exists, an error will be thrown.
Expand All @@ -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, "'.")
}
Expand All @@ -43,5 +43,21 @@
)
)
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(startsWith(config_file, prefix = pkg_path)) {

Check warning on line 49 in R/use_lintr.R

View workflow job for this annotation

GitHub Actions / lint

file=R/use_lintr.R,line=49,col=5,[spaces_left_parentheses_linter] Place a space before left parenthesis, except in a function call.
# 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
ignore <- trimws(readLines(ignore_path, warn = FALSE))
ignore <- ignore[nzchar(ignore)]
if(!any(vapply(ignore, \(x) grepl(rel_path, pattern = x, perl = TRUE, ignore.case = TRUE), logical(1L)))) {

Check warning on line 57 in R/use_lintr.R

View workflow job for this annotation

GitHub Actions / lint

file=R/use_lintr.R,line=57,col=7,[spaces_left_parentheses_linter] Place a space before left parenthesis, except in a function call.
MEO265 marked this conversation as resolved.
Show resolved Hide resolved
cat(file = ignore_path, paste0("^", rel_path, "$"), "\n", append = TRUE)
MEO265 marked this conversation as resolved.
Show resolved Hide resolved
}
}

invisible(config_file)
}
2 changes: 1 addition & 1 deletion man/use_lintr.Rd

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

Loading