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

Fully deprecate anything marked deprecated since 3.0.0 #2284

Merged
merged 24 commits into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
8e3792c
Fully deprecate anything marked deprecated since 3.0.0
MichaelChirico Nov 14, 2023
db3697e
NEWS
MichaelChirico Nov 14, 2023
a304770
delint
MichaelChirico Nov 14, 2023
c379a1c
remove absent parameter from docmentation
MichaelChirico Nov 14, 2023
5415b2f
Correct test name
MichaelChirico Nov 14, 2023
3a1b2fd
remove redundant test
MichaelChirico Nov 14, 2023
fa45f24
restore linters, mark as defunct
MichaelChirico Nov 15, 2023
bf9e233
always exclude defunct tag from available_linters; fix some tests
MichaelChirico Nov 15, 2023
0a81466
exclude defunct from test
MichaelChirico Nov 15, 2023
4303eaf
Merge branch 'deprecated-300' of github.com:r-lib/lintr into deprecat…
MichaelChirico Nov 15, 2023
6ac7003
correct NEWS
MichaelChirico Nov 15, 2023
77f438d
correct NEWS
MichaelChirico Nov 15, 2023
2ff0481
parallel wording
MichaelChirico Nov 15, 2023
9f10a45
guess fix, debug print
MichaelChirico Nov 15, 2023
c9b7fb6
Merge branch 'deprecated-300' of github.com:r-lib/lintr into deprecat…
MichaelChirico Nov 15, 2023
0d0d654
guess correct; remove debug+delint
MichaelChirico Nov 15, 2023
87e62d2
remove obsolete descriptions
MichaelChirico Nov 15, 2023
c854d73
document absence of "defunct" linters
MichaelChirico Nov 15, 2023
dd26f5a
typo except_tags->exclude_tags
MichaelChirico Nov 15, 2023
bed6869
consistency
MichaelChirico Nov 16, 2023
2543cb3
Merge branch 'main' into deprecated-300
MichaelChirico Nov 17, 2023
01e3b37
Merge branch 'main' into deprecated-300
MichaelChirico Nov 18, 2023
5c8e84e
Merge branch 'main' into deprecated-300
MichaelChirico Nov 18, 2023
e5b4a44
Merge branch 'main' into deprecated-300
IndrajeetPatil Nov 18, 2023
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
11 changes: 11 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# lintr (development version)

## Deprecations & breaking changes

* Various things marked deprecated since {lintr} 3.0.0 have been fully deprecated. They will be completely removed in the subsequent release.
+ `source_file=` argument to `ids_with_token()` and `with_id()`.
+ Passing linters by name or as non-`"linter"`-classed functions.
+ `linter=` argument of `Lint()`.
+ Linters `closed_curly_linter()`, `open_curly_linter()`, `paren_brace_linter()`, and `semicolon_terminator_linter()`..
+ `with_defaults()`.
+ Linters `closed_curly_linter()`, `open_curly_linter()`, `paren_brace_linter()`, and `semicolon_terminator_linter()`.
+ Helper `with_defaults()`.

## Bug fixes

* `object_name_linter()` no longer errors when user-supplied `regexes=` have capture groups (#2188, @MichaelChirico).
Expand Down
6 changes: 4 additions & 2 deletions R/deprecated.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
NULL

lintr_deprecated <- function(old, new = NULL, version = NULL,
type = "Function") {
type = "Function", signal = c("warning", "stop")) {
signal <- match.arg(signal)
signal <- match.fun(signal)
msg <- c(
c(type, " ", old, " was deprecated"),
if (length(version) > 0L) {
Expand All @@ -18,5 +20,5 @@ lintr_deprecated <- function(old, new = NULL, version = NULL,
}
)
msg <- paste0(msg, collapse = "")
warning(msg, call. = FALSE, domain = NA)
signal(msg, call. = FALSE, domain = NA)
}
7 changes: 5 additions & 2 deletions R/ids_with_token.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@
#' @export
ids_with_token <- function(source_expression, value, fun = `==`, source_file = NULL) {
if (!missing(source_file)) {
lintr_deprecated(old = "source_file", new = "source_expression", version = "3.0.0", type = "Argument")
source_expression <- source_file
lintr_deprecated(
old = "source_file", new = "source_expression",
version = "3.0.0", type = "Argument",
signal = "stop"
)
}
if (!is_lint_level(source_expression, "expression")) {
return(integer())
Expand Down
39 changes: 18 additions & 21 deletions R/lint.R
Original file line number Diff line number Diff line change
Expand Up @@ -336,31 +336,27 @@ define_linters <- function(linters = NULL) {
}

validate_linter_object <- function(linter, name) {
if (!is_linter(linter) && is.function(linter)) {
if (is_linter_factory(linter)) {
old <- "Passing linters as variables"
new <- "a call to the linters (see ?linters)"
lintr_deprecated(
old = old, new = new, version = "3.0.0",
type = ""
)
linter <- linter()
} else {
old <- "The use of linters of class 'function'"
new <- "linters classed as 'linter' (see ?Linter)"
lintr_deprecated(
old = old, new = new, version = "3.0.0",
type = ""
)
linter <- Linter(linter, name = name)
}
} else if (!is.function(linter)) {
if (is_linter(linter)) {
return(linter)
}
if (!is.function(linter)) {
stop(gettextf(
"Expected '%s' to be a function of class 'linter', not a %s of class '%s'",
name, typeof(linter), class(linter)[[1L]]
))
}
linter
if (is_linter_factory(linter)) {
old <- "Passing linters as variables"
new <- "a call to the linters (see ?linters)"
} else {
old <- "The use of linters of class 'function'"
new <- "linters classed as 'linter' (see ?Linter)"
}
lintr_deprecated(
old = old, new = new, version = "3.0.0",
type = "",
signal = "stop"
)
}

is_linter_factory <- function(fun) {
Expand Down Expand Up @@ -404,7 +400,8 @@ Lint <- function(filename, line_number = 1L, column_number = 1L, # nolint: objec
lintr_deprecated(
old = "Using the `linter` argument of `Lint()`",
version = "3.0.0",
type = ""
type = "",
signal = "stop"
)
}

Expand Down
2 changes: 1 addition & 1 deletion R/linter_tag_docs.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ NULL
#' @name deprecated_linters
#' @description
#' Linters that are deprecated and provided for backwards compatibility only.
#' These linters will be excluded from `linters_with_tags()` by default.
#' These linters will be excluded from [linters_with_tags()] by default.
#' @evalRd rd_linters("deprecated")
#' @seealso [linters] for a complete list of linters available in lintr.
NULL
Expand Down
12 changes: 7 additions & 5 deletions R/linter_tags.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
#'
#' @param packages A character vector of packages to search for linters.
#' @param tags Optional character vector of tags to search. Only linters with at least one matching tag will be
#' returned. If `tags` is `NULL`, all linters will be returned. See `available_tags("lintr")` to find out what
#' tags are already used by lintr.
#' returned. If `tags` is `NULL`, all linters will be returned. See `available_tags("lintr")` to find out what
#' tags are already used by lintr.
#' @param exclude_tags Tags to exclude from the results. Linters with at least one matching tag will not be returned.
#' If `except_tags` is `NULL`, no linters will be excluded. Note that `tags` takes priority, meaning that any
#' tag found in both `tags` and `exclude_tags` will be included, not excluded.
#' If `exclude_tags` is `NULL`, no linters will be excluded. Note that `tags` takes priority, meaning that any
#' tag found in both `tags` and `exclude_tags` will be included, not excluded. Note that linters with tag `"defunct"`
#' (which do not work and can no longer be run) cannot be queried directly. See [lintr-deprecated] instead.
#'
#' @section Package Authors:
#'
Expand Down Expand Up @@ -58,7 +59,8 @@ available_linters <- function(packages = "lintr", tags = NULL, exclude_tags = "d
}

# any tags specified explicitly will not be excluded (#1959)
exclude_tags <- setdiff(exclude_tags, tags)
# never include defunct linters, which don't work / error on instantiation (#2284).
AshesITR marked this conversation as resolved.
Show resolved Hide resolved
exclude_tags <- unique(c(setdiff(exclude_tags, tags), "defunct"))

# Handle multiple packages
if (length(packages) > 1L) {
Expand Down
148 changes: 11 additions & 137 deletions R/lintr-deprecated.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,160 +5,37 @@
#'
#' These functions have been deprecated from lintr.
#'
#' - `open_curly_linter()` and `closed_curly_linter()` check that open and closed curly braces
#' are on their own line unless they follow an else, a comma, or a closing bracket.
#' Deprecated in favor of `brace_linter()`.
#' - `open_curly_linter()` (use [brace_linter()])
#' - `closed_curly_linter()` (use `brace_linter()`)
#' - `paren_brace_linter()` (use `brace_linter()`)
#' - `semicolon_terminator_linter()` (use [semicolon_linter()])
#'
#' - `paren_brace_linter()` checks that there is a space between right parentheses and an opening
#' curly brace. E.g., `function(){}` doesn't have a space, while `function() {}` does.
#' Deprecated in favor of `brace_linter()`.
#'
#' - `semicolon_terminator_linter()` checks that no semicolons terminate expressions.
#' Deprecated in favor of `semicolon_linter()`.
#'
#' @param allow_single_line if `TRUE`, allow an open and closed curly pair on the same line.
#' @param semicolon A character vector defining which semicolons to report:
#' \describe{
#' \item{compound}{Semicolons that separate two statements on the same line.}
#' \item{trailing}{Semicolons following the last statement on the line.}
#' }
#' @param allow_single_line,semicolon Irrelevant parameters to defunct linters.
#'
#' @seealso [linters] for a complete list of linters available in lintr.
#' @evalRd rd_tags("closed_curly_linter")
#' @evalRd rd_tags("single_quotes_linter")
#' @keywords internal
NULL

#' Closed curly linter
#' @rdname lintr-deprecated
#' @export
closed_curly_linter <- function(allow_single_line = FALSE) {
lintr_deprecated("closed_curly_linter", new = "brace_linter", version = "3.0.0", type = "Linter")
xp_cond_closed <- xp_and(c(
# matching { is on same line
if (isTRUE(allow_single_line)) {
"(@line1 != preceding-sibling::OP-LEFT-BRACE/@line1)"
},
# immediately followed by ",", "]" or ")"
"not(
@line1 = ancestor::expr/following-sibling::*[1][
self::OP-COMMA or self::OP-RIGHT-BRACKET or self::OP-RIGHT-PAREN
]/@line1
)",
# double curly
"not(
(@line1 = parent::expr/following-sibling::OP-RIGHT-BRACE/@line1) or
(@line1 = preceding-sibling::expr/OP-RIGHT-BRACE/@line1)
)"
))

xpath <- glue("//OP-RIGHT-BRACE[
{ xp_cond_closed } and (
(@line1 = preceding-sibling::*[1]/@line2) or
(@line1 = parent::expr/following-sibling::*[1][not(self::ELSE)]/@line1)
)
]")

Linter(function(source_expression) {
if (!is_lint_level(source_expression, "expression")) {
return(list())
}

xml_nodes_to_lints(
xml_find_all(source_expression$xml_parsed_content, xpath),
source_expression = source_expression,
lint_message = "Closing curly-braces should always be on their own line, unless they are followed by an else."
)
})
lintr_deprecated("closed_curly_linter", new = "brace_linter", version = "3.0.0", type = "Linter", signal = "stop")
}

#' Open curly linter
#' @rdname lintr-deprecated
#' @export
open_curly_linter <- function(allow_single_line = FALSE) {
lintr_deprecated("open_curly_linter", new = "brace_linter", version = "3.0.0", type = "Linter")

xpath_before <- "//OP-LEFT-BRACE[
not(following-sibling::expr[1][OP-LEFT-BRACE])
and not(parent::expr/preceding-sibling::*[1][OP-LEFT-BRACE])
and @line1 != parent::expr/preceding-sibling::*[1][not(self::ELSE)]/@line2
]"
if (allow_single_line) {
xpath_after <- "//OP-LEFT-BRACE[
not(following-sibling::expr[1][OP-LEFT-BRACE])
and not(parent::expr/preceding-sibling::OP-LEFT-BRACE)
and not(@line2 = following-sibling::OP-RIGHT-BRACE/@line1)
and @line2 = following-sibling::expr[position() = 1 and not(OP-LEFT-BRACE)]/@line1
]"
message_after <- paste(
"Opening curly braces should always be followed by a new line",
"unless the paired closing brace is on the same line."
)
} else {
xpath_after <- "//OP-LEFT-BRACE[
not(following-sibling::expr[1][OP-LEFT-BRACE])
and not(parent::expr/preceding-sibling::OP-LEFT-BRACE)
and @line2 = following-sibling::expr[1]/@line1
]"
message_after <- "Opening curly braces should always be followed by a new line."
}

Linter(function(source_expression) {
if (!is_lint_level(source_expression, "expression")) {
return(list())
}

xml <- source_expression$xml_parsed_content

expr_before <- xml_find_all(xml, xpath_before)
lints_before <- xml_nodes_to_lints(
expr_before,
source_expression = source_expression,
lint_message = "Opening curly braces should never go on their own line.",
type = "style"
)

expr_after <- xml_find_all(xml, xpath_after)
lints_after <- xml_nodes_to_lints(
expr_after,
source_expression = source_expression,
lint_message = message_after,
type = "style"
)

return(c(lints_before, lints_after))
})
lintr_deprecated("open_curly_linter", new = "brace_linter", version = "3.0.0", type = "Linter", signal = "stop")
}

#' Parentheses before brace linter
#' @rdname lintr-deprecated
#' @export
paren_brace_linter <- function() {
lintr_deprecated("paren_brace_linter", new = "brace_linter", version = "3.0.0", type = "Linter")

xpath <- paste(
"//OP-LEFT-BRACE[",
"@line1 = parent::expr/preceding-sibling::OP-RIGHT-PAREN/@line1",
"and",
"@col1 = parent::expr/preceding-sibling::OP-RIGHT-PAREN/@col1 + 1",
"]"
)

Linter(function(source_expression) {
if (!is_lint_level(source_expression, "expression")) {
return(list())
}

xml <- source_expression$xml_parsed_content

match_exprs <- xml_find_all(xml, xpath)

xml_nodes_to_lints(
match_exprs,
source_expression = source_expression,
lint_message = "There should be a space between right parenthesis and an opening curly brace.",
type = "style"
)
})
lintr_deprecated("paren_brace_linter", new = "brace_linter", version = "3.0.0", type = "Linter", signal = "stop")
}

#' Semicolon linter
Expand All @@ -169,12 +46,9 @@ semicolon_terminator_linter <- function(semicolon = c("compound", "trailing")) {
old = "semicolon_terminator_linter",
new = "semicolon_linter",
version = "3.0.0",
type = "Linter"
type = "Linter",
signal = "stop"
)
semicolon <- match.arg(semicolon, several.ok = TRUE)
allow_compound <- !"compound" %in% semicolon
allow_trailing <- !"trailing" %in% semicolon
semicolon_linter(allow_compound, allow_trailing)
}

#' Unnecessary concatenation linter
Expand Down
9 changes: 3 additions & 6 deletions R/with.R
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ all_linters <- function(packages = "lintr", ...) {
#' The result of this function is meant to be passed to the `linters` argument of `lint()`,
#' or to be put in your configuration file.
#'
#' @param defaults,default Default list of linters to modify. Must be named.
#' @param defaults Default list of linters to modify. Must be named.
#' @inheritParams linters_with_tags
#' @examplesIf requireNamespace("withr", quietly = TRUE)
#' # When using interactively you will usually pass the result onto `lint` or `lint_package()`
Expand Down Expand Up @@ -194,13 +194,10 @@ linters_with_defaults <- function(..., defaults = default_linters) {
modify_defaults(..., defaults = defaults)
}

#' @rdname linters_with_defaults
#' @rdname lintr-deprecated
#' @export
with_defaults <- function(..., default = default_linters) {
lintr_deprecated("with_defaults", "linters_with_defaults or modify_defaults", "3.0.0")
# 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)
lintr_deprecated("with_defaults", "linters_with_defaults or modify_defaults", "3.0.0", signal = "stop")
}

#' @keywords internal
Expand Down
7 changes: 5 additions & 2 deletions R/with_id.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@
#' @export
with_id <- function(source_expression, id, source_file) {
if (!missing(source_file)) {
lintr_deprecated(old = "source_file", new = "source_expression", version = "3.0.0", type = "Argument")
source_expression <- source_file
lintr_deprecated(
old = "source_file", new = "source_expression", version = "3.0.0",
type = "Argument",
signal = "stop"
)
}
if (!is_lint_level(source_expression, "expression")) {
return(data.frame())
Expand Down
8 changes: 4 additions & 4 deletions inst/lintr/linters.csv
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ backport_linter,robustness configurable package_development
boolean_arithmetic_linter,efficiency best_practices readability
brace_linter,style readability default configurable
class_equals_linter,best_practices robustness consistency
closed_curly_linter,style readability deprecated configurable
closed_curly_linter,defunct
commas_linter,style readability default configurable
commented_code_linter,style readability best_practices default
comparison_negation_linter,readability consistency
Expand Down Expand Up @@ -61,11 +61,11 @@ numeric_leading_zero_linter,style consistency readability
object_length_linter,style readability default configurable executing
object_name_linter,style consistency default configurable executing
object_usage_linter,style readability correctness default executing configurable
open_curly_linter,style readability deprecated configurable
open_curly_linter,defunct
outer_negation_linter,readability efficiency best_practices
package_hooks_linter,style correctness package_development
paren_body_linter,style readability default
paren_brace_linter,style readability deprecated
paren_brace_linter,defunct
paste_linter,best_practices consistency configurable
pipe_call_linter,style readability
pipe_consistency_linter,style readability configurable
Expand All @@ -80,7 +80,7 @@ routine_registration_linter,best_practices efficiency robustness
sample_int_linter,efficiency readability robustness
scalar_in_linter,readability consistency best_practices efficiency
semicolon_linter,style readability default configurable
semicolon_terminator_linter,style readability deprecated configurable
semicolon_terminator_linter,defunct
seq_linter,robustness efficiency consistency best_practices default
single_quotes_linter,style consistency readability deprecated
sort_linter,readability best_practices efficiency
Expand Down
Loading