| 1 |
import typing as T |
| 2 |
from abc import abstractmethod |
| 3 |
|
| 4 |
from ..errors import CompileError |
| 5 |
from ..language import Literal, Object, Property, QuotedLiteral, Translated, Value |
| 6 |
|
| 7 |
|
| 8 |
class LinterRule: |
| 9 |
id: str |
| 10 |
severity: T.Union[T.Literal["problem"], T.Literal["suggestion"]] |
| 11 |
platform: T.Optional[str] = None |
| 12 |
category: str |
| 13 |
|
| 14 |
def __init__(self, problems: list[CompileError]): |
| 15 |
self.problems = problems |
| 16 |
|
| 17 |
def get_string_value(self, property: Property): |
| 18 |
if not isinstance(property.value, Value): |
| 19 |
return (None, None) |
| 20 |
|
| 21 |
value = property.value.child |
| 22 |
if isinstance(value, Translated): |
| 23 |
return (value.string, value.string_token.range_without_quotes) |
| 24 |
elif isinstance(value, Literal) and isinstance(value.value, QuotedLiteral): |
| 25 |
return (value.value.value, value.value.value_token.range_without_quotes) |
| 26 |
else: |
| 27 |
return (None, None) |
| 28 |
|
| 29 |
@abstractmethod |
| 30 |
def check(self, type: str, child: Object, stack: list[Object]): ... |