diff --git a/.github/workflows/linting.yaml b/.github/workflows/linting.yaml index 21b275c94b..f2b5576109 100644 --- a/.github/workflows/linting.yaml +++ b/.github/workflows/linting.yaml @@ -35,3 +35,6 @@ jobs: - name: Check for Unresolved Conflicts run: python ./scripts/gsrc/check-for-conflicts.py + + - name: Check for Incorrect Asserts + run: python ./scripts/ci/check-for-asserts.py diff --git a/scripts/ci/check-for-asserts.py b/scripts/ci/check-for-asserts.py new file mode 100644 index 0000000000..08847d88e4 --- /dev/null +++ b/scripts/ci/check-for-asserts.py @@ -0,0 +1,26 @@ +import glob +import re + +folders_to_check = ["common", "decompiler", "game", "goalc", "test", "tools", "lsp"] + +flagged_instances = [] + +for folder in folders_to_check: + files_to_check = glob.glob("./{}/**/*.cpp".format(folder), recursive=True) + files_to_check += glob.glob("./{}/**/*.h".format(folder), recursive=True) + for filename in files_to_check: + # Get the file contents + with open(filename, "r", encoding="utf-8") as f: + lines = f.readlines() + for i, line in enumerate(lines): + results = re.findall(r"\bassert\(", line) + if len(results) > 0: + flagged_instances.append(filename + ":" + str(i + 1)) + +if len(flagged_instances) == 0: + exit(0) + +print("Found asserts in the following files:") +for file in flagged_instances: + print(file) +exit(1)