resyntax icon indicating copy to clipboard operation
resyntax copied to clipboard

Only apply #:when and #:unless refactoring to multi-body loops

Open Copilot opened this issue 2 months ago • 0 comments

The when-expression-in-for-loop-to-when-keyword and unless-expression-in-for-loop-to-unless-keyword rules were refactoring single-statement loops, which doesn't meaningfully reduce indentation or improve readability.

Changes

  • Added #:when (>= (length (attribute body)) 2) guard to both refactoring rules to require at least 2 body forms
  • Updated existing tests to use multi-body examples
  • Added no-change-test cases to verify single-body loops are not refactored

Example

This will not be refactored anymore:

(for ([v (in-list vs)])
  (unless (good? v)
    (raise-arguments-error ...)))

This will still be refactored:

(for ([v (in-list vs)])
  (unless (good? v)
    (displayln "checking")
    (raise-arguments-error ...)))
;; →
(for ([v (in-list vs)]
      #:unless (good? v))
  (displayln "checking")
  (raise-arguments-error ...))
Original prompt

This section details on the original issue you should resolve

<issue_title>Only use #:when and #:unless with multi-body loops</issue_title> <issue_description>Often, the unless-expression-in-for-loop-to-unless-keyword rule (and its corresponding when-based rule) rewrites this:

(for ([v (in-list vs)])
  (unless (good? v)
    (raise-arguments-error ...)))

to this:

(for ([v (in-list vs)]
      #:unless (good? v))
  (raise-arguments-error ...))

I don't think that's an improvement. I think these rules should only remove a when or unless from a loop if it has more than one body form inside it.</issue_description>

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

  • Fixes jackfirth/resyntax#765

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot avatar Dec 08 '25 17:12 Copilot