resyntax icon indicating copy to clipboard operation
resyntax copied to clipboard

Lint for `with-output-to-string`

Open jackfirth opened this issue 1 year ago • 1 comments

#lang resyntax/test

test: "with-output-to-string should be used when equivalent"
--------------------
#lang racket
(define (f)
  (define os (open-output-string))
  (parameterize ([current-output-port os])
    (displayln "foo")
    (get-output-string os)))
--------------------
--------------------
#lang racket
(define (f)
  (with-output-to-string (λ () (displayln "foo"))))
--------------------

This should also work for slight variations of the above that are still equivalent, like if (get-output-string os) is outside the parameterize expression.

Unfortunately, this refactoring can only work in #lang racket because in #lang racket/base it requires importing racket/string.

jackfirth avatar Nov 25 '24 22:11 jackfirth

Nit: with-output-to-string is from racket/port not racket/string

samdphillips avatar Nov 26 '24 17:11 samdphillips