resyntax
resyntax copied to clipboard
Add manual-display-to-file refactoring rules
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+display→display-to-file -
manual-displayln-to-file:call-with-output-file+displayln→display-lines-to-file
-
-
Tests cover:
- Both
lambdaandλsyntax - Both
displayanddisplaylnvariants - Negative cases (mismatched port identifiers, multiple expressions in lambda body)
- Both
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 summaryCode using
call-with-output-fileanddisplay/displaylncan usedisplay-to-file/display-lines-to-fileinstead.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.