Skip to content

Lint consistency fuzz testing? #2191

Closed

Description

@MichaelChirico

One concern I have about the consistency cleanups in this release (#2039, #2046, #2190) is there's no mechanism to ensure future improvements/new linters continue to keep "up to code" & enforce the same consistency.

One approach that seems doable is to have a GHA that fuzzes our test suite. For example, for #2190, that means:

  • Go through the suite and identify all expect_lint() calls using "function(...)" or \(...) in the content= argument (text matching should be enough, but we could also use getParseData() here...).
  • Randomly (or exhaustively?) switch all such usages to their opposite: s/function/\/g and s/\/function/g
  • Run the test suite
  • Any test failure means a linter is inconsistently handling function(...) and \(...)

Similar fuzzes could apply in the other cases:

  • Randomly swap %>% and |>
  • Randomly swap $ and @

Some exceptions will need to be carved out, e.g. for cases where intentionally only one alternative is meant to be linted, and we might need some work to make the fuzzing robust to changes in an expected lint message. But overall this approach seems pretty doable to me.

If run with randomness, I'd also run it periodically, not on push/merge, since a failure might not be caught up-front & surfacing that failure on "someone else's" PR would be bad form.

Activity

  1. added
    internals
    on Sep 19, 2023
  2. AshesITR commented on Sep 19, 2023

    @AshesITR
    Collaborator

    Interesting idea. Things to consider:

    • Lint metadata may also change, especially expected column ranges.
    • |> and %>% can't be swapped in all contexts; they also have different placeholder semantics (_ vs. .)
  3. MichaelChirico commented on Sep 19, 2023

    @MichaelChirico
    CollaboratorAuthor

    True. Let's see how relevant those turn out in practice. Another idea is to allow for a # nofuzz escape to skip certain tests if they're too onerous to accomodate.

  4. MichaelChirico commented on Oct 2, 2023

    @MichaelChirico
    CollaboratorAuthor

    we can also work on #2221 here by fuzzing the lint metadata & making sure tests fail.

  5. MichaelChirico commented on Dec 8, 2023

    @MichaelChirico
    CollaboratorAuthor

    Another idea for the fuzz/metatesting suite, based on #2402 -- inject comments in random places in the test code and ensure the linters keep working. Have to exclude linters where <COMMENT> is meaningful, of course.

  6. AshesITR commented on Jul 27, 2025

    @AshesITR
    Collaborator

    Another fuzzer idea: swap =, <- and ->, and maybe the double-assignment arrows.

  7. IndrajeetPatil commented on Jul 27, 2025

    @IndrajeetPatil
    Contributor

    Of interest: there is also a new package for mutation testing in R (https://jakubsobolewski.com/muttest/)

  8. MichaelChirico commented on Jul 28, 2025

    @MichaelChirico
    CollaboratorAuthor

    One problem with -> is it doesn't share operator precedence rules with <- (edit: that's not precisely true, it's something else about the parser that causes this, but the effect is the same), hence the need to ()-wrap here:

    (function(x) {
      x
    }) -> foo

    It will also require a tiny bit of ingenuity to swap the AST entries vs. the simple cases like @↔️$, but comment injection was similarly nontrivial.

    We can try it out and if there's too much nofuzz required we can give it up.

  9. Bisaloo commented on Jul 28, 2025

    @Bisaloo
    Collaborator

    Another potential fuzzer: modify string formats. Switching ' to " and try raw strings.

    Linters that correctly use get_r_string() should pass fine but maybe we are missing cases where it should be used.

  10. MichaelChirico commented on Jul 28, 2025

    @MichaelChirico
    CollaboratorAuthor

    oh that's a really good one

  11. changed the title [-]Consistency fuzz testing?[/-] [+]Lint consistency fuzz testing?[/+] on Dec 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    automation 🤖internalstesting

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions