diff --git a/alxcheck/checks/general.py b/alxcheck/checks/general.py index df6f122..b34f145 100644 --- a/alxcheck/checks/general.py +++ b/alxcheck/checks/general.py @@ -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: diff --git a/alxcheck/main.py b/alxcheck/main.py index 6f87158..57f8a84 100644 --- a/alxcheck/main.py +++ b/alxcheck/main.py @@ -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): diff --git a/alxcheck/tests/test_general.py b/alxcheck/tests/test_general.py index 8644739..df29c01 100644 --- a/alxcheck/tests/test_general.py +++ b/alxcheck/tests/test_general.py @@ -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, ) @@ -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__": diff --git a/alxcheck/utils/helpers.py b/alxcheck/utils/helpers.py index 0ae68fc..e891500 100644 --- a/alxcheck/utils/helpers.py +++ b/alxcheck/utils/helpers.py @@ -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