mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-03-30 02:16:52 +00:00
end_of_file_fixer: write platform native line endings
The most common setup for git is to use platform-native line endings in checkout (`core.autocrlf` set to `true`). So the eol file fixer should write native line endings.
This commit is contained in:
parent
b0f11fe246
commit
cbd515b47c
2 changed files with 6 additions and 3 deletions
|
|
@ -5,6 +5,7 @@ import os
|
|||
from typing import IO
|
||||
from typing import Sequence
|
||||
|
||||
platform_eol = os.linesep.encode('ascii')
|
||||
|
||||
def fix_file(file_obj: IO[bytes]) -> int:
|
||||
# Test for newline at end of file
|
||||
|
|
@ -18,7 +19,7 @@ def fix_file(file_obj: IO[bytes]) -> int:
|
|||
if last_character not in {b'\n', b'\r'} and last_character != b'':
|
||||
# Needs this seek for windows, otherwise IOError
|
||||
file_obj.seek(0, os.SEEK_END)
|
||||
file_obj.write(b'\n')
|
||||
file_obj.write(platform_eol)
|
||||
return 1
|
||||
|
||||
while last_character in {b'\n', b'\r'}:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue