add linter
This commit is contained in:
@@ -1,16 +0,0 @@
|
||||
from tclint.syntax_tree import BracedWord
|
||||
|
||||
|
||||
def lib_spf_prepend(args, parser):
|
||||
if len(args) >= 5:
|
||||
# Heuristik: myTag wurde zu früh getrennt, hänge ihn an den BracedBlock
|
||||
merged_contents = args[3].contents + "\n" + args[4].contents
|
||||
merged = BracedWord(merged_contents, pos=args[3].pos, end_pos=args[4].end_pos)
|
||||
script = parser.parse_script(merged)
|
||||
return args[:3] + [script] # [routine, arg1, arg2, script]
|
||||
elif len(args) >= 4:
|
||||
args[2] = parser.parse_script(args[2])
|
||||
return args
|
||||
|
||||
|
||||
commands = {"LIB_SPF_prepend": lib_spf_prepend}
|
||||
@@ -0,0 +1,53 @@
|
||||
from enum import Enum
|
||||
from tclint.syntax_tree import Visitor
|
||||
from tclint.violations import Violation
|
||||
|
||||
|
||||
class PoCoRule(Enum):
|
||||
POCO_VALIDATION = "poco-validation"
|
||||
|
||||
def __str__(self):
|
||||
return self.value
|
||||
|
||||
|
||||
class PocoCommandChecker(Visitor):
|
||||
def __init__(self):
|
||||
self._violations = []
|
||||
|
||||
def check(self, _, tree):
|
||||
self._violations.clear()
|
||||
tree.accept(self, recurse=True)
|
||||
return self._violations
|
||||
|
||||
def visit_command(self, command):
|
||||
name = command.routine.contents
|
||||
if name not in {"LIB_GE_command_buffer_edit_prepend"}:
|
||||
return
|
||||
|
||||
if len(command.args) != 4:
|
||||
self._violations.append(
|
||||
Violation(
|
||||
PoCoRule.POCO_VALIDATION,
|
||||
f"{name}: expected 4 arguments, got {len(command.args)}",
|
||||
command.pos,
|
||||
command.end_pos,
|
||||
)
|
||||
)
|
||||
return
|
||||
|
||||
script_arg = command.args[2]
|
||||
if script_arg.contents is None:
|
||||
self._violations.append(
|
||||
Violation(
|
||||
PoCoRule.POCO_VALIDATION,
|
||||
f"{name}: third argument must be a braced script",
|
||||
script_arg.pos,
|
||||
script_arg.end_pos,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def get_checkers():
|
||||
checkers = (PocoCommandChecker(),)
|
||||
|
||||
return checkers
|
||||
Reference in New Issue
Block a user