Repository navigation
Conversation
|
This is a new issue and PR but it is part of Tidyverse Dev Day. @batpigandme can you add a dev day label? |
| cat(paste0("linters: with_defaults(\n ", "line_length_linter(80))\n")) | ||
| sink() | ||
|
|
||
| if(type == "test" && !file.exists(".lintr")) file.symlink("inst/.lintr", ".lintr") |
There was a problem hiding this comment.
This symbolic link approach is problematic. This is the "old way" of making lintr used as a testthat unit test work with Travis CI. I think there is a newer, better way to do this that does not involve a symbolic link to a .lintr file located inside inst but I do not know how this should be altered to get rid of the linking approach for the unit test setup.
There was a problem hiding this comment.
usethis uses the fs package for all file system and file path operations. So that should be on the radar as you resolve this.
| type <- match.arg(type) | ||
|
|
||
| if(type == "test"){ | ||
| dir.create("inst", showWarnings = FALSE) |
There was a problem hiding this comment.
This should probably use the internal create_directory() or exported use_directory() for consistency with the rest of usethis.
|
|
||
| sink(.lintr) | ||
| cat(paste0("linters: with_defaults(\n ", "line_length_linter(80))\n")) | ||
| sink() |
There was a problem hiding this comment.
We have existing helpers for writing (into) files. See the functions in write.R.
There was a problem hiding this comment.
Thank you. I'll look into all these changes I need to make to resolve these inconsistencies vis a vis usethis and fs functions.
| cat(paste0("linters: with_defaults(\n ", "line_length_linter(80))\n")) | ||
| sink() | ||
|
|
||
| if(type == "test" && !file.exists(".lintr")) file.symlink("inst/.lintr", ".lintr") |
There was a problem hiding this comment.
usethis uses the fs package for all file system and file path operations. So that should be on the radar as you resolve this.
| expect_proj_file(".lintr") | ||
| }) | ||
|
|
||
| # test_that("use_lintr('test') creates build-ignored, promised files", { |
There was a problem hiding this comment.
This test cannot be run because the testthat unit test setup option for use_lintr still depends on the old, unacceptable symlink approach. I am hoping someone knows of an alternative approach. Obviously the symbolic link cannot be created without elevated privileges.
Separately, I am unsure how to test the writing out of a test file. If I tentatively uncomment this test and elevate my privileges to enable writing of the symbolic link, the test subsequently fails because of an inability to write out the test file during testing.
| @@ -0,0 +1,24 @@ | |||
| context("use_lintr") | |||
|
|
|||
| test_that("use_lintr('local') creates build-ignored, promised file", { | |||
There was a problem hiding this comment.
Should I add lintr to Suggests in DESCRIPTION?
There was a problem hiding this comment.
No, in general we don't necessarily add a package to Suggests here in usethis, just because usethis offers some support for it. It would not be very sustainable. They way we test related functionality is to use a test mock to get around the presence test. See, for example, use_tutorial() is tested vis-a-vis learnr.
jennybc
left a comment
There was a problem hiding this comment.
We are working towards a near term release. We can just let this one age a bit more, but I pointed out a few more things.
| #' Use code linting | ||
| #' | ||
| #' `use_lintr()` Adds support for code linting using the `lintr` package in one of three ways: | ||
| #' local interactive linting only, non-failing (post-build) Travis CI linting, or failing local and Travis CI `testthat` unit test. |
There was a problem hiding this comment.
I suggest you use a bullet list. Note that we use markdown syntax for roxygen comments. If you look around, you will find many other bullet lists to emulate re: whitespace, etc.
There was a problem hiding this comment.
I suggest you add the respective argument values like so:
* "local": local interactive listing only
* "travis": non-failing, post-build lining on Travis CI
* "test": testthat unit test
| #' `use_lintr()` Adds support for code linting using the `lintr` package in one of three ways: | ||
| #' local interactive linting only, non-failing (post-build) Travis CI linting, or failing local and Travis CI `testthat` unit test. | ||
| #' | ||
| #' @param type Options are \code{local}, \code{travis} or \code{test}. |
There was a problem hiding this comment.
| #' @param type Options are \code{local}, \code{travis} or \code{test}. | |
| #' @param type `"local"`, `"travis"`, or `"test"` |
There was a problem hiding this comment.
I wonder if "type" is the right name for this argument. mode also comes to mind, as in "usage mode".
| @@ -0,0 +1,24 @@ | |||
| context("use_lintr") | |||
|
|
|||
| test_that("use_lintr('local') creates build-ignored, promised file", { | |||
There was a problem hiding this comment.
No, in general we don't necessarily add a package to Suggests here in usethis, just because usethis offers some support for it. It would not be very sustainable. They way we test related functionality is to use a test mock to get around the presence test. See, for example, use_tutorial() is tested vis-a-vis learnr.
| } else { | ||
| ui_todo("Code linting set up for interactive use. Edit {ui_path('.lintr')} as needed.") | ||
| } | ||
| use_package("lintr", "suggests") |
There was a problem hiding this comment.
This should near the top of the body, since we would exit early lintr is not installed.
There was a problem hiding this comment.
Thanks, I'll make the suggested changes.
There was a problem hiding this comment.
I've made the changes. I also had to tentatively comment out all three unit tests. I'm still having difficulty understanding how to make those work in this context.
|
@jennybc I think we need to agree on one way of using lintr before adding the support for 3 different styles. |
|
Even though I use lintr as a unit test in packages, that mode is excessive for most users. Maybe the best option for one agreed upon mode is the simplest one: lintr for interactive use only, where all that is created is a default config file? Also, since users may not initially be familiar with how to edit this file to customize their linting preferences, is it better to create one that includes some linting defaults rather than an empty config file? Placing entries in the config file that are already lintr defaults is technically redundant, but would help show users how the file is structured. Thoughts? |
Yeah and the challenge is that I, at least, don't really use lintr with any regularity. Which is one reason to give this a bit more time to simmer. |
|
May I suggest my workflow on this? It might be useful in the discussion on the potential workflows.
|
|
Over a year later and I think it's more obvious how this should now work: as a github action. So I'm going to close this issue — thanks @leonawicz for all your hard work, and we're sorry it didn't end up making it into usethis for before other technology moved on. |
This is an initial version of a
use_lintrfunction that provides three typical methods for how to integrate code linting into package development. It is not ready to be merged yet but this can start the discussion about how it can be improved. It is also lacking unit tests currently.Fixes #579