Skip to content

Commit

Permalink
Add script to verify formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
MonsterDruide1 committed Oct 14, 2023
1 parent 4a231bb commit ca40c9b
Showing 1 changed file with 85 additions and 0 deletions.
85 changes: 85 additions & 0 deletions tools/check-format.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/usr/bin/env python3

import argparse
from setup import get_build_dir
import subprocess
import os
import re
from common import setup_common as setup

# ------
# CHECKS
# ------

issueFound = False

def FAIL(message, line, path):
print("Offending file:", path)
print("Line:", line)
print(message)
print()
global issueFound
issueFound = True

def CHECK(cond, line, message, path):
if not cond(line):
FAIL(message, line, path)
return True
return False


# Common


# Header files


# Source files


# -----
# UTILS
# -----

def check_source(c, path):
return

def check_header(c, path):
return

def check_file(file_str):
file = open(file_str, mode="r")
content = file.read()
file.close()

if file_str.endswith('.h'):
check_header(content, file_str)
elif file_str.endswith('.cpp'):
check_source(content, file_str)
else:
FAIL("Must only contain .h and .cpp files!", "NOT APPLICABLE", file_str)


project_root = setup.ROOT

def main():
parser = argparse.ArgumentParser(
'check-format.py', description="Verify additional formatting options next to clang-format and clang-tidy")
parser.add_argument('--verbose', action='store_true',
help="Give verbose output")
args = parser.parse_args()

for dir in [project_root/'lib'/'al', project_root/'src']:
for root, _, files in os.walk(dir):
for file in files:
file_path = os.path.join(root, file)
file_str = str(file_path)
check_file(file_str)

if issueFound:
exit(1)
else:
print("No issues found!")

if __name__ == "__main__":
main()

0 comments on commit ca40c9b

Please sign in to comment.