Commit 4252ea05 authored by Steije van Schelt's avatar Steije van Schelt Committed by Mark Canterbury
Browse files

Add nolint hints

parent 21c53a4c
Loading
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@
        <xs:sequence>
            <xs:element name="Header" type="MessageHeader"/>
            <xs:element name="Payload" type="MessagePayload"/>
            <!-- nolint: accept untyped element -->
            <xs:element name="Signature" minOccurs="0"/>
            <!-- Use of the Signature element is discouraged – implementers are encouraged use the digsig:Signature element below instead -->
            <xs:element ref="digsig:Signature" minOccurs="0"/>
+1 −0
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@
    </xs:complexType>
    <xs:complexType name="SchemaContent">
        <xs:sequence>
            <!-- nolint: accept untyped element -->
            <xs:element xmlns="http://www.w3.org/2001/XMLSchema" name="schema"/>
        </xs:sequence>
    </xs:complexType>
+9 −1
Original line number Diff line number Diff line
@@ -62,12 +62,20 @@ def get_linting_errors(file: Path) -> str:
        return "\n".join([print_colorized_diff_line(d) for d in diff])

def get_type_errors(file: Path) -> str:
    with open(file) as f:
        lines = f.read().splitlines()

    tree = etree.parse(file, parser=etree_parser)
    root = tree.getroot()

    errors = []

    for el in root.iter(f"{XS}element"):
        try:
            has_nolint = "<!-- nolint:" in lines[el.sourceline-2]
        except IndexError:
            has_nolint = False

        has_ref = el.get("ref") is not None
        has_type_attr = el.get("type") is not None
        has_inline_type = (
@@ -75,7 +83,7 @@ def get_type_errors(file: Path) -> str:
            or el.find(f"{XS}complexType") is not None
        )

        if not has_ref and not has_type_attr and not has_inline_type:
        if not has_nolint and not has_ref and not has_type_attr and not has_inline_type:
            errors.append(f"Line {el.sourceline} has untyped element {el.get('name')}")

    if len(errors) > 0: