sorawee / fmt

A code formatter for Racket
Other
72 stars 6 forks source link

Carriage return breaking formatting #41

Closed cassanof closed 1 year ago

cassanof commented 1 year ago

Hello, Windows' way of inserting line breaks ("\n\r") creates a problem in the formatter. Here is a link to a file formatted using this style: https://gist.github.com/d2db686a7ad030ecb7a0524bd890ed98

the input file contains:

;; blah

;; MyStruct : String [List-of String]
(define-struct MyStruct [key rest])

;; AnotherStruct : MyStruct [List-of String]
(define-struct World [mystruct tried completed])

and raco fmt outputs

;; blah

;; MyStruct : String [List-of Strin
(define-struct MyStruct [key rest])

])

;; AnotherStruct : MyStruct [List-of St
(define-struct World [mystruct tried completed])

which is broken code.

sorawee commented 1 year ago

Thanks for the report!

I can reproduce the issue when running fmt on the file in Mac OS.

Do you know what will happen when you run fmt on the file in Windows? Does it produce a malformed output too? I don't have Windows installed, so I can't test it out.

sorawee commented 1 year ago

My fix above makes fmt work correctly on the mentioned file when run on Mac OS. But since I run on Mac OS, the formatted file doesn't retain CRLF. I think if fmt is run on Windows, CRLF will be preserved however (but correct me if I'm wrong -- again, I don't have Windows, so I can't test it).

It remains a question whether this behavior is desirable -- perhaps there should be an option to preserve CRLF? In any case, I think the original issue is now fixed. It no longer produces a malformed program.