Skip to content

Commit

Permalink
Merge pull request #15 from samdoghor/main
Browse files Browse the repository at this point in the history
fix: checks if files end with newline. closes #13
  • Loading branch information
Emmo00 committed Nov 30, 2023
2 parents 7791568 + cddca05 commit 93a4834
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
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

0 comments on commit 93a4834

Please sign in to comment.