-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Matheus Castello <[email protected]>
- Loading branch information
1 parent
dcc84ee
commit e887537
Showing
2 changed files
with
64 additions
and
2 deletions.
There are no files selected for viewing
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,61 @@ | ||
#!/usr/bin/env xonsh | ||
|
||
# Copyright (c) 2025 Toradex | ||
# SPDX-License-Identifier: MIT | ||
|
||
## | ||
# This script is used to check if all the files have a new line at the end. | ||
# WARNING: | ||
# This script is not meant to be run manually. It's make part of the internal | ||
# validation process from CI/CD. | ||
## | ||
|
||
# use the xonsh environment to update the OS environment | ||
$UPDATE_OS_ENVIRON = True | ||
# always return if a cmd fails | ||
$RAISE_SUBPROC_ERROR = True | ||
|
||
import os | ||
import sys | ||
|
||
|
||
def check_new_line(file_path): | ||
with open(file_path, 'rb') as f: | ||
f.seek(-1, os.SEEK_END) | ||
last_char = f.read(1) | ||
return last_char == b'\n' | ||
|
||
|
||
ignore_folders = [ | ||
".git", | ||
"node_modules", | ||
"id_rsa", | ||
"css", | ||
"obj", | ||
"target", | ||
".mypy", | ||
"egg-info" | ||
] | ||
|
||
error_reach = False | ||
|
||
for root, dirs, files in os.walk('.'): | ||
dirs[:] = [d for d in dirs if d not in ignore_folders] | ||
for file in files: | ||
file_path = os.path.join(root, file) | ||
|
||
if any(ig in file_path for ig in ignore_folders): | ||
continue | ||
|
||
mime_type = $(file --mime-type -b @(file_path)).strip() | ||
if mime_type.startswith('text/') or mime_type in {'application/javascript', 'application/json'}: | ||
if not check_new_line(file_path): | ||
print(f"❌ :: {file_path}", file=sys.stderr) | ||
error_reach = True | ||
|
||
if error_reach: | ||
print("\n❌ :: Files are missing new line at the end\n", file=sys.stderr) | ||
sys.exit(404) | ||
else: | ||
print("\n✅ :: All files have new line at the end\n") | ||
sys.exit(0) |