Skip to content

use linter names in lint() results #673

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Dec 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
)
})