Skip to content

Apply all but some linters #2328

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 25 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
1b77e25
lint-all-by-default
MichaelChirico Nov 21, 2023
49d04d7
restore some of our existing customizations
MichaelChirico Nov 21, 2023
c48f6e2
Merge branch 'main' into delint
MichaelChirico Nov 21, 2023
3d7c859
use ... in all_linters directly
MichaelChirico Nov 21, 2023
2535134
match DESCRIPTION version, not oldrel-4
MichaelChirico Nov 21, 2023
f970575
Merge branch 'main' into delint
AshesITR Nov 22, 2023
3a7cd97
Update test-pipe_continuation_linter.R
MichaelChirico Nov 22, 2023
ae7866f
Merge branch 'main' into delint
MichaelChirico Nov 22, 2023
49d63de
Merge remote-tracking branch 'origin/delint' into delint
MichaelChirico Nov 22, 2023
2165a97
Merge branch 'main' into delint
AshesITR Nov 24, 2023
0fa516f
Merge branch 'main' into delint
MichaelChirico Nov 27, 2023
24520ed
remove redundant edit, sort entries to defaults
MichaelChirico Nov 27, 2023
dac7bbd
Merge remote-tracking branch 'origin/delint' into delint
MichaelChirico Nov 27, 2023
7fdb790
Merge branch 'main' into delint
AshesITR Nov 27, 2023
80d67da
Merge remote-tracking branch 'origin/main' into delint
MichaelChirico Nov 28, 2023
c85ad32
nolint, rename start/end
MichaelChirico Nov 28, 2023
5ab548e
rename start/end again
MichaelChirico Nov 28, 2023
6efc6ca
ban these names
MichaelChirico Nov 28, 2023
2c5a72e
Merge remote-tracking branch 'origin/delint' into delint
MichaelChirico Nov 28, 2023
a329c24
rename lintr_deprecated arguments to avoid overwriting new
MichaelChirico Nov 28, 2023
1a8cdf1
ban new
MichaelChirico Nov 28, 2023
309ff24
rename other usages
MichaelChirico Nov 28, 2023
103b30e
delint
MichaelChirico Nov 28, 2023
004e2d7
missed rename
MichaelChirico Nov 28, 2023
c855526
Merge branch 'main' into delint
AshesITR Nov 28, 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
59 changes: 23 additions & 36 deletions .lintr
Original file line number Diff line number Diff line change
@@ -1,45 +1,32 @@
linters: linters_with_defaults(
any_duplicated_linter(),
any_is_na_linter(),
backport_linter("oldrel-4", except = c("R_user_dir", "str2lang", "str2expression", "deparse1", "...names")),
consecutive_assertion_linter(),
expect_comparison_linter(),
expect_identical_linter(),
expect_length_linter(),
expect_named_linter(),
expect_not_linter(),
expect_null_linter(),
expect_s3_class_linter(),
expect_s4_class_linter(),
expect_true_false_linter(),
expect_type_linter(),
fixed_regex_linter(),
for_loop_index_linter(),
if_not_else_linter(),
implicit_assignment_linter(),
implicit_integer_linter(),
keyword_quote_linter(),
lengths_linter(),
linters: all_linters(
backport_linter("3.6.0", except = c("R_user_dir", "deparse1", "...names")),
line_length_linter(120L),
missing_argument_linter(),
nested_ifelse_linter(),
numeric_leading_zero_linter(),
outer_negation_linter(),
paste_linter(),
redundant_equals_linter(),
redundant_ifelse_linter(),
sort_linter(),
sprintf_linter(),
strings_as_factors_linter(),
undesirable_function_linter(c(Sys.setenv = NA_character_, mapply = NA_character_, structure = NA_character_)),
unnecessary_nested_if_linter(),
unnecessary_lambda_linter(),
object_overwrite_linter(
allow_names = c("end", "line", "lines", "new", "offset", "pipe", "start", "symbols")
),
undesirable_function_linter(modify_defaults(
defaults = default_undesirable_functions,
library = NULL,
options = NULL
)),
undesirable_operator_linter(modify_defaults(
defaults = default_undesirable_operators,
`:::` = NULL,
`<<-` = NULL
)),
unnecessary_concatenation_linter(allow_single_expression = FALSE),
yoda_test_linter()
absolute_path_linter = NULL,
extraction_operator_linter = NULL,
library_call_linter = NULL,
nonportable_path_linter = NULL,
todo_comment_linter = NULL,
# TODO(#2327): Enable this.
unreachable_code_linter = NULL
)
exclusions: list(
"inst/doc/creating_linters.R" = 1,
"inst/example/bad.R",
"tests/testthat.R" = list(unused_import_linter = Inf),
"tests/testthat/default_linter_testcode.R",
"tests/testthat/dummy_packages",
"tests/testthat/dummy_projects",
Expand Down
2 changes: 1 addition & 1 deletion R/settings.R
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ validate_exclusions <- function(exclusions) {
}

exclusion_names <- names2(exclusions)
has_names <- exclusion_names != ""
has_names <- nzchar(exclusion_names)
unnamed_is_string <-
vapply(exclusions[!has_names], function(x) is.character(x) && length(x) == 1L && !is.na(x), logical(1L))
if (!all(unnamed_is_string)) {
Expand Down
2 changes: 1 addition & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ fix_names <- function(x, default) {
if (is.null(nms)) {
nms <- default
} else {
nms[nms == ""] <- default
nms[!nzchar(nms)] <- default
}
names(x) <- nms
x
Expand Down
6 changes: 3 additions & 3 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ all_undesirable_functions <- modify_defaults(
"source() loads code into the global environment unless `local = TRUE` is used,",
"which can cause hard-to-predict behavior"
),
structure =
"Use class<-, names<-, and attr<- to set attributes",
substring =
"use substr() with appropriate `stop=` value.",
Sys.setenv =
Expand All @@ -172,9 +174,7 @@ all_undesirable_functions <- modify_defaults(
untrace = paste(
"remove this likely leftover from debugging.",
"It is only useful for interactive debugging with trace()"
),
structure =
"Use class<-, names<-, and attr<- to set attributes"
)
)

#' @rdname default_undesirable_functions
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-defaults.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ test_that("linters", {
x <- default_linters
expect_type(x, "list")
expect_gt(length(x), 0L)
expect_true(all(names(x) != ""))
expect_true(all(nzchar(names(x))))
expect_true(all(vapply(x, inherits, logical(1L), "linter")))
expect_true(all(vapply(x, is.function, logical(1L))))
})
Expand All @@ -18,7 +18,7 @@ test_that("undesirable functions and operators", {
for (x in vars) {
expect_type(x, "list")
expect_gt(length(x), 0L)
expect_true(all(names(x) != ""))
expect_true(all(nzchar(names(x))))
expect_true(all(vapply(x, function(x) is.na(x) || is.character(x), logical(1L))))
expect_true(all(lengths(x) == 1L))
}
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-normalize_exclusions.R
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,15 @@ test_that("it handles redundant lines", {

test_that("it handles redundant linters", {
t1 <- list()
# nolint next: duplicate_argument_linter.
t1[[a]] <- list(c(1L, 1L, 1L:10L), my_linter = c(1L, 1L, 1L, 2L), my_linter = 3L)
res <- list()
res[[a]] <- list(1L:10L, my_linter = 1L:3L)
expect_identical(lintr:::normalize_exclusions(t1), res)

t1 <- list()
t1[[a]] <- list(c(1L, 1L, 1L:10L), my_linter = c(1L, 1L, 1L, 2L))
# nolint next: duplicate_argument_linter.
t1[[b]] <- list(1L:10L, my_linter = 1L:10L, my_linter = 11L:20L)
res <- list()
res[[a]] <- list(1L:10L, my_linter = 1L:2L)
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-pipe_continuation_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ local({
)
patrick::with_parameters_test_that(
"valid nesting is handled",
# nolint next: unnecessary_nesting_linter. TODO(#2334): Remove this nolint.
{
expect_lint(code_string, NULL, linter)
},
Expand Down