Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
148 commits
Select commit Hold shift + click to select a range
3882350
use maybe_write_content for easier 'mocking'
MichaelChirico Mar 5, 2025
c392c53
initial progress
MichaelChirico Mar 6, 2025
5cef281
getting very close i think...
MichaelChirico Mar 6, 2025
a4e4a66
skip Rmd files
MichaelChirico Mar 6, 2025
0b1eaf5
caught a live one!
MichaelChirico Mar 6, 2025
868ad30
need to match original file extension?
MichaelChirico Mar 6, 2025
0ed5cc0
caught another one!
MichaelChirico Mar 6, 2025
99d00a3
simpler approach, avoid rex() due to bug
MichaelChirico Mar 6, 2025
d3cca7a
also ignore warnings
MichaelChirico Mar 6, 2025
59dc1b0
finally getting somewhere...
MichaelChirico Mar 6, 2025
a25065f
progressively more complicated :(
MichaelChirico Mar 6, 2025
491a340
round of fixes & first working nofuzz
MichaelChirico Mar 6, 2025
92f0628
looks like we got another live one... break time
MichaelChirico Mar 6, 2025
d387a71
another true positive
MichaelChirico Mar 6, 2025
e150ffe
more ignores, need '.' in file extension, restore test
MichaelChirico Mar 6, 2025
3d1fc0e
wrapping up
MichaelChirico Mar 6, 2025
b69b7cd
Write up the GHA config
MichaelChirico Mar 6, 2025
b8a06e3
annotation
MichaelChirico Mar 6, 2025
a3dbf27
comment for future work
MichaelChirico Mar 6, 2025
5a22050
vestigial
MichaelChirico Mar 6, 2025
76b869f
skips on old R
MichaelChirico Mar 6, 2025
afec743
expect_no_lint
MichaelChirico Mar 6, 2025
51593e4
new tests
MichaelChirico Mar 6, 2025
f4b9481
NEWS
MichaelChirico Mar 6, 2025
6389d55
bad copy-paste
MichaelChirico Mar 6, 2025
1550ead
need stop_on_failure for batch?
MichaelChirico Mar 6, 2025
bbdac43
delint, fix last skip for R<4.1.0
MichaelChirico Mar 6, 2025
523c218
more extensible structure
MichaelChirico Mar 7, 2025
852d0ea
expect_no_lint
MichaelChirico Mar 7, 2025
3eb21ca
progress, incl. many 'nofuzz' & 'no_lint'
MichaelChirico Mar 7, 2025
8059091
another round of nofuzz
MichaelChirico Mar 7, 2025
df8cccc
another batch
MichaelChirico Mar 7, 2025
138e9cc
tweak
MichaelChirico Mar 7, 2025
683c461
another nofuzz case, attempting to reduce nofuzz requirements
MichaelChirico Mar 7, 2025
98086d4
fix; scale back nofuzz for an attempt
MichaelChirico Mar 7, 2025
fe88c59
reinstate more legit nofuzz
MichaelChirico Mar 7, 2025
1928831
general fix for issue of S4 method calls under @
MichaelChirico Mar 7, 2025
168ee65
fix missed S4 extractions looking for preamble
MichaelChirico Mar 7, 2025
413e029
expect_no_lint
MichaelChirico Mar 7, 2025
c7cc8ac
handle @ equivalency
MichaelChirico Mar 7, 2025
4d3ff4f
fix an equivalency issue in indentation_linter
MichaelChirico Mar 7, 2025
1d8869f
new simple swap fuzzer, some nofuzz
MichaelChirico Mar 7, 2025
3d106d7
add some vectorization to make debugging easier
MichaelChirico Mar 7, 2025
1d19687
another indentation inconsistency
MichaelChirico Mar 7, 2025
dbfaf5c
nofuzz'ing
MichaelChirico Mar 7, 2025
88117cb
complete NEWS
MichaelChirico Mar 7, 2025
ee611cb
more expect_no_lint
MichaelChirico Mar 7, 2025
aa756e6
more expect_no_lint
MichaelChirico Mar 7, 2025
c3a99ce
add tests of include_s4_slots
MichaelChirico Mar 7, 2025
5893b8c
initial try, let's see
MichaelChirico Mar 7, 2025
8a83c01
adversarial comment protection
MichaelChirico Mar 7, 2025
836bf31
expect_no_lint
MichaelChirico Mar 7, 2025
f0974d9
caught true false positive
MichaelChirico Mar 7, 2025
a0dc171
some nofuzz
MichaelChirico Mar 7, 2025
4fc370d
don't break up calls; report the actual content
MichaelChirico Mar 7, 2025
c130bf4
nofuzz
MichaelChirico Mar 7, 2025
fc097ba
fix another one
MichaelChirico Mar 7, 2025
092f98e
fix another one
MichaelChirico Mar 8, 2025
4c08d49
another real fix
MichaelChirico Mar 8, 2025
7b2a16d
nofuzz
MichaelChirico Mar 8, 2025
78bdc12
no hope for brace_linter; use a space before comment for infix_spaces
MichaelChirico Mar 8, 2025
6446bbb
another real fix
MichaelChirico Mar 8, 2025
d256ccb
expect_no_lint
MichaelChirico Mar 8, 2025
f4e53cb
another real fix
MichaelChirico Mar 8, 2025
f817c77
expect_no_lint
MichaelChirico Mar 8, 2025
3f817a7
expect_no_lint, stylistic touch-up
MichaelChirico Mar 8, 2025
0fa5647
style touch-up (no message=)
MichaelChirico Mar 8, 2025
c2b18ca
nofuzz
MichaelChirico Mar 8, 2025
24f32a4
expect_no_lint
MichaelChirico Mar 8, 2025
c7530e6
more true fixes
MichaelChirico Mar 8, 2025
0ed031d
tidy
MichaelChirico Mar 8, 2025
ccc0f89
tidy2
MichaelChirico Mar 8, 2025
6c090b7
nofuzz, expect_no_lint
MichaelChirico Mar 8, 2025
cd7052b
a real bear here, fixed
MichaelChirico Mar 8, 2025
4326789
another true fix
MichaelChirico Mar 8, 2025
35e7708
bug fix
MichaelChirico Mar 8, 2025
218e656
more nofuzz, another true fix
MichaelChirico Mar 8, 2025
29a6232
another nofuzz, another true fix
MichaelChirico Mar 8, 2025
85fd53e
another case requiring stripping comments, more nofuzz
MichaelChirico Mar 8, 2025
7ae6552
fix yet another, nofuzz
MichaelChirico Mar 8, 2025
c750079
another fix
MichaelChirico Mar 8, 2025
7cede8e
closer & closer: another
MichaelChirico Mar 8, 2025
bacce08
found the MRE, not fixed yet
MichaelChirico Mar 8, 2025
edfe6d3
what eldritch horrors...
MichaelChirico Mar 8, 2025
06b2047
the easier fixes continue
MichaelChirico Mar 8, 2025
de0bf4a
modernize the test file first to apply nofuzz next
MichaelChirico Mar 8, 2025
15d3a50
further tweak, nofuzz
MichaelChirico Mar 8, 2025
7699a7c
ban the '*'
MichaelChirico Mar 8, 2025
4c38b90
node equality tests are going to be a pain...
MichaelChirico Mar 8, 2025
68ab08d
another one requiring a tree copy
MichaelChirico Mar 8, 2025
aad82de
nofuzz
MichaelChirico Mar 8, 2025
9a508b1
*[2]
MichaelChirico Mar 8, 2025
0ad134c
skip another file
MichaelChirico Mar 8, 2025
3929a43
preceding-sibling::*
MichaelChirico Mar 9, 2025
e57707e
improve handling of ifelse_censor, add a new test
MichaelChirico Mar 9, 2025
72164ee
more comments interfering with node=node tests
MichaelChirico Mar 9, 2025
ac774a3
simpler preceding-sibling::* fix
MichaelChirico Mar 9, 2025
173e932
more nofuzz, more preceding-sibling::*
MichaelChirico Mar 9, 2025
fcf7cf7
tricky tricky
MichaelChirico Mar 9, 2025
025537b
hit the dj khaled
MichaelChirico Mar 9, 2025
f0c8c9a
another tricky one
MichaelChirico Mar 9, 2025
ebe7936
kitchen sink
MichaelChirico Mar 9, 2025
04d4e1b
new one, old rule
MichaelChirico Mar 9, 2025
a7c9768
just drop formulas
MichaelChirico Mar 9, 2025
e1a497c
edge case in seq_linter
MichaelChirico Mar 9, 2025
3d11316
another sprintf case
MichaelChirico Mar 9, 2025
a9dca0c
re-fixed unreachable code thing?
MichaelChirico Mar 9, 2025
2a0831d
more nofuzz, and finally fixed the conjunct_test issue
MichaelChirico Mar 9, 2025
9344004
unbelievably tricky
MichaelChirico Mar 10, 2025
f53ec50
need one further level up here too
MichaelChirico Mar 10, 2025
5d61675
one more easy one
MichaelChirico Mar 10, 2025
dd08aa2
another tricky one
MichaelChirico Mar 10, 2025
b96f2b1
trickier handling needed
MichaelChirico Mar 10, 2025
ff083c2
for future reference
MichaelChirico Mar 10, 2025
88f998c
blessed oversight
MichaelChirico Mar 10, 2025
5606eac
vestigial
MichaelChirico Mar 10, 2025
49872bf
expect_no_lint
MichaelChirico Mar 10, 2025
3494010
leftovers
MichaelChirico Mar 10, 2025
0f02cc5
expect_no_lint in all touched files
MichaelChirico Mar 10, 2025
aa3e930
start the NEWS
MichaelChirico Mar 10, 2025
18f32d3
cite all changed linters
MichaelChirico Mar 10, 2025
2907c86
annotate reference issues where noteworthy
MichaelChirico Mar 10, 2025
a42bda5
cleanup
MichaelChirico Mar 10, 2025
1275cca
Merge branch 'main' into fuzz-dollar
AshesITR Jul 24, 2025
ee9b446
remove empty line
AshesITR Jul 24, 2025
50b8832
revert
MichaelChirico Jul 24, 2025
4f95e40
revert
MichaelChirico Jul 24, 2025
ebab604
revert
MichaelChirico Jul 24, 2025
2a1ebe2
failed merge?
MichaelChirico Jul 24, 2025
4870ecb
narrow line
MichaelChirico Jul 24, 2025
83aa12e
trailing ws
MichaelChirico Jul 24, 2025
53148c6
Merge branch 'fuzz-dollar' into fuzz-comments
MichaelChirico Jul 25, 2025
2840d7b
Merge branch 'main' into fuzz-comments
MichaelChirico Jul 26, 2025
5d61a1e
Merge branch 'main' into fuzz-comments
MichaelChirico Jul 26, 2025
2392fa4
missed expect_comparison_linter
MichaelChirico Jul 26, 2025
5490c64
Merge branch 'main' into fuzz-comments
MichaelChirico Jul 28, 2025
b41961d
Merge branch 'main' into fuzz-comments
MichaelChirico Dec 30, 2025
80e71c1
Merge remote-tracking branch 'origin/fuzz-comments' into fuzz-comments
MichaelChirico Dec 30, 2025
a45814a
Merge branch 'main' into fuzz-comments
MichaelChirico Dec 30, 2025
e0d9277
tidy up imperfect merge
MichaelChirico Dec 30, 2025
12a97f8
adjust expect_lint to match fuzzer expectation again
MichaelChirico Dec 31, 2025
3377332
fix two fuzz findings
MichaelChirico Dec 31, 2025
7a9240d
nofuzz the whole test
MichaelChirico Dec 31, 2025
9e56565
another nofuzz
MichaelChirico Dec 31, 2025
84ba9ba
another one
MichaelChirico Dec 31, 2025
3847e51
more nofuzz in expect_lint suite
MichaelChirico Dec 31, 2025
458aeed
Merge branch 'main' into fuzz-comments
MichaelChirico Jan 8, 2026
4836fd2
Increas max_reports to ensure more is shown in the logs
MichaelChirico Jan 8, 2026
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
29 changes: 27 additions & 2 deletions .dev/ast_fuzz_test.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,30 @@ writeLines(
),
expect_lint_file
)

# Ensure the fuzzed contents are always visible to facilitate backing out which fuzzed content is at issue
contents <- readLines(expect_lint_file)
wrong_number_def_idx <- grep('wrong_number_fmt <- "got %d lints instead of %d%s"', contents, fixed = TRUE)
wrong_number_use_idx <- grep("sprintf(wrong_number_fmt,", contents, fixed = TRUE)
if (
length(wrong_number_def_idx) != 1L ||
length(wrong_number_use_idx) == 0L ||
# these lines should be self-contained, have no comments, no nested calls
!all(grepl("[^)][)]$", contents[wrong_number_use_idx])) ||
inherits(tryCatch(parse(text = contents[wrong_number_use_idx]), error = identity), "error")
) {
stop(sprintf(
"Please update this workflow -- need wrong_number_fmt to be easily replaced in file '%s'.",
expect_lint_file
))
}

contents[wrong_number_def_idx] <-
'wrong_number_fmt <- "got %d lints instead of %d%s\\nFile contents:\\n%s"'
contents[wrong_number_use_idx] <-
gsub("\\)$", ", readChar(file, file.size(file)))", contents[wrong_number_use_idx])
writeLines(contents, expect_lint_file)

# Not useful in CI but good when running locally.
withr::defer({
writeLines(original, expect_lint_file)
Expand Down Expand Up @@ -105,7 +129,7 @@ withr::defer(for (restoration in test_restorations) writeLines(restoration$lines
# even 'report <- test_local(...)', which does return an object, lacks any information about
# which tests failed (all reports are about successful or skipped tests). probably this is not
# the best approach but documentation was not very helpful.
reporter <- testthat::SummaryReporter$new()
reporter <- testthat::SummaryReporter$new(max_reports = 500L)
testthat::test_local(reporter = reporter, stop_on_failure = FALSE)

failures <- reporter$failures$as_list()
Expand All @@ -116,7 +140,8 @@ failures <- reporter$failures$as_list()
valid_failure <- vapply(
failures,
function(failure) {
if (grepl("(column_number|ranges|line) .* did not match", failure$message)) {
# line_number is for the comment injection fuzzer, which adds newlines.
if (grepl("(column_number|ranges|line|line_number) .* did not match", failure$message)) {
return(TRUE)
}
FALSE
Expand Down
30 changes: 29 additions & 1 deletion .dev/maybe_fuzz_content.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ maybe_fuzz_content <- function(file, lines) {
file.copy(file, new_file, copy.mode = FALSE)
}

apply_fuzzers(new_file, list(function_lambda_fuzzer, pipe_fuzzer, dollar_at_fuzzer))
apply_fuzzers(new_file, list(function_lambda_fuzzer, pipe_fuzzer, dollar_at_fuzzer, comment_injection_fuzzer))

new_file
}
Expand Down Expand Up @@ -59,6 +59,34 @@ dollar_at_fuzzer <- simple_swap_fuzzer(
replacements = c("$", "@")
)

comment_injection_fuzzer <- function(pd, lines) {
# injecting comment before a call often structurally breaks parsing
# (SYMBOL_FUNCTION_CALL-->SYMBOL), so avoid
terminal_token_idx <- which(pd$terminal & !pd$token %in% c("COMMENT", "SYMBOL_FUNCTION_CALL", "SLOT"))
# formula is messy because it's very easy to break parsing, but not easy to exclude the right
# elements from the pd data.frame (easier with XPath ancestor axis). Just skip for now.
if (any(pd$token == "'~'")) {
return(invisible())
}
injection_count <- sample(0:length(terminal_token_idx), 1L)

if (injection_count == 0L) {
return(invisible())
}

terminal_token_idx <- sort(sample(terminal_token_idx, injection_count))

for (ii in rev(terminal_token_idx)) {
line <- lines[pd$line2[ii]]
lines[pd$line2[ii]] <- paste0(
substr(line, 1L, pd$col2[ii]),
" # INJECTED COMMENT\n",
substr(line, pd$col2[ii] + 1L, nchar(line))
)
}
lines
}

# we could also consider just passing any test where no fuzzing takes place,
# i.e. letting the other GHA handle whether unfuzzed tests pass as expected.
apply_fuzzers <- function(f, fuzzers) {
Expand Down
37 changes: 37 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,43 @@

* Excluding `cyclocomp_linter()` in `available_linters()` or `linters_with_tags()`, which requires the weak dependency {cyclocomp}, no longer emits a warning (#2909, @MichaelChirico).

## New and improved features

### Linter improvements

* General handling of logic around where comments can appear in code has been improved (#2822, @MichaelChirico). In many cases, this is a tiny robustness fix for weird edge cases unlikely to be found in practice, but in others, this improves practical linter precision (reduced false positives and/or false negatives). The affected linters (with annotations for changes noteworthy enough to have gotten a dedicated bug) are:
+ `brace_linter()`
+ `coalesce_linter()`
+ `comparison_negation_linter()` #2826
+ `conjunct_test_linter()` #2827
+ `empty_assignment_linter()`
+ `expect_comparison_linter()`
+ `fixed_regex_linter()` #2827
+ `if_switch_linter()`
+ `ifelse_censor_linter()` #2826
+ `implicit_assignment_linter()`
+ `length_test_linter()`
+ `literal_coercion_linter()` #2824
+ `matrix_apply_linter()` #2825
+ `nzchar_linter()` #2826
+ `object_length_linter()` #2827
+ `object_name_linter()` #2827
+ `object_usage_linter()`
+ `outer_negation_linter()` #2827
+ `redundant_equals_linter()`
+ `regex_subset_linter()`
+ `seq_linter()`
+ `sort_linter()`
+ `sprintf_linter()` #2827
+ `string_boundary_linter()`
+ `strings_as_factors_linter()`
+ `unnecessary_concatenation_linter()` #2827
+ `unnecessary_lambda_linter()` #2827
+ `unnecessary_nesting_linter()` #2827
+ `unnecessary_placeholder_linter()`
+ `unreachable_code_linter()` #2827
+ `vector_logic_linter()` #2826

## Notes

* {lintr} now requires R 4.1.0
Expand Down
6 changes: 4 additions & 2 deletions R/expect_lint.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ expect_lint <- function(content, checks, ..., file = NULL, language = "en", igno
wrong_number_fmt <- "got %d lints instead of %d%s"
if (is.null(checks)) {
if (n_lints != 0L) {
return(testthat::fail(sprintf(wrong_number_fmt, n_lints, 0L, lint_str)))
fail_msg <- sprintf(wrong_number_fmt, n_lints, 0L, lint_str)
return(testthat::fail(fail_msg))
}
return(testthat::succeed())
}
Expand All @@ -71,7 +72,8 @@ expect_lint <- function(content, checks, ..., file = NULL, language = "en", igno
checks[] <- lapply(checks, fix_names, "message")

if (n_lints != length(checks)) {
return(testthat::fail(sprintf(wrong_number_fmt, n_lints, length(checks), lint_str)))
fail_msg <- sprintf(wrong_number_fmt, n_lints, length(checks), lint_str)
return(testthat::fail(fail_msg))
}

if (ignore_order) {
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-assignment_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ test_that("arguments handle <<- and ->/->> correctly", {
)
})

test_that("arguments handle trailing assignment operators correctly", {
test_that("arguments handle trailing assignment operators correctly", { # nofuzz
linter_default <- assignment_linter()
linter_no_trailing <- assignment_linter(allow_trailing = FALSE)
expect_no_lint("x <- y", linter_no_trailing)
Expand Down Expand Up @@ -165,7 +165,7 @@ test_that("arguments handle trailing assignment operators correctly", {
)
})

test_that("allow_trailing interacts correctly with comments in braced expressions", {
test_that("allow_trailing interacts correctly with comments in braced expressions", { # nofuzz
linter <- assignment_linter(allow_trailing = FALSE)
expect_no_lint(
trim_some("
Expand Down
68 changes: 35 additions & 33 deletions tests/testthat/test-commas_linter.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# nofuzz start
test_that("returns the correct linting (with default parameters)", {
linter <- commas_linter()
msg_after <- rex::rex("Put a space after a comma.")
msg_before <- rex::rex("Remove spaces before a comma.")

expect_lint("blah", NULL, linter)
expect_lint("fun(1, 1)", NULL, linter)
expect_lint("fun(1,\n 1)", NULL, linter)
expect_lint("fun(1,\n1)", NULL, linter)
expect_lint("fun(1\n,\n1)", NULL, linter)
expect_lint("fun(1\n ,\n1)", NULL, linter)
expect_no_lint("blah", linter)
expect_no_lint("fun(1, 1)", linter)
expect_no_lint("fun(1,\n 1)", linter)
expect_no_lint("fun(1,\n1)", linter)
expect_no_lint("fun(1\n,\n1)", linter)
expect_no_lint("fun(1\n ,\n1)", linter)

expect_lint("fun(1\n,1)", msg_after, linter)
expect_lint("fun(1,1)", msg_after, linter)
Expand All @@ -25,14 +26,14 @@ test_that("returns the correct linting (with default parameters)", {
linter
)

expect_lint("\"fun(1 ,1)\"", NULL, linter)
expect_lint("a[1, , 2]", NULL, linter)
expect_lint("a[1, , 2, , 3]", NULL, linter)
expect_no_lint('"fun(1 ,1)"', linter)
expect_no_lint("a[1, , 2]", linter)
expect_no_lint("a[1, , 2, , 3]", linter)

expect_lint("switch(op, x = foo, y = bar)", NULL, linter)
expect_lint("switch(op, x = , y = bar)", NULL, linter)
expect_lint("switch(op, \"x\" = , y = bar)", NULL, linter)
expect_lint("switch(op, x = ,\ny = bar)", NULL, linter)
expect_no_lint("switch(op, x = foo, y = bar)", linter)
expect_no_lint("switch(op, x = , y = bar)", linter)
expect_no_lint('switch(op, "x" = , y = bar)', linter)
expect_no_lint("switch(op, x = ,\ny = bar)", linter)

expect_lint("switch(op, x = foo , y = bar)", msg_before, linter)
expect_lint("switch(op, x = foo , y = bar)", msg_before, linter)
Expand All @@ -55,8 +56,8 @@ test_that("returns the correct linting (with default parameters)", {
expect_lint(
"fun(op ,bar)",
list(
list(message = msg_before, column_number = 7L, ranges = list(c(7L, 10L))),
list(message = msg_after, column_number = 12L, ranges = list(c(12L, 12L)))
list(msg_before, column_number = 7L, ranges = list(c(7L, 10L))),
list(msg_after, column_number = 12L, ranges = list(c(12L, 12L)))
),
linter
)
Expand All @@ -67,14 +68,14 @@ test_that("returns the correct linting (with 'allow_trailing' set)", {
msg_after <- rex::rex("Put a space after a comma.")
msg_before <- rex::rex("Remove spaces before a comma.")

expect_lint("blah", NULL, linter)
expect_lint("fun(1, 1)", NULL, linter)
expect_lint("fun(1,\n 1)", NULL, linter)
expect_lint("fun(1,\n1)", NULL, linter)
expect_lint("fun(1\n,\n1)", NULL, linter)
expect_lint("fun(1\n ,\n1)", NULL, linter)
expect_lint("a[1,]", NULL, linter)
expect_lint("a(1,)", NULL, linter)
expect_no_lint("blah", linter)
expect_no_lint("fun(1, 1)", linter)
expect_no_lint("fun(1,\n 1)", linter)
expect_no_lint("fun(1,\n1)", linter)
expect_no_lint("fun(1\n,\n1)", linter)
expect_no_lint("fun(1\n ,\n1)", linter)
expect_no_lint("a[1,]", linter)
expect_no_lint("a(1,)", linter)

expect_lint("fun(1\n,1)", msg_after, linter)
expect_lint("fun(1,1)", msg_after, linter)
Expand All @@ -88,15 +89,15 @@ test_that("returns the correct linting (with 'allow_trailing' set)", {
linter
)

expect_lint("\"fun(1 ,1)\"", NULL, linter)
expect_lint("a[1, , 2]", NULL, linter)
expect_lint("a[1, , 2, , 3]", NULL, linter)
expect_lint("a[[1,]]", NULL, linter)
expect_no_lint('"fun(1 ,1)"', linter)
expect_no_lint("a[1, , 2]", linter)
expect_no_lint("a[1, , 2, , 3]", linter)
expect_no_lint("a[[1,]]", linter)

expect_lint("switch(op, x = foo, y = bar)", NULL, linter)
expect_lint("switch(op, x = , y = bar)", NULL, linter)
expect_lint("switch(op, \"x\" = , y = bar)", NULL, linter)
expect_lint("switch(op, x = ,\ny = bar)", NULL, linter)
expect_no_lint("switch(op, x = foo, y = bar)", linter)
expect_no_lint("switch(op, x = , y = bar)", linter)
expect_no_lint('switch(op, "x" = , y = bar)', linter)
expect_no_lint("switch(op, x = ,\ny = bar)", linter)

expect_lint("switch(op, x = foo , y = bar)", msg_before, linter)
expect_lint("switch(op, x = foo , y = bar)", msg_before, linter)
Expand All @@ -107,9 +108,10 @@ test_that("returns the correct linting (with 'allow_trailing' set)", {
expect_lint(
"fun(op ,bar)",
list(
list(message = msg_before, column_number = 7L, ranges = list(c(7L, 10L))),
list(message = msg_after, column_number = 12L, ranges = list(c(12L, 12L)))
list(msg_before, column_number = 7L, ranges = list(c(7L, 10L))),
list(msg_after, column_number = 12L, ranges = list(c(12L, 12L)))
),
linter
)
})
# nofuzz end
2 changes: 1 addition & 1 deletion tests/testthat/test-exclusions.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ test_that("it gives the expected error message when there is mismatch between mu
)
})

test_that("partial matching works for exclusions but warns if no linter found", {
test_that("partial matching works for exclusions but warns if no linter found", { # nofuzz
withr::local_dir(test_path("dummy_projects", "project"))

expect_warning(
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-expect_lint.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ test_that("single check", {
expect_success(expect_lint("1:nrow(x)", "(nrow)", seq_linter()))
})

test_that("multiple checks", {
test_that("multiple checks", { # nofuzz
expect_success(
expect_lint(file = "exclusions-test", checks = as.list(rep(lint_msg, 9L)), linters = linter, parse_settings = FALSE)
)
Expand Down Expand Up @@ -85,7 +85,7 @@ test_that("execution without testthat gives the right errors", {
expect_error(expect_lint_free(), lint_msg("expect_lint_free"))
})

test_that("lint order can be ignored", {
test_that("lint order can be ignored", { # nofuzz
linters <- list(assignment_linter(), infix_spaces_linter())
expected <- lapply(linters, \(l) list(linter = attr(l, "name")))
expect_success(expect_lint("a=1", expected, linters, ignore_order = TRUE))
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-expect_true_false_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ test_that("expect_true_false_linter skips allowed usages", {
# expect_true is a scalar test; testing logical vectors with expect_equal is OK
expect_no_lint("expect_equal(x, c(TRUE, FALSE))", linter)

expect_no_lint("expect_equal(x, y, ignore_attr = TRUE)")
expect_no_lint("expect_equal(x, y, ignore_attr = TRUE)", linter)

expect_no_lint("42 %>% expect_identical(42, ignore_attr = TRUE)", linter)
expect_no_lint("42 %>% expect_identical(42, TRUE)", linter)
Expand Down
10 changes: 5 additions & 5 deletions tests/testthat/test-function_left_parentheses_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ test_that("function_left_parentheses_linter skips allowed usages", {
expect_no_lint("base::print(blah)", linter)
expect_no_lint('base::"print"(blah)', linter)
expect_no_lint("base::print(blah, fun(1))", linter)
expect_no_lint("blah <- function(blah) { }", linter)
expect_no_lint("blah <- function(blah) { }", linter) # nofuzz
expect_no_lint("(1 + 1)", linter)
expect_no_lint("( (1 + 1) )", linter)
expect_no_lint("if (blah) { }", linter)
Expand All @@ -18,9 +18,9 @@ test_that("function_left_parentheses_linter skips allowed usages", {
expect_no_lint("c(1, 2, 3)[(2 - 1)]", linter)
expect_no_lint("list(1, 2, 3)[[(2 - 1)]]", linter)
expect_no_lint("range(10)[(2 - 1):(10 - 1)]", linter)
expect_no_lint("function(){function(){}}()()", linter)
expect_no_lint("c(function(){})[1]()", linter)
expect_no_lint("function(x) (mean(x) + 3)", linter)
expect_no_lint("function(){function(){}}()()", linter) # nofuzz
expect_no_lint("c(function(){})[1]()", linter) # nofuzz
expect_no_lint("function(x) (mean(x) + 3)", linter) # nofuzz
expect_no_lint('"blah (1)"', linter)
})

Expand Down Expand Up @@ -197,7 +197,7 @@ test_that("newline in character string doesn't trigger false positive (#1963)",
)
})

test_that("shorthand functions are handled", {
test_that("shorthand functions are handled", { # nofuzz
linter <- function_left_parentheses_linter()
fun_lint_msg <- rex::rex("Remove spaces before the left parenthesis in a function definition.")

Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-indentation_linter.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# nofuzz start
test_that("indentation linter flags unindented expressions", {
linter <- indentation_linter(indent = 2L)

Expand Down Expand Up @@ -910,3 +911,4 @@ test_that("for loop gets correct linting", {
linter
)
})
# nofuzz end
2 changes: 2 additions & 0 deletions tests/testthat/test-infix_spaces_linter.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# nofuzz start
test_that("returns the correct linting", {
ops <- c(
"+",
Expand Down Expand Up @@ -234,3 +235,4 @@ test_that("lints vectorize", {
infix_spaces_linter()
)
})
# nofuzz end
5 changes: 2 additions & 3 deletions tests/testthat/test-knitr_formats.R
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ test_that("it handles asciidoc", {
)
})

test_that("it does _not_ handle brew", {
test_that("it does _not_ handle brew", { # nofuzz
expect_lint("'<% a %>'\n",
checks = list(
regexes[["quotes"]],
Expand All @@ -131,9 +131,8 @@ test_that("it does _not_ handle brew", {
})

test_that("it does _not_ error with inline \\Sexpr", {
expect_lint(
expect_no_lint(
"#' text \\Sexpr{1 + 1} more text",
NULL,
default_linters
)
})
Expand Down
Loading
Loading