feat: Add expect_no_match rule (testthat)#368
Merged
etiennebacher merged 5 commits intoetiennebacher:mainfrom Feb 28, 2026
Merged
feat: Add expect_no_match rule (testthat)#368etiennebacher merged 5 commits intoetiennebacher:mainfrom
expect_no_match rule (testthat)#368etiennebacher merged 5 commits intoetiennebacher:mainfrom
Conversation
Pretty much a copy paste job from the expect_match linter, but I noticed a bit (impacting expect_match as well) where unnamed/positional args in grepl would be incorrectly carried over in a fix due to ignore.case being the 3rd grepl arg but not a positional arg in expect_match/no_match at all. docs: add in changelog and rules.
Ecosystem checkseasystats/datawizard: +4 -0 violationsNew violations (first 100): tests/testthat/test-data_tabulate.R[711:2]: expect_no_match -- `expect_false(grepl(...))` is not as clear as `expect_no_match(...)`. tests/testthat/test-data_tabulate.R[712:2]: expect_no_match -- `expect_false(grepl(...))` is not as clear as `expect_no_match(...)`. tests/testthat/test-data_tabulate.R[715:2]: expect_no_match -- `expect_false(grepl(...))` is not as clear as `expect_no_match(...)`. tests/testthat/test-data_tabulate.R[716:2]: expect_no_match -- `expect_false(grepl(...))` is not as clear as `expect_no_match(...)`. nlmixr2/nlmixr2est: +8 -0 violationsNew violations (first 100): tests/testthat/test-issue-281.R[48:4]: expect_no_match -- `expect_false(grepl(...))` is not as clear as `expect_no_match(...)`. tests/testthat/test-issue-281.R[51:4]: expect_no_match -- `expect_false(grepl(...))` is not as clear as `expect_no_match(...)`. tests/testthat/test-issue-281.R[55:4]: expect_no_match -- `expect_false(grepl(...))` is not as clear as `expect_no_match(...)`. tests/testthat/test-issue-281.R[57:4]: expect_no_match -- `expect_false(grepl(...))` is not as clear as `expect_no_match(...)`. tests/testthat/test-issue-281.R[59:4]: expect_no_match -- `expect_false(grepl(...))` is not as clear as `expect_no_match(...)`. tests/testthat/test-nlm.R[47:4]: expect_no_match -- `expect_false(grepl(...))` is not as clear as `expect_no_match(...)`. tests/testthat/test-nlme.R[28:4]: expect_no_match -- `expect_false(grepl(...))` is not as clear as `expect_no_match(...)`. tests/testthat/test-nls.R[21:4]: expect_no_match -- `expect_false(grepl(...))` is not as clear as `expect_no_match(...)`. ropensci/targets: +1 -0 violationsNew violations (first 100): tests/testthat/test-utils_data.R[6:2]: expect_no_match -- `expect_false(grepl(...))` is not as clear as `expect_no_match(...)`. rstudio/shiny: +1 -0 violationsNew violations (first 100): tests/testthat/test-built-files.R[9:4]: expect_no_match -- `expect_false(grepl(...))` is not as clear as `expect_no_match(...)`. |
Benchmark on real-projects
|
expect_no_match rule (testthat)
Owner
etiennebacher
left a comment
There was a problem hiding this comment.
Thanks, just a couple of nitpicks
crates/jarl-core/src/analyze/call.rs
Outdated
Comment on lines
+66
to
+68
| if checker.is_rule_enabled(Rule::ExpectNoMatch) { | ||
| checker.report_diagnostic(expect_no_match(r_expr)?); | ||
| } |
Owner
There was a problem hiding this comment.
Can you put this in alphabetical order?
crates/jarl-core/src/rule_set.rs
Outdated
Comment on lines
+356
to
+362
| ExpectNoMatch => { | ||
| name: "expect_no_match", | ||
| categories: [Testthat], | ||
| default: Disabled, | ||
| fix: Safe, | ||
| min_r_version: None, | ||
| }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Largely a copy paste job from the expect_match linter. It is not doing any handling of
!at the moment as these cases are covered by the expect_not linter.I did however discover a bug with the fix for the expect_match linter while working on this. In cases where grepl has extra args (i.e. perl, fixed, etc.) that are unnamed, the fix cannot be applied due to differences in the args and orders between grepl and expect_match.
This has been addressed for this linter by reporting the lint but no fix where unnamed additional args exist. I'll open up a separate pr to fix the expect_match linter.
Part of #214