Skip to content

Commit

Permalink
feat(HIS): add cyclomatic complexity metric 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 Oct 27, 2023
1 parent fc92083 commit 1d6bdbe
Show file tree
Hide file tree
Showing 2 changed files with 23 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
23 changes: 22 additions & 1 deletion his_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,30 @@

import sys
import argparse
import os

CYCLOMATIC_THRESHOLD = 10

def process_complexity(files):

"""Process McCabe Cyclomatic Complexity for each function in a file"""

metric_fail = 0
cc_tool = "pmccabe -c "
print("== Checking McCabe Cyclomatic Complexity metric ==")
for file in files.files:
sline = os.popen(cc_tool + str(file)).read().split('\n')
for fields in [line.split('\t') for line in sline[:-1]]:
if int(fields[0]) > CYCLOMATIC_THRESHOLD:
fields[5] = fields[5][fields[5].find("src"):]
print("At " + fields[5] + " has a complexity of "+ fields[0]
+ ". The maximum is "+str(CYCLOMATIC_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_complexity]
CHECK_FAIL = 0
PARSER = argparse.ArgumentParser()
PARSER.add_argument("files", nargs="+", help="The files to process")
Expand Down

0 comments on commit 1d6bdbe

Please sign in to comment.