- add some type annotation

- resolve an issue with directories
This commit is contained in:
Mylloon 2023-05-29 17:17:24 +02:00
parent f04e89cf3f
commit cc24d047b4
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
2 changed files with 7 additions and 8 deletions

View file

@ -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")

View file

@ -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))