Skip to content

Commit bbdaa67

Browse files
Implement all_linters() wrapper to access all available linters
Closes #1843
1 parent 73f744a commit bbdaa67

File tree

6 files changed

+62
-6
lines changed

6 files changed

+62
-6
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export(Lint)
1919
export(Linter)
2020
export(T_and_F_symbol_linter)
2121
export(absolute_path_linter)
22+
export(all_linters)
2223
export(all_undesirable_functions)
2324
export(all_undesirable_operators)
2425
export(any_duplicated_linter)

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@
8686

8787
* Added `format()` functions for `lint` and `lints` (#1784, @AshesITR)
8888

89+
* `all_linters()` function provides an easy way to access all available linters (#1843, @IndrajeetPatil)
90+
8991
### New linters
9092

9193
* `unnecessary_lambda_linter()`: detect unnecessary lambdas (anonymous functions), e.g.

R/with.R

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,10 @@ modify_defaults <- function(defaults, ...) {
6565
#'
6666
#' @return A modified list of linters.
6767
#' @seealso
68-
#' [linters_with_defaults] for basing off lintr's set of default linters.
69-
#' [available_linters] to get a data frame of available linters.
70-
#' [linters] for a complete list of linters available in lintr.
68+
#' - [linters_with_defaults] for basing off lintr's set of default linters.
69+
#' - [available_linters] to get a data frame of available linters.
70+
#' - [linters] for a complete list of linters available in lintr.
71+
#'
7172
#' @examples
7273
#' # `linters_with_defaults()` and `linters_with_tags("default")` are the same:
7374
#' all.equal(linters_with_defaults(), linters_with_tags("default"))
@@ -117,6 +118,23 @@ linters_with_tags <- function(tags, ..., packages = "lintr", exclude_tags = "dep
117118
modify_defaults(..., defaults = tagged_linters)
118119
}
119120

121+
#' Create a linter configuration based on all available linters
122+
#'
123+
#' @inheritParams linters_with_tags
124+
#'
125+
#' @examples
126+
#' names(all_linters())
127+
#'
128+
#' @seealso
129+
#' - [linters_with_defaults] for basing off lintr's set of default linters.
130+
#' - [linters_with_tags] for basing off tags attached to linters, possibly across multiple packages.
131+
#' - [available_linters] to get a data frame of available linters.
132+
#' - [linters] for a complete list of linters available in lintr.
133+
#' @export
134+
all_linters <- function(packages = "lintr") {
135+
linters_with_tags(tags = NULL, packages = packages)
136+
}
137+
120138
#' Create a linter configuration based on defaults
121139
#'
122140
#' Make a new list based on \pkg{lintr}'s default linters.

man/all_linters.Rd

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/linters_with_tags.Rd

Lines changed: 5 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-with.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,10 @@ test_that("linters_with_defaults(default = .) is supported with a deprecation wa
9292
expect_silent(linters <- linters_with_defaults(defaults = list(), default = default))
9393
expect_named(linters, "default")
9494
})
95+
96+
test_that("all_linters contains all available linters", {
97+
all_linters <- all_linters(packages = "lintr")
98+
99+
expect_identical(linters_with_tags(NULL, packages = "lintr"), all_linters)
100+
expect_identical(length(all_linters), nrow(available_linters()))
101+
})

0 commit comments

Comments
 (0)