Skip to content

Commit

Permalink
use linter names in lint() results (#673)
Browse files Browse the repository at this point in the history
* use linter names in lint() results

* add tests and documentation.

* add trailing newline

Co-authored-by: Michael Chirico <michaelchirico4@gmail.com>
  • Loading branch information
AshesITR and MichaelChirico authored Dec 6, 2020
1 parent c2765ad commit 3ec404d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
* New `backport_linter()` for detecting mismatched R version dependencies (#506, @MichaelChirico)
* `paren_brace_linter` and `no_tab_linter` also use more reliable matching (e.g.,
excluding matches found in comments; #441 and #545, @russHyde)
* Lints are now marked with the name of the `linter` that caused them instead of the name of their implementation
function (#664, #673, @AshesITR).
* Fixed `spaces_left_parentheses_linter` sporadically causing warnings (#654, #674, @AshesITR)

# lintr 2.0.1
Expand Down
7 changes: 7 additions & 0 deletions R/lint.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ lint <- function(filename, linters = NULL, cache = FALSE, ..., parse_settings =
else {
expr_lints <- flatten_lints(linters[[linter]](expr)) # nolint

if (length(expr_lints)) {
expr_lints[] <- lapply(expr_lints, function(lint) {
lint$linter <- linter
lint
})
}

lints[[itr <- itr + 1L]] <- expr_lints
if (isTRUE(cache)) {
cache_lint(lint_cache, expr, linter, expr_lints)
Expand Down
13 changes: 13 additions & 0 deletions tests/testthat/test-lint_file.R
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,16 @@ test_that("lint() results do not depend on the position of the .lintr", {
)
)
})

test_that("lint uses linter names", {
expect_lint("a = 2", list(linter = "bla"), linters = list(bla = assignment_linter), parse_settings = FALSE)
})

test_that("exclusions work with custom linter names", {
expect_lint(
"a = 2 # nolint: bla.",
NULL,
linters = list(bla = assignment_linter),
parse_settings = FALSE
)
})

0 comments on commit 3ec404d

Please sign in to comment.