mirror of
https://github.com/isledecomp/isle.git
synced 2026-01-24 08:41:16 +00:00
Type hints, working test for byname ignore
This commit is contained in:
parent
38b44e1246
commit
70f2a672ee
@ -1,5 +1,5 @@
|
||||
from __future__ import annotations # python <3.10 compatibility
|
||||
from enum import Enum
|
||||
from typing import Optional
|
||||
from dataclasses import dataclass
|
||||
|
||||
|
||||
@ -62,7 +62,7 @@ class ParserError(Enum):
|
||||
class ParserAlert:
|
||||
code: ParserError
|
||||
line_number: int
|
||||
line: str | None = None
|
||||
line: Optional[str] = None
|
||||
|
||||
def is_warning(self) -> bool:
|
||||
return self.code.value < ParserError.DECOMP_ERROR_START.value
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
from typing import List, Optional
|
||||
from .parser import DecompParser
|
||||
from .error import ParserAlert, ParserError
|
||||
|
||||
@ -8,11 +9,11 @@ def get_checkorder_filter(module):
|
||||
|
||||
|
||||
class DecompLinter:
|
||||
def __init__(self):
|
||||
self.alerts = []
|
||||
def __init__(self) -> None:
|
||||
self.alerts: List[ParserAlert] = []
|
||||
self._parser = DecompParser()
|
||||
self._filename = ""
|
||||
self._module = None
|
||||
self._filename: str = ""
|
||||
self._module: Optional[str] = None
|
||||
|
||||
def reset(self):
|
||||
self.alerts = []
|
||||
@ -53,7 +54,7 @@ def _check_function_order(self):
|
||||
|
||||
last_offset = fun.offset
|
||||
|
||||
def _check_symbol_uniqueness(self):
|
||||
def _check_offset_uniqueness(self):
|
||||
# TODO
|
||||
pass
|
||||
|
||||
@ -85,7 +86,7 @@ def check_lines(self, lines, filename, module=None):
|
||||
|
||||
if self._module is not None:
|
||||
self._check_byname_allowed()
|
||||
self._check_symbol_uniqueness()
|
||||
self._check_offset_uniqueness()
|
||||
|
||||
if not self.file_is_header():
|
||||
self._check_function_order()
|
||||
|
||||
@ -56,7 +56,7 @@ def marker_is_vtable(marker: DecompMarker) -> bool:
|
||||
|
||||
|
||||
class MarkerDict:
|
||||
def __init__(self):
|
||||
def __init__(self) -> None:
|
||||
self.markers: dict = {}
|
||||
|
||||
def insert(self, marker: DecompMarker) -> bool:
|
||||
@ -80,7 +80,7 @@ class DecompParser:
|
||||
# pylint: disable=too-many-instance-attributes
|
||||
# Could combine output lists into a single list to get under the limit,
|
||||
# but not right now
|
||||
def __init__(self):
|
||||
def __init__(self) -> None:
|
||||
# The lists to be populated as we parse
|
||||
self.functions: List[ParserFunction] = []
|
||||
self.vtables: List[ParserVtable] = []
|
||||
|
||||
@ -47,9 +47,12 @@ def test_byname_ignored(linter):
|
||||
"// FUNCTION: TEST 0x2000",
|
||||
"void function2() {}",
|
||||
]
|
||||
# TODO: This will fail after enforcing that bynames belong in headers
|
||||
assert linter.check_lines(lines, "test.cpp", "TEST") is True
|
||||
assert len(linter.alerts) == 0
|
||||
# This will fail because byname lookup does not belong in the cpp file
|
||||
assert linter.check_lines(lines, "test.cpp", "TEST") is False
|
||||
# but it should not fail for function order.
|
||||
assert all(
|
||||
alert.code != ParserError.FUNCTION_OUT_OF_ORDER for alert in linter.alerts
|
||||
)
|
||||
|
||||
|
||||
def test_module_isolation(linter):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user