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

Conversation

MEO265
Copy link
Contributor

@MEO265 MEO265 commented Dec 5, 2023

Closes #1805

I know that a PR (#1895) already exists, but it doesn't seem to be moving forward anymore.

Please give me your opinion on whether information should be output or additional parameters should be added.

@MEO265
Copy link
Contributor Author

MEO265 commented Dec 5, 2023

Copy link
Collaborator

@AshesITR AshesITR left a comment

Choose a reason for hiding this comment

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

Is there a test that can be added?

R/use_lintr.R Outdated Show resolved Hide resolved
R/use_lintr.R Outdated Show resolved Hide resolved
R/use_lintr.R Outdated Show resolved Hide resolved
R/use_lintr.R Show resolved Hide resolved
@MEO265
Copy link
Contributor Author

MEO265 commented Dec 6, 2023

Is there a test that can be added?

Surely. I'll take care of that too. Just wanted to hear beforehand whether additional functionality would be desired. In order not to have to adapt the tests again and again.

R/use_lintr.R Outdated Show resolved Hide resolved
@codecov-commenter
Copy link

codecov-commenter commented Dec 7, 2023

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (8029e1f) 98.68% compared to head (7edac16) 98.65%.

❗ Current head 7edac16 differs from pull request most recent head 9e9611b. Consider uploading reports for the commit 9e9611b to get more accurate results

Files Patch % Lines
R/use_lintr.R 90.90% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2396      +/-   ##
==========================================
- Coverage   98.68%   98.65%   -0.04%     
==========================================
  Files         126      126              
  Lines        5700     5721      +21     
==========================================
+ Hits         5625     5644      +19     
- Misses         75       77       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

R/use_lintr.R Outdated Show resolved Hide resolved
@MEO265 MEO265 marked this pull request as ready for review December 8, 2023 06:45
@MEO265 MEO265 marked this pull request as draft December 8, 2023 07:02
@MEO265
Copy link
Contributor Author

MEO265 commented Dec 8, 2023

The code is a bit more complex than initially expected, but it should work now

@MEO265 MEO265 marked this pull request as ready for review December 8, 2023 11:11
@MEO265 MEO265 changed the title feat: use_lintradds .lintr to .Rbuildignore use_lintr adds .lintr to .Rbuildignore Dec 8, 2023

if (file.exists(file.path(path, "DESCRIPTION"))) {
# Some OS can only normalize a path if the associated file or folder exists, so the path needs to be re-normalized
tryCatch({
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't understand this part.
What do these systems return with normalizePath("foo", mustWork = FALSE) if foo doesn't exist?

pkg_path <- normalizePath(path, mustWork = TRUE, winslash = "/")
config_file <- normalizePath(file.path(path, lintr_option("linter_file")), mustWork = TRUE, winslash = "/")
}, error = function(e) {
stop("No entry could be added to the .Rbuildignore.", call. = FALSE)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This sounds like a warning is in order. The main side effect was caused at this point anyway.

# Skip a extra character for the leading `/`
rel_path <- substring(config_file, first = nchar(pkg_path) + 2L, last = nchar(config_file))
ignore_path <- file.path(pkg_path, ".Rbuildignore")
if (!file.exists(ignore_path)) file.create(ignore_path)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This branch can be a writeLines(..., ignore_path) with immediate return.

ignore <- tryCatch({
trimws(readLines(ignore_path))
}, warning = function(e) {
cat(file = ignore_path, "\n", append = TRUE)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why are you silently fixing the missing terminal newline here?

already_ignored <-
any(vapply(ignore, FUN = grepl, x = rel_path, perl = TRUE, ignore.case = TRUE, FUN.VALUE = logical(1L)))
if (!already_ignored) {
cat(file = ignore_path, rex::rex(start, rel_path, end), sep = "\n", append = TRUE)
Copy link
Collaborator

Choose a reason for hiding this comment

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

IINM the sep= is ignored because you only pass one entry into cat.


expect_message({
lintr_file <- use_lintr(path = tmp, type = "full")
}, regexp = "Adding .* to .Rbuildignore")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: the . in front of Rbuildignore matches any character.

* `string_boundary_linter()` recognizes regular expression calls like `grepl("^abc$", x)` that can be replaced by using `==` instead (#1613, @MichaelChirico).
* `unreachable_code_linter()` has an argument `allow_comment_regex` for customizing which "terminal" comments to exclude (#2327, @MichaelChirico). `# nolint end` comments are always excluded, as are {covr} exclusions (e.g. `# nocov end`) by default.
* `format()` and `print()` methods for `lint` and `lints` classes get a new option `width` to control the printing width of lint messages (#1884, @MichaelChirico). The default is controlled by a new option `lintr.format_width`; if unset, no wrapping occurs (matching earlier behavior).


Copy link
Collaborator

Choose a reason for hiding this comment

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

Superfluous 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

use_lintr() should add .lintr to .Rbuildignore
4 participants