Skip to content

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?

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

@codecov-commenter
Copy link

codecov-commenter commented Dec 7, 2023

Codecov Report

❌ Patch coverage is 91.30435% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 99.25%. Comparing base (1939058) to head (6bc6009).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
R/use_lintr.R 91.30% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2396      +/-   ##
==========================================
- Coverage   99.28%   99.25%   -0.03%     
==========================================
  Files         129      129              
  Lines        7266     7289      +23     
==========================================
+ Hits         7214     7235      +21     
- Misses         52       54       +2     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

* `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

#' 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.

@MichaelChirico
Copy link
Collaborator

With the new release, it would be good to get this up to date & ready to merge. Note that one important change is we've switched to using {cli} for signalling conditions.

Let us know if you need any help & thanks!

@AshesITR
Copy link
Collaborator

Closing (#2926 was merged)
Thank you for the initial effort!

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
6 participants