format with black

This commit is contained in:
Mylloon 2023-04-18 22:27:34 +02:00
parent 1787de042b
commit 99905e6847
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

28
main.py
View file

@ -6,8 +6,7 @@ import sys
def clang_format(file_path): def clang_format(file_path):
command = ["clang-format", "--dry-run", file_path] command = ["clang-format", "--dry-run", file_path]
try: try:
output = subprocess.check_output( output = subprocess.check_output(command, stderr=subprocess.STDOUT, text=True)
command, stderr=subprocess.STDOUT, text=True)
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
output = e.output output = e.output
except FileNotFoundError as e: except FileNotFoundError as e:
@ -18,8 +17,10 @@ def clang_format(file_path):
def parse_clang_format_output(output): def parse_clang_format_output(output):
error_pattern = r"(?P<filename>.+):(?P<line_number>\d+):(?P<column_number>\d+):" + \ error_pattern = (
r" warning: code should be clang-formatted \[(?P<warning_message>.+)\]" r"(?P<filename>.+):(?P<line_number>\d+):(?P<column_number>\d+):"
+ r" warning: code should be clang-formatted \[(?P<warning_message>.+)\]"
)
error_matches = re.finditer(error_pattern, output) error_matches = re.finditer(error_pattern, output)
if error_matches: if error_matches:
@ -30,12 +31,14 @@ def parse_clang_format_output(output):
column_number = int(error_match.group("column_number")) column_number = int(error_match.group("column_number"))
warning_message = error_match.group("warning_message") warning_message = error_match.group("warning_message")
errors.append({ errors.append(
"filename": filename, {
"line_number": line_number, "filename": filename,
"column_number": column_number, "line_number": line_number,
"warning_message": warning_message[1:] "column_number": column_number,
}) "warning_message": warning_message[1:],
}
)
return errors return errors
@ -49,7 +52,8 @@ if __name__ == "__main__":
if parsed_output: if parsed_output:
for error in parsed_output: for error in parsed_output:
print( print(
f"Warning dans {error['filename']} à la ligne {error['line_number']}," + f"Warning dans {error['filename']} à la ligne {error['line_number']},"
f" caractère {error['column_number']} : {error['warning_message']}") + f" caractère {error['column_number']} : {error['warning_message']}"
)
else: else:
print("No warnings found.") print("No warnings found.")