Skip to content

Commit

Permalink
feat(HIS): add number of function parameters check to script
Browse files Browse the repository at this point in the history
Signed-off-by: Afonso Santos <[email protected]>
  • Loading branch information
AfonsoSantos96 committed Nov 10, 2023
1 parent 2c77837 commit a99acac
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion his_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,37 @@

import sys
import argparse
import os
import re

PARAMETERS_THRESHOLD = 5

def process_parameters(files):

"""Process the number of function parameters."""

metric_fail = 0
cflow = "cflow -l --depth=1"
print("Checking the number of function parameters")
for file in files.files:
with os.popen(f"{cflow} {file}") as pipe:
lines = pipe.read()
pattern = r'\{.*?\} (\w+)\(.*?\(([^)]*)\) at ([^:]+):(\d+)'
matches = re.findall(pattern, lines)
for function_name, parameters, file_path, line_number in matches:
parameters = \
[param.strip() for param in parameters.split(',') if param.strip()]
num_param = len(parameters)
if num_param > PARAMETERS_THRESHOLD:
print(f"At {file_path}({line_number}): {function_name} has "
f"{num_param} function parameters. Functions must only "
f"have a maximum of {PARAMETERS_THRESHOLD} parameters.")
metric_fail += 1
print(f"Check done with {metric_fail} error(s)\n")
return metric_fail

if __name__ == "__main__":
METRICS_LIST = []
METRICS_LIST = [process_parameters]
CHECK_FAIL = 0
PARSER = argparse.ArgumentParser()
PARSER.add_argument("files", nargs="+", help="The files to process")
Expand Down

0 comments on commit a99acac

Please sign in to comment.