From e4d86a4c46f0bf5a8ab236f2494513f8162f0a02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bern=C3=A1t=20G=C3=A1bor?= Date: Fri, 30 Jan 2026 00:28:09 -0800 Subject: [PATCH] Force LF line endings when writing files Use newline='\n' in write_text() to prevent Windows from converting LF to CRLF. Fixes tox-dev/toml-fmt#99 --- src/toml_fmt_common/__init__.py | 2 +- tests/test_app.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/toml_fmt_common/__init__.py b/src/toml_fmt_common/__init__.py index 7762970..2c28b78 100644 --- a/src/toml_fmt_common/__init__.py +++ b/src/toml_fmt_common/__init__.py @@ -264,7 +264,7 @@ def _handle_one(info: TOMLFormatter[T], config: _Config[T]) -> bool: return changed if before != formatted and not config.check: - config.toml_filename.write_text(formatted, encoding="utf-8") + config.toml_filename.write_text(formatted, encoding="utf-8", newline="\n") if config.no_print_diff: return changed try: diff --git a/tests/test_app.py b/tests/test_app.py index ba31ccd..f468e54 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -279,3 +279,14 @@ def test_dumb_path_no_write(capsys: pytest.CaptureFixture[str], tmp_path: Path) out, err = capsys.readouterr() assert "\ntoml-fmt-common: error: argument inputs: cannot write path\n" in err assert not out + + +def test_writes_lf_line_endings(tmp_path: Path) -> None: + dumb = tmp_path / "dumb.toml" + dumb.write_text("") + + run(Dumb(), ["E", str(dumb)]) + + raw = dumb.read_bytes() + assert b"\r\n" not in raw + assert b"\n" in raw