Only apply #:when and #:unless refactoring to multi-body loops
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-testcases 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
#:whenand#:unlesswith multi-body loops</issue_title> <issue_description>Often, theunless-expression-in-for-loop-to-unless-keywordrule (and its correspondingwhen-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
whenorunlessfrom 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.