-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
49 additions
and
271 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# https://git-scm.com/docs/gitignore | ||
# https://www.atlassian.com/ru/git/tutorials/saving-changes/gitignore | ||
|
||
# Игнорируем папки, которые создаёт VS Code | ||
/.vscode/ | ||
/build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Удаляет пробелы в конце строк | ||
|
||
import os | ||
|
||
|
||
def get_newline(file_path): | ||
with open(file_path, 'rb') as file: | ||
content = file.read() | ||
|
||
if b'\r\n' in content: | ||
return '\r\n' | ||
else: | ||
return '\n' | ||
|
||
|
||
def remove_trailing_spaces(file_path): | ||
with open(file_path, 'r', encoding='utf-8') as file: | ||
lines = file.readlines() | ||
|
||
# Сохраняем формат разделителя строк | ||
nel = get_newline(file_path) | ||
|
||
with open(file_path, 'w', encoding='utf-8', newline=nel) as file: | ||
for line in lines: | ||
file.write(line.rstrip() + '\n') | ||
|
||
|
||
if __name__ == '__main__': | ||
repo_dir = os.path.dirname(os.path.realpath(__file__)) | ||
exts = {'.bat', '.sh', '.md', '.hpp', '.cpp', '.txt', '.py', '.yml', '.editorconfig', '.gitattributes', '.gitignore'} | ||
|
||
for root, dirs, files in os.walk(repo_dir): | ||
if '.git' in dirs: # Не заходим в папку .git | ||
dirs.remove('.git') | ||
|
||
for file in files: | ||
if any(file.endswith(ext) for ext in exts): | ||
file_path = os.path.join(root, file) | ||
remove_trailing_spaces(file_path) | ||
print('Обработан файл: ' + file_path) |