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 authored and danielRep committed Feb 27, 2024
1 parent 27fec24 commit 82ffe41
Showing 1 changed file with 43 additions and 7 deletions.
50 changes: 43 additions & 7 deletions his_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

import sys
import argparse
import os
import re

def process_calling(files, threshold):
"""
Expand Down Expand Up @@ -57,13 +59,47 @@ def process_level(files, threshold):

def process_param(files, threshold):
"""
Process the parameters metric
"""

print(f"Processing PARAMETERS metric with threshold [0-{threshold}] for files: \
{', '.join(files)}")

return 0
Process number of parameters in a function. This function checks each function in the provided
files for the number of parameters. If the number of parameters in a function exceeds the
defined threshold, an error message is printed and the error count is incremented.
Args:
files: A list of file paths to check for the number of parameters.
threshold: The maximum allowed number of parameters.
Returns:
The number of files that exceed the parameters threshold.
"""

metric_fail = 0
cflow = "cflow -l"

print("--------------------------------------------")
print(f"Processing PARAM metric with threshold >{threshold}")
print("--------------------------------------------")

# Process each file
for file in 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 > threshold:
print(f"At {file_path}({line_number}): {function_name} has "
f"{num_param} function parameters.")
metric_fail += 1

print("--------------------------------------------")
if metric_fail:
print("PARAM metric failed with " + str(metric_fail) + " error(s)\n")
else:
print("PARAM metric passed")

return metric_fail

def process_path(files, threshold):
"""
Expand Down

0 comments on commit 82ffe41

Please sign in to comment.