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: Ignore empty __init__.py. Closes #5 #10

Merged
merged 2 commits into from
Nov 19, 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
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