Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 12, 2025

Implementing support for warning-only refactoring rules (rules that can warn without fixing).

Plan:

  • Explore codebase structure
  • Extend define-refactoring-rule to support warning-only rules
  • Update refactoring-rule object type to track fix availability
  • Modify refactoring-result to support warning-only results
  • Update refactoring-rules-refactor to handle warning-only rules
  • Filter out warning-only results in resyntax fix command
  • Update CLI output and GitHub integration
  • Add tests for warning-only rules
  • Update test infrastructure to support comment-only-test
  • Address code review feedback (API improvements)
  • Return #t instead of (void) for no-suggestion rules
  • Run existing tests to ensure no regressions

Summary:
Successfully implemented complete support for warning-only refactoring rules with improved API based on code review feedback.

API:

  1. refactoring-rule-suggestion-count returns exact-nonnegative-integer? (0 for no suggestions, 1 for one suggestion, extensible to multiple)
  2. Use #:no-suggestion keyword as the replacement template position for warning-only rules
  3. No-suggestion rules return #t when pattern matches (instead of void)

Example Usage:

(define-refactoring-rule equality-check-against-self
  #:description "Comparing a value to itself always returns true"
  #:literals (equal?)
  (equal? a:id a2:id)
  #:when (free-identifier=? (attribute a) (attribute a2))
  #:no-suggestion)

All tests pass.

Original prompt

This section details on the original issue you should resolve

<issue_title>Allow rules to warn without fixing</issue_title>
<issue_description>Currently, Resyntax will only comment on issues where it can produce a single unambiguous fix that resolves that issue. But some issues, such as the one mentioned in #483, are easy to detect but have no obvious fix. Resyntax should support writing such rules and including their warnings in resyntax analyze.

Several changes need to be made to support this. First, define-refactoring-rule should be extended with an option for declaring rules without fixes. Here's one possible syntax:

(define-refactoring-rule dont-do-that
  #:description "Don't do that"
  #:suggested-fixes none
  (bad-thing))

That is, there would be a #:suggested-fixes option which can take on the values none or one, and which defaults to one. Making the value a symbol (matched by datum) instead of a boolean makes it easy to extend this in the future to rules which offer a choice among multiple possible fixes.

The representation of refactoring rules and warnings would need to be updated to accommodate warnings that do not include suggested fixes. This would probably amount to resyntax analyze adjusting how it displays results to allow for results without fixes, and resyntax fix filtering out results to only those which have a suggested fix.

The resyntax/test language would need to be updated too. Currently it has no mechanism to test that a refactoring rule produces a result without checking that the result actually changes the input code. One possible approach could be to add a comment-only-test statement which uses options to assert that Resyntax comments on the code without changing it. Here's a possible syntax:

comment-only-test: "duplicate equality comparison"
---
(define a 5)
(equal? a a)
---
@inspect - (equal? a a)
@assertMatch equality-check-against-self

This would work similarly to the analysis-test statement, in that it would use @inspect (and optionally @within) to specify a subexpression to make assertions on. The assertion checks that a rule with a specific name warns about that subexpression without suggesting any fixes to it.</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Add support for rules to warn without fixing Add support for warning-only refactoring rules Nov 12, 2025
Copilot AI requested a review from jackfirth November 12, 2025 17:50
Copilot finished work on behalf of jackfirth November 12, 2025 17:50
@jackfirth jackfirth marked this pull request as ready for review November 12, 2025 19:25
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resyntax analyzed 10 files in this pull request and has added suggestions.

@coveralls
Copy link

coveralls commented Nov 12, 2025

Coverage Status

coverage: 93.268% (-0.4%) from 93.661%
when pulling f514b0f on copilot/add-warning-rule-support
into ef1a5e9 on master.

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resyntax analyzed 10 files in this pull request and has added suggestions.

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resyntax analyzed 10 files in this pull request and has added suggestions.

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resyntax analyzed 10 files in this pull request and found no issues.

Copy link
Owner

@jackfirth jackfirth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- Changed `refactoring-rule-suggested-fixes` to `refactoring-rule-suggestion-count` returning exact-nonnegative-integer
- Replaced `#:suggested-fixes 'none` parameter with `#:no-suggestion` keyword as replacement template
- Updated all test files to use new API
- Tests pass

Co-authored-by: jackfirth <[email protected]>
Copilot AI requested a review from jackfirth November 13, 2025 07:07
Copilot finished work on behalf of jackfirth November 13, 2025 07:08
Copy link
Owner

@jackfirth jackfirth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When a rule uses #:no-suggestion, the transformer now returns (present #t)
instead of (present #'(void)) for pattern matches.

Co-authored-by: jackfirth <[email protected]>
Copilot AI requested a review from jackfirth November 13, 2025 08:17
Copilot finished work on behalf of jackfirth November 13, 2025 08:17
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.

Allow rules to warn without fixing

3 participants