fish-station/Tools/check_crlf.py
Rinary 3450799bc2
Фикс Ошибок Yaml linter, CRLF Check проекта (#109)
* Added Sound in Lobby

* Loadout Groups Locale Fix

* Может сначала укажем спрайт а потом указываем стейты с этого спрайта?

* Sprite in Icon

* Убрал лишнее из Audio

* SS13 Lobby Sound

* кто-то додумался запихнуть русские символы в название файла) Теперь git grep умирает от кодировки

* Прикольный вендомат(покупаешь за 1200, продаешь за 1290)

* backslash in file names fix

* No Cirilic in File Names
2024-06-13 16:35:57 +03:00

40 lines
No EOL
1.1 KiB
Python
Executable file

#!/usr/bin/env python3
import subprocess
import os
from typing import Iterable
def main() -> int:
any_failed = False
for file_name in get_text_files():
if is_file_crlf(file_name):
print(f"::error file={file_name},title=File contains CRLF line endings::The file '{file_name}' was committed with CRLF new lines. Please make sure your git client is configured correctly and you are not uploading files directly to GitHub via the web interface.")
any_failed = True
return 1 if any_failed else 0
def get_text_files() -> Iterable[str]:
# https://stackoverflow.com/a/24350112/4678631
process = subprocess.run(
["git", "grep", "--cached", "-Il", ""],
check=True,
encoding="utf-8",
stdout=subprocess.PIPE)
for x in process.stdout.splitlines():
yield x.strip()
def is_file_crlf(path: str) -> bool:
if '\\' in path:
print(f"File {path} contains a backslash in its name.")
return True
with open(path, "rb") as f:
for line in f:
if line.endswith(b"\r\n"):
return True
return False
exit(main())