diff --git a/NEWS.md b/NEWS.md index 652420862..c0d7a37ba 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/R/lint.R b/R/lint.R index f777311ed..d22a5abf1 100644 --- a/R/lint.R +++ b/R/lint.R @@ -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) diff --git a/tests/testthat/test-lint_file.R b/tests/testthat/test-lint_file.R index 142825602..8596b2b8e 100644 --- a/tests/testthat/test-lint_file.R +++ b/tests/testthat/test-lint_file.R @@ -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 + ) +})