Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 8, 2025

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)


💡 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.

- Add check to require at least 2 body forms before refactoring
- Update test cases to test both multi-body (should refactor) and single-body (should not refactor) cases
- All tests pass successfully

Co-authored-by: jackfirth <[email protected]>
Copilot AI changed the title [WIP] Fix usage of #:when and #:unless in single-body loops Only apply #:when and #:unless refactoring to multi-body loops Dec 8, 2025
Copilot AI requested a review from jackfirth December 8, 2025 17: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.

Only use #:when and #:unless with multi-body loops

2 participants