From 07c0753a0125d3135d62a487b3e79aefd0b8ff71 Mon Sep 17 00:00:00 2001 From: disinvite Date: Sun, 10 Dec 2023 20:47:12 -0500 Subject: [PATCH] Comment markers in headers only, rename script, update github actions --- .github/workflows/order.yml | 6 +++--- .../decomplint.py} | 0 tools/isledecomp/isledecomp/parser/error.py | 3 +++ tools/isledecomp/isledecomp/parser/linter.py | 20 ++++++++++--------- tools/isledecomp/tests/test_linter.py | 12 +++++++++++ 5 files changed, 29 insertions(+), 12 deletions(-) rename tools/{checkorder/checkorder.py => decomplint/decomplint.py} (100%) diff --git a/.github/workflows/order.yml b/.github/workflows/order.yml index d7ae315c..0e0dda82 100644 --- a/.github/workflows/order.yml +++ b/.github/workflows/order.yml @@ -13,7 +13,7 @@ jobs: run: | pip install -r tools/requirements.txt - - name: Run checkorder.py + - name: Run decomplint.py run: | - python3 tools/checkorder/checkorder.py --verbose --enforce ISLE - python3 tools/checkorder/checkorder.py --verbose --enforce LEGO1 + python3 tools/decomplint/decomplint.py --enforce ISLE --module ISLE + python3 tools/decomplint/decomplint.py --enforce LEGO1 --module LEGO1 diff --git a/tools/checkorder/checkorder.py b/tools/decomplint/decomplint.py similarity index 100% rename from tools/checkorder/checkorder.py rename to tools/decomplint/decomplint.py diff --git a/tools/isledecomp/isledecomp/parser/error.py b/tools/isledecomp/isledecomp/parser/error.py index 6de98c56..58482296 100644 --- a/tools/isledecomp/isledecomp/parser/error.py +++ b/tools/isledecomp/isledecomp/parser/error.py @@ -35,6 +35,9 @@ class ParserError(Enum): # state of SEARCH UNEXPECTED_END_OF_FILE = 108 + # WARN: We found a marker to be referenced by name outside of a header file. + BYNAME_FUNCTION_IN_CPP = 109 + # This code or higher is an error, not a warning DECOMP_ERROR_START = 200 diff --git a/tools/isledecomp/isledecomp/parser/linter.py b/tools/isledecomp/isledecomp/parser/linter.py index 21666539..ea24c69c 100644 --- a/tools/isledecomp/isledecomp/parser/linter.py +++ b/tools/isledecomp/isledecomp/parser/linter.py @@ -2,13 +2,6 @@ from .error import ParserAlert, ParserError -# TODO: You get an error for each function out of order. -# Same as the verbose display but just as main line errors. -# TODO: Sort alerts by line number at the end? -# TODO: No more verbose mode. This is a linter and you get warnings always. -# TODO: --warnfail flag? - - def get_checkorder_filter(module): """Return a filter function on implemented functions in the given module""" return lambda fun: fun.module == module and not fun.lookup_by_name @@ -65,8 +58,17 @@ def _check_symbol_uniqueness(self): pass def _check_byname_allowed(self): - # TODO - pass + if self.file_is_header(): + return + + for fun in self._parser.functions: + if fun.lookup_by_name: + self.alerts.append( + ParserAlert( + code=ParserError.BYNAME_FUNCTION_IN_CPP, + line_number=fun.line_number, + ) + ) def check_lines(self, lines, filename, module=None): """`lines` is a generic iterable to allow for testing with a list of strings. diff --git a/tools/isledecomp/tests/test_linter.py b/tools/isledecomp/tests/test_linter.py index 6560e957..6fca10fb 100644 --- a/tools/isledecomp/tests/test_linter.py +++ b/tools/isledecomp/tests/test_linter.py @@ -68,3 +68,15 @@ def test_module_isolation(linter): assert linter.check_lines(lines, "test.cpp", "TEST") is True assert linter.check_lines(lines, "test.cpp", "ALPHA") is True + + +def test_byname_headers_only(linter): + """Markers that ar referenced by name with cvdump belong in header files only.""" + lines = [ + "// FUNCTION: TEST 0x1000", + "// MyClass::~MyClass", + ] + + assert linter.check_lines(lines, "test.h", "TEST") is True + assert linter.check_lines(lines, "test.cpp", "TEST") is False + assert linter.alerts[0].code == ParserError.BYNAME_FUNCTION_IN_CPP