Skip to content

with_defaults(default=NULL continues to work #1362

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

Merged
merged 1 commit into from
Jun 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 3 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@
adopted the `source_file` naming and want to adapt to keep in sync.
* Deprecated `with_defaults()` in favor of `linters_with_defaults()`, and add `modify_defaults()` which is intended to be used
more generally to modify (i.e., extend, trim, and/or update) a list of defaults. Note that the argument corresponding to
`with_defaults()`'s `default=` is called `defaults=` (i.e., pluralized) in both of these (#1029, #1336, @AshesITR and @michaelchirico)
`with_defaults()`'s `default=` is called `defaults=` (i.e., pluralized) in both of these, and that usage like
`with_defaults(default = NULL, ...)` should be converted to `linters_with_defaults(defaults = list(), ...)`
(#1029, #1336, #1361, @AshesITR and @michaelchirico)

## Other changes to defaults

Expand Down
2 changes: 2 additions & 0 deletions R/with.R
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ linters_with_defaults <- function(..., defaults = default_linters) {
#' @export
with_defaults <- function(..., default = default_linters) {
lintr_deprecated("with_defaults", "linters_with_defaults", "2.0.9001")
# to ease the burden of transition -- default = NULL used to behave like defaults = list() now does
if (is.null(default)) default <- list()
linters_with_defaults(..., defaults = default)
}

Expand Down
10 changes: 9 additions & 1 deletion tests/testthat/test-with.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,15 @@ test_that("with_defaults is supported with a deprecation warning", {
old_defaults <- with_defaults(),
rex::rex("Use linters_with_defaults instead.")
)
expect_equal(defaults, old_defaults)
expect_identical(defaults, old_defaults)

# linters_with_defaults only accepts `defaults = list()` to start from blank
defaults <- linters_with_defaults(defaults = list(), no_tab_linter())
expect_warning(
old_defaults <- with_defaults(default = NULL, no_tab_linter()),
rex::rex("Use linters_with_defaults instead.")
)
expect_identical(defaults, old_defaults)
})

test_that("modify_defaults works", {
Expand Down