Skip to content

Commit

Permalink
feat(HIS): added checker of a file comment density
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 Mar 6, 2024
1 parent 2a2ac26 commit da904be
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
6 changes: 4 additions & 2 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ RUN apt-get update && apt-get install -y \
tree \
vim \
nano \
device-tree-compiler
device-tree-compiler \
pmccabe

# Install python packages
RUN pip3 install \
Expand All @@ -56,7 +57,8 @@ RUN pip3 install \
pyspellchecker \
ROPgadget \
capstone \
GitPython
GitPython \
pygount

# Install javascript packages
RUN npm install -g cspell@latest
Expand Down
36 changes: 29 additions & 7 deletions his_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,35 @@ def process_calls(files, threshold):
return 0

def process_comf(files, threshold):
"""
Process the comf metric
"""

print(f"Processing COMF metric with threshold >{threshold} for files: {', '.join(files)}")

return 0
"""Process comment density within a file"""

metric_fail = 0
statements_tool = "pmccabe -c "
pmccabe_stat_index = 2
total_statements = 0
comments_tool = "pygount --format=cloc-xml "
comment_index = 21
comment_density = 0
license_comment_size = 4
print("Checking the file comment density")
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])
total_statements = total_statements + statements
lines = os.popen(comments_tool + str(file)).read().split(' ')
if lines[comment_index].startswith("comment"):
comments = int(lines[comment_index].split("=")[1].replace('"', ''))
comments = comments - license_comment_size
comment_density = comments/total_statements
if comment_density < COMMENTS_THRESHOLD:
print(f"The file {file}: has a comment density (comments/"
f"statements) of {comment_density}. The minimum is a "
f"density of {COMMENTS_THRESHOLD}")
metric_fail += 1
total_statements = 0
print("Check done with " + str(metric_fail) + " error(s)\n")
return metric_fail

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

0 comments on commit da904be

Please sign in to comment.