Skip to content

Commit

Permalink
Improve docs about how to list and use all linters (#1576)
Browse files Browse the repository at this point in the history
* Improve docs about how to list and use all linters

Closes #1482

* Use correct branches

* address comments
  • Loading branch information
IndrajeetPatil authored Oct 1, 2022
1 parent 554a11a commit 4085922
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
6 changes: 3 additions & 3 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
* `object_usage_linter()` gains `skip_with` argument to skip code in `with()` expressions.
To be consistent with `R CMD check`, it defaults to `TRUE` (#941, #1458, @IndrajeetPatil).

* `unused_import_linter()` can detect datasets from imported packages and no longer
warns when a package is imported only for its datasets (#1545, @IndrajeetPatil).

## New and improved features

* New `get_r_string()` helper to get the R-equivalent value of a string, especially useful for R-4-style raw strings.
Previously an internal `lintr` helper, now exported to facilitate writing custom linters (#1493, @MichaelChirico).

* `object_usage_linter()` improves lint metadata when detecting undefined infix operators, e.g. `%>%` or `:=` (#1497, @MichaelChirico)

* `unused_import_linter()` can detect datasets from imported packages and no longer
warns when a package is imported only for its datasets (#1545, @IndrajeetPatil).

### New linters

* `unnecessary_lambda_linter()`: detect unnecessary lambdas (anonymous functions), e.g.
Expand Down
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# lintr
[![R build status](https://github.com/r-lib/lintr/workflows/R-CMD-check/badge.svg)](https://github.com/r-lib/lintr/actions)
[![codecov.io](https://codecov.io/github/r-lib/lintr/coverage.svg?branch=master)](https://codecov.io/github/r-lib/lintr?branch=master)
[![codecov.io](https://codecov.io/github/r-lib/lintr/coverage.svg?branch=main)](https://codecov.io/github/r-lib/lintr?branch=main)
[![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/lintr)](https://cran.r-project.org/package=lintr)
[![Join the chat at https://gitter.im/jimhester-lintr/Lobby](https://badges.gitter.im/jimhester-lintr/Lobby.svg)](https://gitter.im/jimhester-lintr/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

`lintr` provides [static code analysis for R](https://en.wikipedia.org/wiki/Static_program_analysis). It checks for adherence to a given style, identifying syntax errors and possible semantic issues, then reports them to you so you can take action. Watch lintr in action in the following animation:

Expand Down Expand Up @@ -38,6 +37,16 @@ usethis::use_github_action("lint")
lintr::lint_package()
```

To see a list of linters included for each configuration:

```R
# tidyverse (default)
names(lintr::linters_with_defaults())

# full
names(lintr::linters_with_tags(tags = NULL))
```

You can also run lintr during continuous integration or within your IDE or text editor. See `vignette("continuous-integration")` and `vignette("editors")` for more details.

Without further configuration, this will run the [default linters](https://lintr.r-lib.org/reference/default_linters.html). See `vignette("lintr")` to learn how to modify these defaults.
2 changes: 1 addition & 1 deletion vignettes/creating_linters.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ testing. You can run all of the currently available tests using
`filter` argument to `devtools::test()`.
Linter tests should be put in the
[tests/testthat/](https://github.com/r-lib/lintr/tree/master/tests/testthat)
[tests/testthat/](https://github.com/r-lib/lintr/tree/main/tests/testthat)
folder. The test filename should be the linter name prefixed by `test-`, e.g.
`test-pipe_continuation_linter.R`.
Expand Down
26 changes: 26 additions & 0 deletions vignettes/lintr.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,32 @@ defaults_table <- data.frame(
knitr::kable(defaults_table)
```

#### 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))
```

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)
)
```

If you want to use all available linters *except* a few, you can exclude them using `NULL`:

```r
linters: linters_with_defaults(
commented_code_linter = NULL,
implicit_integer_linter = NULL,
defaults = linters_with_tags(tags = NULL)
)
```

#### Advanced: programmatic retrieval of linters

For some use cases, it may be useful to specify linters by string instead of by name, i.e. `"assignment_linter"` instead of writing out `assignment_linter()`.
Expand Down

0 comments on commit 4085922

Please sign in to comment.