fixed line ending conversion for windows

This commit is contained in:
Christopher Pickering 2023-01-19 10:24:37 -06:00
parent 7a0a442fec
commit 64eb26be3f
No known key found for this signature in database
GPG key ID: E14DB3B0A0FACF84

View file

@ -36,7 +36,8 @@ def reformat_file(config: Config, this_file: Path) -> dict:
# preserve original line endings
line_ending = rawcode.find("\n")
if line_ending > -1 and rawcode[max(line_ending - 1, 0)] == "\r":
beautified_code = beautified_code.replace("\n", "\r\n")
# convert \r?\n to \r\n
beautified_code = beautified_code.replace("\r", "").replace("\n", "\r\n")
if config.check is not True or config.stdin is True:
this_file.write_bytes(beautified_code.encode("utf8"))