From 706ec98b666ffb9d1af560df3e3e458cf7bf5973 Mon Sep 17 00:00:00 2001 From: Jonathan Carroll Date: Fri, 1 Jul 2022 14:21:51 +0930 Subject: [PATCH] enable skipping linters --- inst/hooks/exported/lintr.R | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/inst/hooks/exported/lintr.R b/inst/hooks/exported/lintr.R index c40fd3571..b80dae26b 100755 --- a/inst/hooks/exported/lintr.R +++ b/inst/hooks/exported/lintr.R @@ -3,11 +3,13 @@ "Run lintr on R files during a precommit. Usage: - lintr [--warn_only] ... + lintr [--warn_only] [--exclude_lintr=] ... Options: --warn_only Print lint warnings instead of blocking the commit. Should be used with `verbose: True` in `.pre-commit-config.yaml`. Otherwise, lints will never be shown to the user. + --exclude_lintr linters to exclude. Should be a comma-separated entry, e.g. + --exclude_lintr=object_name_linter,object_usage_linter " -> doc arguments <- docopt::docopt(doc) @@ -23,8 +25,13 @@ if (any(lintr_staged)) { ) } +exclude_linters <- trimws(strsplit(arguments$exclude_lintr, ",")[[1]]) +n_exclude <- length(exclude_linters) +exclude_linters <- setNames(rep(list(NULL), n_exclude), exclude_linters) +default_linters <- do.call(lintr::linters_with_defaults, exclude_linters) + for (path in arguments$files) { - lints <- lintr::lint(path) + lints <- lintr::lint(path, linters = default_linters) if (length(lints) > 0) { cat("File `", path, "` is not lint free\n", sep = "") rendered_lints <- capture.output(print(lints))