Skip to content

Commit 49486ac

Browse files
Deprecate unnecessary_concatenation_linter() (#1862)
* Deprecate `unnecessary_concatenation_linter()` In favour of `unnecessary_concatenation_linter()` Closes #1797 * fix tests * fix new lint * minor docs * update deprecated_linters list * address review comments * add tests for validations * fix lint
1 parent f253094 commit 49486ac

22 files changed

+205
-147
lines changed

.lintr_new

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ linters: linters_with_defaults(
2727
strings_as_factors_linter(),
2828
unnecessary_nested_if_linter(),
2929
unnecessary_lambda_linter(),
30-
unneeded_concatenation_linter(allow_single_expression = FALSE),
30+
unnecessary_concatenation_linter(allow_single_expression = FALSE),
3131
yoda_test_linter()
3232
)
3333
exclusions: list(

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,10 @@ Collate:
160160
'tree_utils.R'
161161
'undesirable_function_linter.R'
162162
'undesirable_operator_linter.R'
163+
'unnecessary_concatenation_linter.R'
163164
'unnecessary_lambda_linter.R'
164165
'unnecessary_nested_if_linter.R'
165166
'unnecessary_placeholder_linter.R'
166-
'unneeded_concatenation_linter.R'
167167
'unreachable_code_linter.R'
168168
'unused_import_linter.R'
169169
'use_lintr.R'

NAMESPACE

+1
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ export(trailing_blank_lines_linter)
123123
export(trailing_whitespace_linter)
124124
export(undesirable_function_linter)
125125
export(undesirable_operator_linter)
126+
export(unnecessary_concatenation_linter)
126127
export(unnecessary_lambda_linter)
127128
export(unnecessary_nested_if_linter)
128129
export(unnecessary_placeholder_linter)

NEWS.md

+3
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@
4444

4545
* The new `indentation_linter()` is part of the default linters. See "New linters" for more details.
4646

47+
* For naming consistency, `unneeded_concatenation_linter()` has been deprecated in favour of
48+
`unnecessary_concatenation_linter()` (#1797, @IndrajeetPatil).
49+
4750
## New and improved features
4851

4952
* New `get_r_string()` helper to get the R-equivalent value of a string, especially useful for R-4-style raw strings.

R/empty_assignment_linter.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#' Block assignment of `{}`
22
#'
33
#' Assignment of `{}` is the same as assignment of `NULL`; use the latter
4-
#' for clarity. Closely related: [unneeded_concatenation_linter()].
4+
#' for clarity. Closely related: [unnecessary_concatenation_linter()].
55
#'
66
#' @examples
77
#' # will produce lints

R/linter_tags.R

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
#'
55
#' @param packages A character vector of packages to search for linters.
66
#' @param tags Optional character vector of tags to search. Only linters with at least one matching tag will be
7-
#' returned. If `tags` is `NULL`, all linters will be returned.
7+
#' returned. If `tags` is `NULL`, all linters will be returned. See `available_tags("lintr")` to find out what
8+
#' tags are already used by lintr.
89
#' @param exclude_tags Tags to exclude from the results. Linters with at least one matching tag will not be returned.
910
#' If `except_tags` is `NULL`, no linters will be excluded.
1011
#'

R/lintr-deprecated.R

+18
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,24 @@ semicolon_terminator_linter <- function(semicolon = c("compound", "trailing")) {
177177
semicolon_linter(allow_compound, allow_trailing)
178178
}
179179

180+
#' Unnecessary concatenation linter
181+
#' @rdname lintr-deprecated
182+
#' @export
183+
unneeded_concatenation_linter <- function(allow_single_expression = TRUE) {
184+
lintr_deprecated(
185+
old = "unneeded_concatenation_linter",
186+
new = "unnecessary_concatenation_linter",
187+
version = "3.1.0",
188+
type = "Linter"
189+
)
190+
191+
stopifnot(
192+
is.logical(allow_single_expression),
193+
length(allow_single_expression) == 1L
194+
)
195+
unnecessary_concatenation_linter(allow_single_expression = allow_single_expression)
196+
}
197+
180198
#' @keywords internal
181199
#' @noRd
182200
find_line_fun <- function(content, newline_locs) {

R/unneeded_concatenation_linter.R renamed to R/unnecessary_concatenation_linter.R

+14-9
Original file line numberDiff line numberDiff line change
@@ -13,45 +13,50 @@
1313
#' # will produce lints
1414
#' lint(
1515
#' text = "x <- c()",
16-
#' linters = unneeded_concatenation_linter()
16+
#' linters = unnecessary_concatenation_linter()
1717
#' )
1818
#'
1919
#' lint(
2020
#' text = "x <- c(TRUE)",
21-
#' linters = unneeded_concatenation_linter()
21+
#' linters = unnecessary_concatenation_linter()
2222
#' )
2323
#'
2424
#' lint(
2525
#' text = "x <- c(1.5 + 2.5)",
26-
#' linters = unneeded_concatenation_linter(allow_single_expression = FALSE)
26+
#' linters = unnecessary_concatenation_linter(allow_single_expression = FALSE)
2727
#' )
2828
#'
2929
#' # okay
3030
#' lint(
3131
#' text = "x <- NULL",
32-
#' linters = unneeded_concatenation_linter()
32+
#' linters = unnecessary_concatenation_linter()
3333
#' )
3434
#'
3535
#' # In case the intent here was to seed a vector of known size
3636
#' lint(
3737
#' text = "x <- integer(4L)",
38-
#' linters = unneeded_concatenation_linter()
38+
#' linters = unnecessary_concatenation_linter()
3939
#' )
4040
#'
4141
#' lint(
4242
#' text = "x <- TRUE",
43-
#' linters = unneeded_concatenation_linter()
43+
#' linters = unnecessary_concatenation_linter()
4444
#' )
4545
#'
4646
#' lint(
4747
#' text = "x <- c(1.5 + 2.5)",
48-
#' linters = unneeded_concatenation_linter(allow_single_expression = TRUE)
48+
#' linters = unnecessary_concatenation_linter(allow_single_expression = TRUE)
4949
#' )
5050
#'
51-
#' @evalRd rd_tags("unneeded_concatenation_linter")
51+
#' @evalRd rd_tags("unnecessary_concatenation_linter")
5252
#' @seealso [linters] for a complete list of linters available in lintr.
5353
#' @export
54-
unneeded_concatenation_linter <- function(allow_single_expression = TRUE) {
54+
unnecessary_concatenation_linter <- function(allow_single_expression = TRUE) { # nolint: object_length_linter.
55+
stopifnot(
56+
is.logical(allow_single_expression),
57+
length(allow_single_expression) == 1L
58+
)
59+
5560
msg_empty <- paste(
5661
"Unneeded concatenation without arguments.",
5762
'Replace the "c" call by NULL or, whenever possible,',

inst/lintr/linters.csv

+2-1
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,11 @@ trailing_blank_lines_linter,style default
8282
trailing_whitespace_linter,style default configurable
8383
undesirable_function_linter,style efficiency configurable robustness best_practices
8484
undesirable_operator_linter,style efficiency configurable robustness best_practices
85+
unnecessary_concatenation_linter,style readability efficiency configurable
8586
unnecessary_lambda_linter,best_practices efficiency readability
8687
unnecessary_nested_if_linter,readability best_practices
8788
unnecessary_placeholder_linter,readability best_practices
88-
unneeded_concatenation_linter,style readability efficiency configurable
89+
unneeded_concatenation_linter,style readability efficiency configurable deprecated
8990
unreachable_code_linter,best_practices readability
9091
unused_import_linter,best_practices common_mistakes configurable executing
9192
vector_logic_linter,default efficiency best_practices

man/available_linters.Rd

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/configurable_linters.Rd

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/deprecated_linters.Rd

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/efficiency_linters.Rd

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/empty_assignment_linter.Rd

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/linters.Rd

+7-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/linters_with_tags.Rd

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/lintr-deprecated.Rd

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/readability_linters.Rd

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/style_linters.Rd

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/unneeded_concatenation_linter.Rd renamed to man/unnecessary_concatenation_linter.Rd

+11-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)