Add targeted rule suppression with resyntax-suppress
Refactoring suggestions sometimes make sense generally but break intentional code patterns (e.g., visual symmetry in comparisons). Users currently must repeatedly ignore autofixer PRs for these cases.
Changes
-
Added
resyntax-suppressmacro (base.rkt)- Accepts rule name and body expressions
- Propagates
resyntax-suppressed-rulessyntax property through entire syntax tree - Property preserved through macro expansion
-
Updated refactoring engine (
main.rkt)- Check for suppressed rules before applying refactorings
- Skip refactoring when rule is suppressed for syntax object
-
Documentation (
main.scrbl)- New subsection with usage examples
- Exported
syntax-suppresses-rule?for programmatic checks
Usage
#lang racket/base
(require resyntax/base)
;; Maintain visual symmetry - suppress specific comparisons
(resyntax-suppress comparison-of-difference-and-zero-to-direct-comparison
(cond
[(= (- x y) 0) "equal"]
[(> (- x y) 0) "greater"] ; Won't suggest (> x y)
[(< (- x y) 0) "less"])) ; Won't suggest (< x y)
;; Suppression is rule-specific - other rules still apply
(resyntax-suppress nested-or-to-flat-or
(and 1 (and 2 3))) ; Still suggests (and 1 2 3)
Rule names are shown in brackets when running resyntax analyze.
Original prompt
This section details on the original issue you should resolve
<issue_title>Targeted suggestion suppression</issue_title> <issue_description>Sometimes a suggestion from Resyntax makes sense generally, but is unhelpful in a specific context. See this comment for an example. Currently, this situation requires users to repeatedly ignore Autofixer pull requests that try to fix the issue they don't care about. Usually in this situation I prefer to just get rid of the suggestion entirely, or otherwise rework it so that it only targets the high-value cases. I don't see a way to do that with the linked issue, since it's very dependent on the surrounding context.
As a last resort, Resyntax may need to provide a way to handle these sorts of issues. I can think of a few approaches:
- Make the autofixer somehow magically "just know" that a suggestion shouldn't be made because it's been made before and was disregarded.
- Add a way to annotate code that suppresses refactoring rules for that code alone, e.g.
(resyntax-suppress zero-comparison-to-positive? (some-code ...)).- Add a way to annotate packages or collections to suppress refactoring rules for that entire package or collection, e.g. in an
info.rktfile.- Add a way for refactoring rules to inspect their surrounding context, so that the
zero-comparison-to-positive?rule can see that a>or<form is being used alongside a=form like in the example from the comment above. Then that rule could silence itself in cases where it would break "visual symmetry".</issue_description>Comments on the Issue (you are @copilot in this section)
- Fixes jackfirth/resyntax#436
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.