Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 14, 2025

Detects manual file I/O patterns using call-with-output-file with display/displayln and suggests the more concise display-to-file/display-lines-to-file functions.

Changes

  • Two new refactoring rules in file-io-suggestions.rkt:

    • manual-display-to-file: call-with-output-file + displaydisplay-to-file
    • manual-displayln-to-file: call-with-output-file + displaylndisplay-lines-to-file
  • Tests cover:

    • Both lambda and λ syntax
    • Both display and displayln variants
    • Negative cases (mismatched port identifiers, multiple expressions in lambda body)

Example

Before:

(define (f path s)
  (call-with-output-file path
    (lambda (out)
      (displayln s out))))

After:

(define (f path s)
  (display-lines-to-file (list s) path))
Original prompt

This section details on the original issue you should resolve

<issue_title>New rule: manual-display-to-file</issue_title>
<issue_description>### Rule summary

Code using call-with-output-file and display / displayln can use display-to-file / display-lines-to-file instead.

Test case

#lang resyntax/test

test: "original code should be refactorable to new code"
--------------------
#lang racket
(define (f path s)
  (call-with-output-file path
    (lambda (out)
      (displayln s out))))
====================
#lang racket
(define (f path s)
  (display-lines-to-file (list s) path))
--------------------

</issue_description>

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


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Add new rule for manual display to file refactoring Add manual-display-to-file refactoring rules Nov 14, 2025
Copilot AI requested a review from jackfirth November 14, 2025 17:25
Copilot finished work on behalf of jackfirth November 14, 2025 17:25
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.

New rule: manual-display-to-file

2 participants