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 e257e16
Showing 1 changed file with 39 additions and 4 deletions.
43 changes: 39 additions & 4 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,41 @@ def process_level(files, threshold):

def process_param(files, threshold):
"""
Process the parameters metric
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.
"""

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

return 0
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

return metric_fail

def process_path(files, threshold):
"""
Expand Down Expand Up @@ -206,6 +236,11 @@ def process_v_g(files, threshold):

# Add the number of failures for the metric to the total failure count
CHECK_FAIL += metric_function(ARGS.files, val)
print("--------------------------------------------")
if CHECK_FAIL:
print(f"{metric} metric failed with {CHECK_FAIL} error(s)\n")
else:
print(f"{metric} metric passed")

# If there were any failures, exit with an error code
if CHECK_FAIL:
Expand Down

0 comments on commit e257e16

Please sign in to comment.