Skip to content

Commit

Permalink
Merge pull request #10 from adobki/main
Browse files Browse the repository at this point in the history
FIX: Ignore empty __init__.py. Closes #5
  • Loading branch information
Emmo00 committed Nov 19, 2023
2 parents 6f53419 + 2031509 commit aa09c96
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion alxcheck/checks/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def check_file_not_empty(file_path):
return True


def check_file_ends_with_new_lines(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:
Expand Down
7 changes: 4 additions & 3 deletions alxcheck/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ def main():
if file_path.endswith(
(".c", ".py", ".js", ".m", ".h", ".mjs", ".jsx", ".json")
):
if not check_file_ends_with_new_lines(file_path):
print_no_ending_new_line(file_path)
if not check_file_ends_with_new_line(file_path):
if not is_empty_init_py(file_path):
print_no_ending_new_line(file_path)
# c and c header files
if file.endswith((".c", ".h")):
betty_check(file_path)
# python checks
if file_path.endswith(".py"):
if file_path.endswith(".py") and not is_empty_init_py(file_path):
if not check_file_is_executable(file_path):
print_file_not_executable(file_path)
if file != "__init__.py" and not check_python_shebang(file_path):
Expand Down
6 changes: 3 additions & 3 deletions alxcheck/tests/test_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from ..checks import (
check_file_present,
check_file_not_empty,
check_file_ends_with_new_lines,
check_file_ends_with_new_line,
)


Expand All @@ -26,11 +26,11 @@ def test_readme_not_empty_check(self):
def test_files_with_new_line_check(self):
f = open("file", "w")
f.close()
self.assertFalse(check_file_ends_with_new_lines("file"))
self.assertFalse(check_file_ends_with_new_line("file"))
f = open("file", "wb")
f.write(b"line\n\n")
f.close()
self.assertTrue(check_file_ends_with_new_lines("file"))
self.assertTrue(check_file_ends_with_new_line("file"))


if __name__ == "__main__":
Expand Down
9 changes: 9 additions & 0 deletions alxcheck/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,12 @@ def is_nodejs_project():
if switch in sys.argv:
return True
return False


def is_empty_init_py(file_path):
"""Checks if file is empty __init__.py"""
if file_path.endswith('__init__.py'):
from ..checks.general import check_file_not_empty
if not check_file_not_empty(file_path):
return True
return False

0 comments on commit aa09c96

Please sign in to comment.