Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: checks if files end with newline. closes #13 #15

Merged
merged 3 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions alxcheck/checks/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ def check_file_not_empty(file_path):
def check_file_ends_with_new_line(file_path):
if not check_file_not_empty(file_path):
return False
with open(file_path, "r") as f:
return f.read()[-1] == "\n"

with open(file_path, "rb") as f:
return f.readlines()[-1] == b"\n"
5 changes: 4 additions & 1 deletion alxcheck/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ def main():
sys.exit(1)
if not check_file_not_empty("README.md"):
print_file_empty("README.md")
if not check_file_ends_with_new_line("README.md"):
print_no_ending_new_line("README.md")
for root, dirs, files in os.walk("."):
# exclude virtual environment folders
for dir in dirs:
Expand All @@ -23,7 +25,8 @@ def main():
for file in files:
file_path = os.path.join(root, file)
if file_path.endswith(
(".c", ".py", ".js", ".m", ".h", ".mjs", ".jsx", ".json")
(".c", ".py", ".js", ".m", ".h",
".mjs", ".jsx", ".json")
):
if not check_file_ends_with_new_line(file_path):
if not is_empty_init_py(file_path):
Expand Down