-
Notifications
You must be signed in to change notification settings - Fork 195
Implement all_linters() wrapper to access all available linters
#1854
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
Changes from 17 commits
bbdaa67
dd37a75
123c2a5
bffab55
f514cf7
e8d1031
e6047e3
7bf4b20
a180456
88d53e7
79e2319
a0605ad
8da7c64
2a55b7c
c9e38e4
930552a
41ae46a
70166c6
79a8402
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,14 @@ | |
| #' @param defaults named list of elements to modify. | ||
| #' @return A modified list of elements, sorted by name. To achieve this sort in a platform-independent way, two | ||
| #' transformations are applied to the names: (1) replace `_` with `0` and (2) convert [tolower()]. | ||
| #' @seealso [linters_with_tags], [linters_with_defaults] for creating linter lists. | ||
| #' | ||
| #' @seealso | ||
| #' - [linters_with_defaults] for basing off lintr's set of default linters. | ||
| #' - [all_linters] for basing off all available linters in lintr. | ||
| #' - [linters_with_tags] for basing off tags attached to linters, possibly across multiple packages. | ||
| #' - [available_linters] to get a data frame of available linters. | ||
| #' - [linters] for a complete list of linters available in lintr. | ||
| #' | ||
| #' @examples | ||
| #' # custom list of undesirable functions: | ||
| #' # remove `sapply` (using `NULL`) | ||
|
|
@@ -65,19 +72,17 @@ modify_defaults <- function(defaults, ...) { | |
| #' | ||
| #' @return A modified list of linters. | ||
| #' @seealso | ||
| #' [linters_with_defaults] for basing off lintr's set of default linters. | ||
| #' [available_linters] to get a data frame of available linters. | ||
| #' [linters] for a complete list of linters available in lintr. | ||
| #' - [linters_with_defaults] for basing off lintr's set of default linters. | ||
| #' - [all_linters] for basing off all available linters in lintr. | ||
| #' - [available_linters] to get a data frame of available linters. | ||
| #' - [linters] for a complete list of linters available in lintr. | ||
| #' | ||
| #' @examples | ||
| #' # `linters_with_defaults()` and `linters_with_tags("default")` are the same: | ||
| #' all.equal(linters_with_defaults(), linters_with_tags("default")) | ||
| #' | ||
| #' # Get all linters useful for package development | ||
| #' linters <- linters_with_tags(tags = "package_development") | ||
| #' names(linters) | ||
| #' | ||
| #' # Get all linters provided by lintr | ||
| #' linters <- linters_with_tags(tags = NULL) | ||
| #' linters <- linters_with_tags(tags = c("package_development", "style")) | ||
| #' names(linters) | ||
| #' | ||
| #' # Get all linters tagged as "default" from lintr and mypkg | ||
|
|
@@ -117,6 +122,23 @@ linters_with_tags <- function(tags, ..., packages = "lintr", exclude_tags = "dep | |
| modify_defaults(..., defaults = tagged_linters) | ||
| } | ||
|
|
||
| #' Create a linter configuration based on all available linters | ||
| #' | ||
| #' @inheritParams linters_with_tags | ||
| #' | ||
| #' @examples | ||
| #' names(all_linters()) | ||
| #' | ||
| #' @seealso | ||
| #' - [linters_with_defaults] for basing off lintr's set of default linters. | ||
| #' - [linters_with_tags] for basing off tags attached to linters, possibly across multiple packages. | ||
| #' - [available_linters] to get a data frame of available linters. | ||
| #' - [linters] for a complete list of linters available in lintr. | ||
| #' @export | ||
| all_linters <- function(packages = "lintr", ...) { | ||
| linters_with_tags(tags = NULL, packages = packages, ...) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens in the unlikely case that
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It will produce an error: library(lintr)
all_linters(tags = "default")
#> Error in linters_with_tags(tags = NULL, packages = packages, ...): formal argument "tags" matched by multiple actual argumentsCreated on 2022-12-18 with reprex v2.0.2 But I doubt anyone will do this because this assumes that the user has looked at the implementation details for this newly introduced function and figured out that
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
|
|
||
| #' Create a linter configuration based on defaults | ||
| #' | ||
| #' Make a new list based on \pkg{lintr}'s default linters. | ||
|
|
@@ -148,6 +170,7 @@ linters_with_tags <- function(tags, ..., packages = "lintr", exclude_tags = "dep | |
| #' | ||
| #' @seealso | ||
| #' - [linters_with_tags] for basing off tags attached to linters, possibly across multiple packages. | ||
| #' - [all_linters] for basing off all available linters in lintr. | ||
| #' - [available_linters] to get a data frame of available linters. | ||
| #' - [linters] for a complete list of linters available in lintr. | ||
| #' @export | ||
|
|
@@ -180,6 +203,8 @@ with_defaults <- function(..., default = default_linters) { | |
| linters_with_defaults(..., defaults = default) | ||
| } | ||
|
|
||
| #' @keywords internal | ||
| #' @noRd | ||
| call_linter_factory <- function(linter_factory, linter_name, package) { | ||
| linter <- tryCatch( | ||
| linter_factory(), | ||
|
|
@@ -192,6 +217,8 @@ call_linter_factory <- function(linter_factory, linter_name, package) { | |
| linter | ||
| } | ||
|
|
||
| #' @keywords internal | ||
| #' @noRd | ||
| guess_names <- function(..., missing_index) { | ||
| args <- as.character(eval(substitute(alist(...)[missing_index]))) | ||
| # foo_linter(x=1) => "foo" | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -150,6 +150,7 @@ If an Encoding is found in a `.Rproj` file or a `DESCRIPTION` file, that encodin | |
|
|
||
| If you only want to customize some linters, you can use the helper function `linters_with_defaults()`, which will keep all unnamed linters with the default settings. | ||
| Disable a linter by passing `NULL`. | ||
|
|
||
| For example, to set the line length limit to 120 characters and globally disable the `no_tab_linter`, you can put this into your `.lintr`: | ||
|
|
||
| ``` r | ||
|
|
@@ -194,29 +195,49 @@ defaults_table <- data.frame( | |
| knitr::kable(defaults_table) | ||
| ``` | ||
|
|
||
| Another way to customize linters is by specifying tags in `linters_with_tags()`. | ||
| The available tags are listed below: | ||
|
|
||
| ```{r} | ||
| available_tags(packages = "lintr") | ||
IndrajeetPatil marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ``` | ||
|
|
||
| You can select tags of interest to see which linters are included: | ||
|
|
||
| ```{r} | ||
| linters <- linters_with_tags(tags = c("package_development", "readability")) | ||
IndrajeetPatil marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| names(linters) | ||
| ``` | ||
|
|
||
| You can include tag-based linters in the configuration file, and customize them further: | ||
|
|
||
| ```r | ||
|
||
| linters: linters_with_tags( | ||
| tags = c("package_development", "readability"), | ||
| yoda_test_linter = NULL | ||
| ) | ||
| ``` | ||
|
|
||
| #### Using all available linters | ||
|
|
||
| The default lintr configuration includes only linters relevant to the tidyverse style guide, but there are many other linters available in `{lintr}`. You can see a list of all available linters using | ||
|
|
||
| ```{r} | ||
| names(lintr::linters_with_tags(tags = NULL)) | ||
| names(lintr::all_linters()) | ||
| ``` | ||
|
|
||
| If you want to use all available linters, you can include this in your `.lintr` file: | ||
|
|
||
| ```r | ||
| linters: linters_with_defaults( | ||
| defaults = linters_with_tags(tags = NULL) | ||
| ) | ||
| linters: all_linters() | ||
| ``` | ||
|
|
||
| If you want to use all available linters *except* a few, you can exclude them using `NULL`: | ||
|
|
||
| ```r | ||
| linters: linters_with_defaults( | ||
| linters: all_linters( | ||
| commented_code_linter = NULL, | ||
| implicit_integer_linter = NULL, | ||
| defaults = linters_with_tags(tags = NULL) | ||
| implicit_integer_linter = NULL | ||
| ) | ||
| ``` | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.