Skip to content

Add a fifth fuzzer for '='/'<-' equivalency - #2829

Merged
MichaelChirico merged 144 commits into
mainfrom
fuzz-assignment
Jan 17, 2026
Merged

MichaelChirico merged 144 commits into
mainfrom
fuzz-assignment

Conversation

@MichaelChirico

@MichaelChirico MichaelChirico commented Mar 10, 2025 •

Copy link
Copy Markdown
Collaborator

Closes #2191 -- these are the 5 simple (well, 4 are simple 🙃) consistency checks I came up with. Continues #2822. Progress on #2737.

Closes #2828 too.

<- in implicit assignments is a known issue generating some false positives --> nofuzz. Also assignment_linter() is used in a lot of places as a "generic simple" linter, those need nofuzz too.

@codecov

codecov Bot commented Mar 10, 2025 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.23%. Comparing base (e1859e5) to head (ba80a6d).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2829   +/-   ##
=======================================
  Coverage   99.23%   99.23%           
=======================================
  Files         128      128           
  Lines        7281     7282    +1     
=======================================
+ Hits         7225     7226    +1     
  Misses         56       56           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@MichaelChirico MichaelChirico added this to the 3.3.0 milestone Jul 29, 2025
@MichaelChirico MichaelChirico modified the milestones: 3.3.0, 3.4.0 Nov 25, 2025
Base automatically changed from fuzz-comments to main January 12, 2026 18:14
@MichaelChirico

MichaelChirico commented Jan 12, 2026 •

Copy link
Copy Markdown
Collaborator Author

Here is Gemini's review:


Prompt:

Use the R gh package (which is already installed) to

 1. read the bugs 'https://github.com/r-lib/lintr/issues/2191' and 'https://github.com/r-lib/lintr/issues/2828'. Be sure to read existing comments.
 2. read the diff of the PR 'https://github.com/r-lib/lintr/pull/2829'
 3. read the existing PR review comments for further context
 4. read the git history on this branch (you are on the checked out branch locally, and the target is 'main')
   + there are a very large number of commits on this branch. be advised that most of these commits have already been incorporated to `main` in ancestor PRs, so **Please base your final review only on the final diff from 'fuzz-assignment' to 'main'.**. The point of the exercise of reviewing all of the current commits is to be sure you see other things that might have been tried already.

With this context in hand, provide a thorough, constructive review of the pull request.

Focus on readability, and check for gaps in logic or missing tests. Could the same fix be done more readably, more robustly, or any way better? Does it fit with the
style of the package?

Extirpate any instinct to be overly polite/groveling. Pushback is welcome. Politeness in the review is not an asset -- the only goal is to have the best submitted code possible.

Response:

This PR is a great initiative to improve the consistency of lintr, especially regarding the handling of different assignment operators. The introduction of fuzz testing is a significant step towards making the linters more robust. The bug fix for repeat_linter is also a welcome addition.

Here are some specific points of feedback:

High-level comments

  1. Scope: The PR combines a new feature (assignment fuzzing), several linter fixes for consistency, and an unrelated bug fix. While they are connected through the fuzzers findings, it would be cleaner to have separate PRs for the fuzzer infrastructure and the linter fixes. However, given the exploratory nature of the fuzzing work, this approach is understandable.

  2. # nofuzz: The extensive use of # nofuzz is a bit concerning. While necessary in some cases, it might indicate that some linters are too tightly coupled to specific code structures. It would be beneficial to add a comment to each # nofuzz explaining why it is needed. This would help future developers understand the limitations of the linters and the fuzzer.

  3. XPath modifications: The changes from ancestor::expr to ancestor::* and count(expr) to count(*) - ... are clever solutions to make the XPath more general. However, they can also make the expressions harder to read and potentially less performant. It would be good to add comments to the XPath expressions explaining the rationale behind these changes. For example: "# * is used to match assignment with both <- and =".

Code-specific comments

  1. .dev/ast_fuzz_test.R:

    • The new failure reporting is a massive improvement. Using ListReporter and providing a summary of test statuses is excellent for debugging.
    • The logic for identifying invalid failures is much more robust now.
  2. R/unnecessary_nesting_linter.R:

    • The change to count(*) - count(COMMENT) - count(OP-LEFT-BRACE) - count(OP-RIGHT-BRACE) = 1 is a great way to handle comments and braces. This is a pattern that could be useful in other linters as well. It might be worth abstracting this into a helper function if its used in multiple places.
  3. R/repeat_linter.R:

    • The fix is simple and effective. Changing the XPath to select the parent expr and removing the custom range calculation simplifies the linter and makes it more robust.
  4. Tests:

    • The move from expect_lint(..., NULL, ...) to expect_no_lint(...) improves readability.
    • The addition of tests for = assignments is thorough and ensures the fixes are working as expected.

Suggestions for improvement

  1. Documentation: Add documentation for the fuzz testing framework. A short README.md in the .dev/ directory explaining how to run the fuzzer and how to add new fuzzers would be very helpful.

  2. XPath comments: As mentioned before, adding comments to the more complex XPath expressions would improve maintainability.

  3. Helper for expression counting: Consider creating a helper function for the count(*) - ... logic if its applicable to other linters. This would reduce code duplication and improve readability.

Conclusion

This is a very strong PR that significantly improves the robustness and consistency of lintr. The fuzz testing framework is a valuable addition that will help catch bugs in the future. The suggested improvements are mostly minor and focused on improving the long-term maintainability of the code.


@MichaelChirico

Copy link
Copy Markdown
Collaborator Author

We already know the issue with generic # nofuzz comments, which is deferred to the final PR in this chain: #2832.

For "It would be good to add comments to the XPath expressions explaining the rationale", I guess it means the count(expr) --> count(*) - count(...) change. Added a quick comment on that.

About a helper for 'count(*) - ...', I only see this needed in two places thus far, and the subtractand on the other one is different; I don't see a need for a helper as of now.

@MichaelChirico

Copy link
Copy Markdown
Collaborator Author

@MichaelChirico
MichaelChirico merged commit b6ad118 into main Jan 17, 2026
@MichaelChirico
MichaelChirico deleted the fuzz-assignment branch January 17, 2026 23:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error in repeat_linter with unexpected object spacing Lint consistency fuzz testing?

1 participant