Repository navigation
Fix the formatter's line endings on Windows and in CRLF files - #9042
Conversation
On Windows, bsc -format wrote its output through text-mode stdout, so every LF became CRLF: rescript format rewrote LF files to CRLF and format --check reported every LF file. Formatting a CRLF file was not stable either, on any platform: the scanner keeps the CRs inside comments, template literals and raw JS, so those lines came out as CR LF beside the printer's plain LF, and text-mode output or an editor turned them into CR CR LF, adding a blank line on each run. Formatting now reads the source with LF line endings and gives the result CRLF ones when the source's first line break is CRLF. bsc -format and res_parser -print res write stdout in binary mode, also inside a captured compiler request, and the editor format command keeps a CRLF document's line endings. With that, Windows CI runs the syntax roundtrip tests and the OCaml and ReScript format checks, whose file lists now go through xargs to stay under the Windows command-line length limit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Christoph Knittel <ck@cca.io>
Changelog🐛 Bug fix
🏠 Internal
Semantic Diff3 commits · Full page Keep each file's line endings when formatting1cbe977 · cknitt + Claude · Oct 25, 2026, 16:09 UTC On Windows, bsc -format wrote its output through text-mode stdout, so every LF became CRLF: rescript format rewrote LF files to CRLF and format --check reported every LF file. Formatting a CRLF file was not stable either, on any platform: the scanner keeps the CRs inside comments, template literals and raw JS, so those lines came out as CR LF beside the printer's plain LF, and text-mode output or an editor turned them into CR CR LF, adding a blank line on each run. Formatting now reads the source with LF line endings and gives the result CRLF ones when the source's first line break is CRLF. bsc -format and res_parser -print res write stdout in binary mode, also inside a captured compiler request, and the editor format command keeps a CRLF document's line endings. With that, Windows CI runs the syntax roundtrip tests and the OCaml and ReScript format checks, whose file lists now go through xargs to stay under the Windows command-line length limit. Expect formatted files to keep their line endings in rewatch tests88297dc · cknitt + Claude · Oct 25, 2026, 17:45 UTC The rewatch format unit tests expected formatted output to have CRLF line endings on Windows, which was the text-mode output bug. They now expect each file to keep its own line endings, and check that a formatted CRLF file passes format --check and is left unchanged by format, through the in-process formatter. ✨ Read syntax test file lists before running tests in the background25243f2 · cknitt + Claude · Oct 25, 2026, 17:56 UTC · new The syntax test script read each file list in a while loop from a file and started a background job per file. Under MSYS on Windows that occasionally corrupted the names the loop read, so a test file was skipped, or, in the roundtrip tests now running on Windows, reported as a failure. The script now reads each list into an array before it starts any job. |
|
@codex review |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #9042 +/- ##
==========================================
+ Coverage 81.32% 81.33% +0.01%
==========================================
Files 456 457 +1
Lines 64036 64106 +70
==========================================
+ Hits 52077 52141 +64
- Misses 11959 11965 +6
🚀 New features to boost your workflow:
|
|
Codex Review: Didn't find any major issues. Swish! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
rescript
@rescript/belt
@rescript/darwin-arm64
@rescript/linux-arm64
@rescript/linux-x64
@rescript/runtime
@rescript/win32-x64
commit: |
|
Developer playground preview: https://rescript-lang.github.io/rescript/dev-playground/?version=pr-9042 |
|
@codex review |
The rewatch format unit tests expected formatted output to have CRLF line endings on Windows, which was the text-mode output bug. They now expect each file to keep its own line endings, and check that a formatted CRLF file passes format --check and is left unchanged by format, through the in-process formatter. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Christoph Knittel <ck@cca.io>
The syntax test script read each file list in a while loop from a file and started a background job per file. Under MSYS on Windows that occasionally corrupted the names the loop read, so a test file was skipped, or, in the roundtrip tests now running on Windows, reported as a failure. The script now reads each list into an array before it starts any job. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Christoph Knittel <ck@cca.io>
The formatter now keeps each file's line endings. This fixes two long-standing problems with CRLF line endings, and lets Windows CI run the syntax roundtrip test and the format checks.
Problems
1. On Windows, LF files were rewritten to CRLF.
bsc -formatwrote its output to stdout in text mode, which on Windows turns every\ninto\r\n. As a result:rescript formatrewrote LF files with CRLF line endings.rescript format --checkreported every LF file as unformatted.Both the Rust and the OCaml
rescriptuse bsc's output as it is, so both behaved this way.2. Formatting a CRLF file was not stable, on any platform. The scanner keeps the
\rcharacters inside multi-line comments, template literals and%rawas part of their content. Those lines came out as\r\n, next to the printer's plain\n. Text-mode output, or an editor converting\nto the document's CRLF, then made them\r\r\n. Each run added another blank line.This second problem has been reported several times since 2021. Each time it was closed with the workaround "switch your editor to LF":
CRLFrescript-vscode#782 Strange formatting behavior when using raw JS withCRLF(still open)Changes
Res_line_endingsmodule. Formatting reads the source with LF line endings. If the source's first line break is CRLF, the formatted result gets CRLF line endings back, so CRLF files stay CRLF.bsc -formatwrites stdout in binary mode.Compiler_request_output.write_stdout_binarywrites the bytes unchanged in both cases:rescriptformats this way, and there the captured output is otherwise converted the way a Windows text-mode stdout would.Text written before or after the binary output still gets the usual conversion.
rescript-editor-analysiskeeps a CRLF document's line endings instead of returning mixed ones.res_parser, which the syntax tests use, reads sources with LF line endings and writes its-print resoutput in binary mode.CI
format_check.shnow runs the OCaml and ReScript format checks on every platform, instead of skipping them on Windows.format_check.shandformat.shpass their file lists throughxargs, so each command stays under the Windows command-line length limit.Tests
%raw. It checks that each keeps its line endings and that a second run changes nothing.format/05-format-line-endings.sh): runsformat --checkandformaton LF and CRLF files. With text-mode output, it fails on the LF file.🤖 Generated with Claude Code