resyntax icon indicating copy to clipboard operation
resyntax copied to clipboard

Add manual-display-to-file refactoring rules

Open Copilot opened this issue 3 months ago • 0 comments

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)

  • Fixes jackfirth/resyntax#673

✨ 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 avatar Nov 14 '25 17:11 Copilot