Skip to main content

API reference

Reference for the framework's public Python API. Use this when wiring ignition-lint into custom tooling, building rule generators, or auditing the registry programmatically.

Rule registry

from ignition_lint.rules.registry import (
get_registry,
register_rule,
discover_rules,
RuleValidationError,
)
from ignition_lint.rules import get_all_rules

register_rule(rule_class, rule_name=None) → str

Register a rule with the global registry. Usable as a decorator or function.

ParameterTypeDescription
rule_classType[LintingRule]The rule class
rule_namestr | NoneCustom name (defaults to class name)

Returns: registered rule name

Raises: RuleValidationError if validation fails

@register_rule
class MyRule(LintingRule):
...

# Or as a function with a custom name
register_rule(MyRule, "CustomName")

get_registry() → RuleRegistry

Returns the global RuleRegistry singleton.

get_all_rules() → dict[str, Type[LintingRule]]

Returns every registered rule, keyed by name.

from ignition_lint.rules import get_all_rules

rules = get_all_rules()
for name, cls in rules.items():
print(f"{name}: {cls.__doc__}")

discover_rules() → list[str]

Walks src/ignition_lint/rules/ and registers every valid LintingRule subclass it finds. Called automatically on package import; rarely needed manually.

RuleValidationError

Raised when a rule fails registration. Common causes:

  • Class doesn't inherit from LintingRule
  • error_message property is missing
  • Rule cannot be instantiated with cls.create_from_config({})
  • Name conflict with an already-registered rule

RuleRegistry

from ignition_lint.rules.registry import RuleRegistry
MethodReturnsPurpose
register_rule(rule_class, rule_name=None)strRegister a rule
get_rule(rule_name)Type[LintingRule] | NoneLook up by name
get_all_rules()dict[str, Type[LintingRule]]All registered rules
list_rules()list[str]Rule names only
is_registered(rule_name)boolCheck existence
get_rule_metadata(rule_name)dict | NoneExtracted metadata for a rule
discover_and_register_rules(package_path=None)list[str]Run discovery

Metadata fields

get_rule_metadata returns a dict with:

KeyDescription
class_nameClass name
moduleDefining module
docstringClass docstring
source_filePath to the source file
error_messageRule's error_message property value

Useful for auto-generating rule catalogs or IDE help.

LintingRule base class

from ignition_lint.rules.common import LintingRule, BindingRule, ScriptRule, FixableMixin

Constructor

LintingRule(
target_node_types: set[NodeType] | None = None,
severity: str = "error",
include_private_properties: bool = False,
)
ParameterDescription
target_node_typesNode types this rule processes (filters which visit_* methods receive nodes). None ≡ no filtering.
severityDefault severity: "error" or "warning"
include_private_propertiesWhen False, properties starting with _ and the reserved key _JavaDate are skipped

Required: error_message

@property
@abstractmethod
def error_message(self) -> str:
...

Description of what the rule checks. Used in CLI output and metadata.

Lifecycle

MethodDefault behaviorOverride to...
applies_to(node)Filter by target_node_types and private-property settingCustomize node filtering
process_nodes(nodes)Reset state, filter, dispatch via accept, call post_processBypass standard iteration entirely
post_process()No-opRun cross-node analysis after all nodes visited
add_violation(message, severity=None)Routes to errors or warnings(rarely)

preprocess_config(cls, config)

Class method that runs before __init__. Default behavior strips keys starting with _ (used for inline comments). Override to convert strings to enums, validate values, etc.

@classmethod
def preprocess_config(cls, config: dict) -> dict:
processed = super().preprocess_config(config)
if 'target_node_types' in processed:
processed['target_node_types'] = {
NodeType(s) for s in processed['target_node_types']
}
return processed

create_from_config(cls, config)

Builds a rule instance from a config dict. Calls preprocess_config first, then unpacks the result as kwargs to __init__. The framework calls this internally when loading rule_config.json.

BindingRule

Specializes LintingRule for binding-only rules:

class BindingRule(LintingRule):
def __init__(self, target_node_types=None, severity="error", include_private_properties=False):
if target_node_types is None:
target_node_types = ALL_BINDINGS
super().__init__(target_node_types, severity, include_private_properties)

Use when your rule visits one or more binding types. Same API as LintingRule otherwise.

ScriptRule

Specializes LintingRule for script-only rules. Auto-collects scripts and exposes them as a batch:

class ScriptRule(LintingRule):
@abstractmethod
def process_scripts(self, scripts: dict[str, ScriptNode]):
"""Receive all collected scripts at once."""

The framework calls every visit_*_handler / visit_custom_method / visit_transform for you (each appends to self.collected_scripts), then invokes process_scripts in post_process. You typically only override process_scripts and the constructor.

FixableMixin

Adds auto-fix capability. Inherit alongside any rule base:

class MyRule(FixableMixin, LintingRule):
...
MethodPurpose
add_fix(fix: Fix)Add a fix to the collection
get_fixes() → list[Fix]Return collected fixes
reset_fixes()Clear collected fixes
set_fix_context(json_data, path_translator)Called by LintEngine when fix mode is active
has_fix_context → boolTrue when fix mode is active
supports_fix → boolAlways True for FixableMixin consumers

Fix and FixOperation

from ignition_lint.common.fix_operations import Fix, FixOperation, FixOperationType

Fix

FieldTypeDescription
rule_namestrProducing rule (typically self.error_key)
violation_messagestrThe violation this fix addresses
descriptionstrHuman-readable summary
operationslist[FixOperation]Edit operations
is_safeboolWhether automatic application is safe
safety_notesstrIf unsafe, why ("updates 3 reference(s)", "component uses 'this.meta.name' binding")

FixOperation

FieldDescription
operationOne of FixOperationType.SET_VALUE, DELETE, INSERT (see source for current full set)
json_pathList of dict keys / array indices into the original JSON
old_valueValue before the fix (for verification)
new_valueValue after the fix
descriptionPer-operation description

The LintEngine resolves json_path against the loaded JSON document and applies operations in order.

NodeType

from ignition_lint.model.node_types import (
NodeType,
ALL_BINDINGS,
ALL_SCRIPTS,
ViewNode,
Component,
Property,
ExpressionBinding,
PropertyBinding,
TagBinding,
QueryBinding,
EventHandlerScript,
MessageHandlerScript,
CustomMethodScript,
TransformScript,
)

Enum values

NodeType is a string enum — values match the strings used in rule_config.json for target_node_types:

Value (string)Class
"component"Component
"property"Property
"expression_binding"ExpressionBinding
"expression_struct_binding"ExpressionStructBinding
"property_binding"PropertyBinding
"tag_binding"TagBinding
"query_binding"QueryBinding
"event_handler"EventHandlerScript
"message_handler"MessageHandlerScript
"custom_method"CustomMethodScript
"transform"TransformScript

Sets

SetMembers
ALL_BINDINGSAll binding node types
ALL_SCRIPTSAll script node types

ViewNode and node attributes

Every node has:

node.path # Full dotted path in the original JSON
node.node_type # NodeType enum value
node.accept(visitor) # Visitor pattern dispatch

Type-specific attributes (most common):

ClassAttributes
Componentname, type, properties (dict)
Propertyname
ExpressionBindingexpression, config
ExpressionStructBindingstruct (dict[str, str])
PropertyBindingtarget_path, config
TagBindingtag_path, mode ("direct" / "expression" / "indirect"), references
QueryBindingparameters (dict[str, str])
*Script (all)script, get_formatted_script()
MessageHandlerScript+ message_type, scope
CustomMethodScript+ name, params
TransformScript+ binding_path
EventHandlerScript+ event_type, scope

get_formatted_script() on script nodes returns runnable Python with the appropriate indentation and (for custom methods) function definition.

LintEngine

from ignition_lint.linter import LintEngine

The orchestrator. Wraps configuration, model building, and rule execution. Most consumers don't construct it directly — cli.py is the canonical entry point — but it's available for embedding in custom tools:

from ignition_lint.linter import LintEngine

engine = LintEngine(config_path="rule_config.json")
report = engine.lint_file("path/to/view.json")

See src/ignition_lint/linter.py for the full interface.

See also