pre-commit / pre-commit-hooks

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

Handling of CR as EOL in trailing-whitespace #1066

Closed AFulgens closed 5 months ago

AFulgens commented 5 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 5 months ago

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

AFulgens commented 4 months 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 4 months ago

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