Skip to content

Commit

Permalink
added comment checker
Browse files Browse the repository at this point in the history
  • Loading branch information
cophilot committed Mar 6, 2024
1 parent a6f20a4 commit acc227b
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/check_rust_quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ jobs:
steps:
- uses: actions/checkout@v2

- name: Check for missing comments
run: ./scripts/comment:check

- name: Check formating
run: ./scripts/format:check

Expand Down
3 changes: 3 additions & 0 deletions scripts/comment:check
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

python scripts/py/check_comment.py
58 changes: 58 additions & 0 deletions scripts/py/check_comment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import os

DIRECTORY = ["./src"]

FILE_TYPES = ["rs"]

def main():
print("Checking for missing comments...")
print()
error_detected = False
for dir in DIRECTORY:
if not check_dir(dir):
error_detected = True
if error_detected:
exit(1)
print("No missing comments found!")

def check_dir(directory):
return_value = True

files = os.listdir(directory)
for file in files:
if os.path.isdir(os.path.join(directory, file)):
if not check_dir(os.path.join(directory, file)):
return_value = False
else:
if not check_file(os.path.abspath(os.path.join(directory, file))):
return_value = False
return return_value

def check_file(file):
if not (file.split(".")[-1] in FILE_TYPES):
return True
return_value = True
with open(file, "r") as f:
lines = f.readlines()
for i in range(0, len(lines)):
line = lines[i]
if line.strip().startswith("//") or line.strip().startswith("/*") or line.strip().startswith("*") or line.strip().startswith("*/"):
continue
if not "fn" in line.split(" ") and not "struct" in line.split(" "):
continue
if i == 0:
return_value = False
print_error(file, i + 1)
continue
line_before = lines[i - 1]
if (not "///" in line_before):
return_value = False
print_error(file, i + 1)
return return_value

def print_error(file, line):
path = os.path.abspath(file)
print(f"Missing Comment: {path}, line {str(line)}")

if __name__ == "__main__":
main()

0 comments on commit acc227b

Please sign in to comment.