Skip to content

Commit

Permalink
Improved script generating the .lintr file, fixes #268 (#344)
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillawme authored and jimhester committed Sep 26, 2019
1 parent 1f2cb45 commit 8288366
Showing 1 changed file with 32 additions and 6 deletions.
38 changes: 32 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,41 @@ exclude_end: "# End Exclude Linting"
With the following command, you can create a configuration file for `lintr` that ignores all linters that show at least one error:

```r
# Create configuration file for lintr
# Source this file in package root directory

# List here files to exclude from lint checking, as a character vector
excluded_files <- c(
list.files("data", recursive = TRUE, full.names = TRUE),
list.files("docs", recursive = TRUE, full.names = TRUE),
list.files("inst/doc", recursive = TRUE, full.names = TRUE),
list.files("man", recursive = TRUE, full.names = TRUE),
list.files("vignettes", recursive = TRUE, full.names = TRUE)
)

### Do not edit after this line ###

library(magrittr)
library(dplyr)

# Make sure we start fresh
if (file.exists(".lintr")) { file.remove(".lintr") }

# List current lints
lintr::lint_package() %>%
as.data.frame %>%
group_by(linter) %>%
tally(sort = TRUE) %$%
sprintf("linters: with_defaults(\n %s\n NULL\n )\n",
paste0(linter, " = NULL, # ", n, collapse="\n ")) %>%
cat(file = ".lintr")
as.data.frame %>%
group_by(linter) %>%
tally(sort = TRUE) %$%
sprintf("linters: with_defaults(\n %s\n dummy_linter = NULL\n )\n",
paste0(linter, " = NULL, # ", n, collapse = "\n ")) %>%
cat(file = ".lintr")

sprintf("exclusions: list(\n %s\n )\n",
paste0('"', excluded_files, '"', collapse = ",\n ")) %>%
cat(file = ".lintr", append = TRUE)

# Clean up workspace
remove(excluded_files)
```

The resulting configuration will contain each currently failing linter and the corresponding number of hits as a comment. Proceed by successively enabling linters, starting with those with the least number of hits. Note that this requires `lintr` 0.3.0.9001 or later.
Expand Down

0 comments on commit 8288366

Please sign in to comment.