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

Allow that a tag has no associated linters (esp. "deprecated") #2745

Merged
merged 13 commits into from
Feb 17, 2025
Merged
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Deprecations & breaking changes

* Arguments `allow_cascading_assign=`, `allow_right_assign=`, and `allow_pipe_assign=` to `assignment_linter()` are now defunct.
* Two linters marked as deprecated with warning in the previous release are now fully deprecated: `extraction_operator_linter()` and `unnecessary_nested_if_linter()`. They will be removed in the next release.
* Six linters marked as deprecated with warning in the previous release are now fully deprecated: `consecutive_stopifnot_linter()`, `extraction_operator_linter()`, `no_tab_linter()`, `single_quotes_linter()`, `unnecessary_nested_if_linter()`, and `unneeded_concatenation_linter()`. They will be removed in the next release.
* As previously announced, the following fully-deprecated items are now removed from the package:
+ `source_file=` argument to `ids_with_token()` and `with_id()`.
+ Passing linters by name or as non-`"linter"`-classed functions.
Expand Down
18 changes: 9 additions & 9 deletions R/linter_tags.R
Original file line number Diff line number Diff line change
Expand Up @@ -165,17 +165,17 @@ rd_linters <- function(tag_name) {
linters <- available_linters(tags = tag_name)
tagged <- platform_independent_sort(linters[["linter"]])
if (length(tagged) == 0L) {
cli_abort("No linters found associated with tag {.emph {tag_name}}.")
section_body <- paste0("There are not currently any linters tagged with '", tag_name, "'.")
} else {
section_body <- c(
paste0("The following linters are tagged with '", tag_name, "':"),
"\\itemize{",
paste0("\\item{\\code{\\link{", tagged, "}}}"),
"}"
)
}

c(
"\\section{Linters}{",
paste0("The following linters are tagged with '", tag_name, "':"),
"\\itemize{",
paste0("\\item{\\code{\\link{", tagged, "}}}"),
"}", # itemize
"}" # section
)
c("\\section{Linters}{", section_body, "}")
}

#' Generate Rd fragment for the main help page, listing all tags
Expand Down
26 changes: 11 additions & 15 deletions R/lintr-deprecated.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#' @name lintr-deprecated
#' @title Deprecated functions in lintr
#'
#' @seealso [linters] for a complete list of linters available in lintr.
#' @evalRd rd_tags("single_quotes_linter")
#' @seealso
#' - [linters] for a complete list of linters available in lintr.
#' - [deprecated_linters] for a list of linters tagged as deprecated.
#' @keywords internal
NULL

Expand All @@ -14,14 +15,9 @@ unneeded_concatenation_linter <- function(allow_single_expression = TRUE) {
what = "unneeded_concatenation_linter",
alternative = "unnecessary_concatenation_linter",
version = "3.1.0",
type = "Linter"
)

stopifnot(
is.logical(allow_single_expression),
length(allow_single_expression) == 1L
type = "Linter",
signal = "stop"
)
unnecessary_concatenation_linter(allow_single_expression = allow_single_expression)
}

#' Single quotes linter
Expand All @@ -32,9 +28,9 @@ single_quotes_linter <- function() {
what = "single_quotes_linter",
alternative = "quotes_linter",
version = "3.1.0",
type = "Linter"
type = "Linter",
signal = "stop"
)
quotes_linter()
}

#' Consecutive stopifnot linter
Expand All @@ -45,9 +41,9 @@ consecutive_stopifnot_linter <- function() {
what = "consecutive_stopifnot_linter",
alternative = "consecutive_assertion_linter",
version = "3.1.0",
type = "Linter"
type = "Linter",
signal = "stop"
)
consecutive_assertion_linter()
}

#' No tabs linter
Expand All @@ -58,9 +54,9 @@ no_tab_linter <- function() {
what = "no_tab_linter",
alternative = "whitespace_linter",
version = "3.1.0",
type = "Linter"
type = "Linter",
signal = "stop"
)
whitespace_linter()
}

#' Extraction operator linter
Expand Down
8 changes: 4 additions & 4 deletions inst/lintr/linters.csv
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ condition_message_linter,best_practices consistency
conjunct_test_linter,package_development best_practices readability configurable pkg_testthat
consecutive_assertion_linter,style readability consistency
consecutive_mutate_linter,consistency readability configurable efficiency
consecutive_stopifnot_linter,style readability consistency deprecated
consecutive_stopifnot_linter,defunct
cyclocomp_linter,style readability best_practices configurable
duplicate_argument_linter,correctness common_mistakes configurable
empty_assignment_linter,readability best_practices
Expand Down Expand Up @@ -59,7 +59,7 @@ missing_package_linter,robustness common_mistakes
namespace_linter,correctness robustness configurable executing
nested_ifelse_linter,efficiency readability
nested_pipe_linter,readability consistency configurable
no_tab_linter,style consistency deprecated
no_tab_linter,defunct
nonportable_path_linter,robustness best_practices configurable
nrow_subset_linter,efficiency consistency best_practices
numeric_leading_zero_linter,style consistency readability
Expand Down Expand Up @@ -90,7 +90,7 @@ sample_int_linter,efficiency readability robustness
scalar_in_linter,readability consistency best_practices efficiency configurable
semicolon_linter,style readability default configurable
seq_linter,robustness efficiency consistency best_practices default
single_quotes_linter,style consistency readability deprecated
single_quotes_linter,defunct
sort_linter,readability best_practices efficiency
spaces_inside_linter,style readability default
spaces_left_parentheses_linter,style readability default
Expand All @@ -111,7 +111,7 @@ unnecessary_lambda_linter,best_practices efficiency readability configurable
unnecessary_nested_if_linter,defunct
unnecessary_nesting_linter,readability consistency configurable best_practices
unnecessary_placeholder_linter,readability best_practices
unneeded_concatenation_linter,style readability efficiency configurable deprecated
unneeded_concatenation_linter,defunct
unreachable_code_linter,best_practices readability configurable
unused_import_linter,best_practices common_mistakes configurable executing
vector_logic_linter,default efficiency best_practices common_mistakes
Expand Down
8 changes: 1 addition & 7 deletions man/deprecated_linters.Rd

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

1 change: 0 additions & 1 deletion man/linters.Rd

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

8 changes: 4 additions & 4 deletions man/lintr-deprecated.Rd

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

12 changes: 2 additions & 10 deletions tests/testthat/test-consecutive_assertion_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,8 @@ test_that("lints vectorize", {
)
})

test_that("old name consecutive_stopifnot_linter() is deprecated", {
expect_warning(
{
old_linter <- consecutive_stopifnot_linter()
},
"Use consecutive_assertion_linter instead",
fixed = TRUE
)
expect_lint("stopifnot(x); y; stopifnot(z)", NULL, old_linter)
expect_lint("stopifnot(x); stopifnot(y)", "Unify consecutive calls", old_linter)
test_that("old name consecutive_stopifnot_linter() is defunct", {
expect_error(consecutive_stopifnot_linter(), "Use consecutive_assertion_linter instead", fixed = TRUE)
})

test_that("interceding = assignments aren't linted", {
Expand Down
12 changes: 2 additions & 10 deletions tests/testthat/test-quotes_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,8 @@ test_that("raw strings are handled correctly", {
expect_no_lint("r'(\")'", linter)
})

test_that("single_quotes_linter is deprecated", {
expect_warning(
{
old_linter <- single_quotes_linter()
},
"Use quotes_linter instead",
fixed = TRUE
)
expect_no_lint('"blah"', old_linter)
expect_lint("'blah'", "Only use double-quotes", old_linter)
test_that("single_quotes_linter is defunct", {
expect_error(single_quotes_linter(), "Use quotes_linter instead", fixed = TRUE)
})

test_that("lints vectorize", {
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-unneeded_concatenation_linter.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
test_that("unneeded_concatenation_linter generates deprecation warning", {
expect_warning(
test_that("unneeded_concatenation_linter generates defunct error", {
expect_error(
unneeded_concatenation_linter(),
rex::rex("Linter unneeded_concatenation_linter was deprecated")
)
Expand Down
12 changes: 2 additions & 10 deletions tests/testthat/test-whitespace_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,6 @@ test_that("whitespace_linter blocks disallowed usages with a pipe", {
)
})

test_that("no_tab_linter id deprecated", {
expect_warning(
{
old_linter <- no_tab_linter()
},
"Use whitespace_linter instead",
fixed = TRUE
)
expect_lint(" f(a, b, c)", NULL, old_linter)
expect_lint("\tf(a, b, c)", "not tabs", old_linter)
test_that("no_tab_linter is defunct", {
expect_error(no_tab_linter(), "Use whitespace_linter instead", fixed = TRUE)
})
Loading