Skip to content

Commit 1d45565

Browse files
authored
fix 1442 and add regression test (#1447)
1 parent 0e7da0d commit 1d45565

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

NEWS.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
newlines.
3737
* The `vignette("lintr")` incorrectly cited `exclude` as the key for setting file exclusions in `.lintr` when it is
3838
actually `exclusions`. (#1401, @AshesITR)
39-
* `lint_dir()` no longer errors if there are multiple configured exclusions for a single file (#1413, @AshesITR).
39+
* Fixed file exclusion detection in `lint_dir()` so it no longer errors if there are multiple exclusions or no global
40+
exclusions configured for a single file (#1413, #1442, @AshesITR).
4041

4142
## Other changes
4243

R/exclude.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ is_excluded <- function(line_number, linter, file_exclusion) {
5959
}
6060

6161
is_excluded_file <- function(file_exclusion) {
62-
Inf %in% file_exclusion[[which(names2(file_exclusion) == "")]]
62+
any(vapply(
63+
file_exclusion[!nzchar(names2(file_exclusion))],
64+
function(full_exclusion) Inf %in% full_exclusion,
65+
logical(1L)
66+
))
6367
}
6468

6569
line_info <- function(line_numbers, type = c("start", "end")) {

tests/testthat/test-exclusions.R

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,48 @@ test_that("#1413: lint_dir properly excludes files", {
126126

127127
expect_length(lint(file.path(tmp, "bad.R")), 0L)
128128
expect_length(lint_dir(tmp), 0L)
129+
130+
})
131+
132+
test_that("#1442: is_excluded_files works if no global exclusions are specified", {
133+
withr::local_options(lintr.linter_file = "lintr_test_config")
134+
tmp <- withr::local_tempdir()
135+
136+
writeLines(
137+
trim_some("
138+
linters: linters_with_defaults(
139+
line_length_linter(10)
140+
)
141+
exclusions: list(
142+
'bad.R' = list(
143+
line_length_linter = 4:6
144+
)
145+
)
146+
"),
147+
file.path(tmp, "lintr_test_config")
148+
)
149+
150+
writeLines(
151+
trim_some("
152+
tmp = 'value'
153+
154+
# comment
155+
# long comment
156+
# long comment
157+
# long comment
158+
# comment
159+
"),
160+
file.path(tmp, "bad.R")
161+
)
162+
163+
# 3 lints: assignment_linter(), single_quotes_linter() and line_length_linter()
164+
expect_lint(
165+
file = file.path(tmp, "bad.R"),
166+
checks = list(
167+
list(linter = "assignment_linter", line_number = 1L),
168+
list(linter = "single_quotes_linter", line_number = 1L),
169+
list(linter = "line_length_linter", line_number = 1L)
170+
)
171+
)
172+
expect_length(lint_dir(tmp), 3L)
129173
})

0 commit comments

Comments
 (0)