Skip to content

Commit

Permalink
feat(HIS): added checker of number of statements 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 9, 2023
1 parent 2c77837 commit 91bfb45
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ RUN apt-get update && apt-get install -y \
clang-tidy-$CLANG_VERSION \
nodejs \
npm \
pmccabe \
enchant-2 && \
pip3 install gitlint && \
pip3 install license-expression && \
Expand Down
26 changes: 25 additions & 1 deletion his_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,33 @@

import sys
import argparse
import os

STATEMENTS_THRESHOLD = 50

def process_statements(files):

"""Process number of statements in a function"""

metric_fail = 0
pmccabe_stat_index = 2
function_index = 5
statements_tool = "pmccabe -c "
print("Checking the number of statements in each function")
for file in files.files:
sline = os.popen(statements_tool + str(file)).read().split('\n')
for fields in [line.split('\t') for line in sline[:-1]]:
statements = int(fields[pmccabe_stat_index])
if statements > STATEMENTS_THRESHOLD:
function_name = fields[function_index]
print("At " + function_name + " function has " + str(statements) +
" statements. The maximum is " + str(STATEMENTS_THRESHOLD))
metric_fail += 1
print("Check done with " + str(metric_fail) + " error(s)\n")
return metric_fail

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

0 comments on commit 91bfb45

Please sign in to comment.