Skip to content

Some hooks change EOL from CRLF to LF #38

@Flo3561

Description

@Flo3561

Current Behavior

If a file was CRLF it will be changed to LF.

Expected Behavior

EOL should not be changed from the original file format

Context / environment

Steps to Reproduce (for bugs)

  1. Have a repo with a file ending in CRLF
  2. run e.g. pre-commit hook twincat-leading-tabs-remover on all files
  3. Check file ending of the file which is now

Suggested Solution

Adapt the hooks to clean the output with something like

with open(filename, "r", encoding="utf-8", newline="") as f:
    original = f.read()

eol = "\r\n" if "\r\n" in original else "\n"
fixed = original.replace("\r\n", "\n")  # normalize internally
fixed = do_your_thing(fixed)
fixed = fixed.replace("\n", eol)        # restore

with open(filename, "w", encoding="utf-8", newline="") as f:
    f.write(fixed)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions