pre-commit / pre-commit-hooks

Some out-of-the-box hooks for pre-commit
MIT License
5.2k stars 694 forks source link

Handling of CR as EOL in trailing-whitespace #1066

Closed AFulgens closed 2 months ago

AFulgens commented 2 months ago

Currently the trailing-whitespace hook (trailing_whitespace_fixer.py) handles the end-of-line (EOL) combinations of:

However, files that use CR as EOL are handled incorrectly by the hook, and in combanation with EOF-Fixer (end_of_file_fixer.py) this makes it impossible to commit the file if both hooks are active, because:

(Or the other way around, depending on order of the hooks.)

Current workarounds:

Question: Would it be OK to handle \r the same way \n and \r\n are handled in trailing_whitespace_fixer.py? If yes, I'll gladly prepare a PR.

asottile commented 2 months ago

it's been decades since anything used cr as eol. it is unsupported intentionally

AFulgens commented 1 month ago

I guess, we are the only team in the world then working on legacy software, which is generating XMLs with CR as EOL and we must parse it in modern codebase, and thus have tests for it. Nevertheless, I appreciate your answer, onto the exclude list with those test XMLs for this hook! 🏴‍☠️

asottile commented 1 month ago

if you have generated files you probably don't want to lint them anyway