From cc24d047b42144a27af8bd2854776e5c8e7406b4 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Mon, 29 May 2023 17:17:24 +0200 Subject: [PATCH] - add some type annotation - resolve an issue with directories --- main.py | 5 +---- src/utils.py | 10 ++++++---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/main.py b/main.py index a09ccb0..c89701d 100644 --- a/main.py +++ b/main.py @@ -6,7 +6,7 @@ from src.errors import ClangError from src.utils import analyze_args -def clang_format(file_path): +def clang_format(file_path) -> str: command = ["clang-format", "--dry-run", file_path] try: output = subprocess.check_output(command, stderr=subprocess.STDOUT, text=True) @@ -31,9 +31,6 @@ def parse_clang_format_output(output) -> list[ClangError]: ) error_matches = re.finditer(error_pattern, output) - if not error_matches: - return [] - errors = [] for error_match in error_matches: filename = error_match.group("filename") diff --git a/src/utils.py b/src/utils.py index fddd1e3..9f14f88 100644 --- a/src/utils.py +++ b/src/utils.py @@ -2,7 +2,7 @@ import os import sys -def analyze_args(args: list): +def analyze_args(args: list) -> list[str]: """Renvoie la liste des fichiers""" if len(args) > 1: print("Trop d'arguments renseignés.", file=sys.stderr) @@ -24,13 +24,15 @@ def analyze_args(args: list): return files -def check_ext(filename: str): +def check_ext(filename: str) -> bool: """Vérifie qu'un fichier est supporté en se basant sur son extension""" supported_exts = ".c" return filename.endswith(supported_exts) -def iterate_over_directory(dirname: str): +def iterate_over_directory(dirname: str) -> list[str]: """Trouve tout les fichiers d'un dossier""" - return next(os.walk(dirname))[2] + files = next(os.walk(dirname))[2] + + return list(map(lambda file: os.path.join(dirname, file), files))