Skip to content

Commit

Permalink
Update maplint
Browse files Browse the repository at this point in the history
  • Loading branch information
Drulikar committed Jul 8, 2024
1 parent 49a98be commit d888353
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion tools/maplint/source/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def print_error(message: str, filename: str, line_number: int, github_error_styl

def print_maplint_error(error: MaplintError, github_error_style: bool):
print_error(
f"{f'(in pop {error.pop_id}) ' if error.pop_id else ''}{f'(at {error.coordinates}) ' if error.coordinates else ''}{error}",
f"{f'(in pop {error.pop_id}) ' if error.pop_id else ''}{f'(at {error.coordinates}) ' if error.coordinates else ''}{error}" + (f"\n {error.help}" if error.help is not None else ""),
error.file_name,
error.line_number,
github_error_style,
Expand Down
9 changes: 7 additions & 2 deletions tools/maplint/source/error.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Optional

"""Linting error with associated filename and line number."""
class MaplintError(Exception):
"""The DMM file name the exception occurred in"""
Expand All @@ -7,10 +9,13 @@ class MaplintError(Exception):
line_number = 1

"""The optional coordinates"""
coordinates: str = None
coordinates: Optional[str] = None

"""The optional pop ID"""
pop_id: str = None
pop_id: Optional[str] = None

"""The optional help message"""
help: Optional[str] = None

def __init__(self, message: str, file_name: str, line_number = 1):
Exception.__init__(self, message)
Expand Down
11 changes: 8 additions & 3 deletions tools/maplint/source/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,13 @@ def __init__(self, typepath, data = {}):

def matches(self, identified: Content, neighbor: Content):
if self.identical:
return neighbor == identified
if identified.path != neighbor.path:
return False

if identified.var_edits != neighbor.var_edits:
return False

return True

if self.typepath is not None:
if self.typepath.matches_path(neighbor.path):
Expand Down Expand Up @@ -260,9 +266,8 @@ def run(self, map_data: DMM) -> list[MaplintError]:
coordinate_texts.append(f"and {leftover_coordinates} more")

for failure in failures:
if self.help is not None:
failure.message += f"\n {self.help}"
failure.coordinates = ', '.join(coordinate_texts)
failure.help = self.help
failure.pop_id = pop
all_failures.append(failure)

Expand Down

0 comments on commit d888353

Please sign in to comment.