Skip to content

types_

ruff_sync.tui.types_

Data types for the TUI.

ConfigNode

Bases: Protocol

Protocol for TUI Configuration Nodes.

Source code in src/ruff_sync/tui/types_.py
@runtime_checkable
class ConfigNode(Protocol):
    """Protocol for TUI Configuration Nodes."""

    @property
    def key(self) -> str:
        """The key or label for this node."""
        ...

    @property
    def path(self) -> str:
        """The full configuration path."""
        ...

    def children(self) -> list[ConfigNode]:
        """Child nodes for tree expansion."""
        ...

    def doc_target(self) -> tuple[str, Literal["rule", "config", "none"]]:
        """Returns the documentation target and type."""
        ...

key property

key

The key or label for this node.

path property

path

The full configuration path.

children

children()

Child nodes for tree expansion.

Source code in src/ruff_sync/tui/types_.py
def children(self) -> list[ConfigNode]:
    """Child nodes for tree expansion."""
    ...

doc_target

doc_target()

Returns the documentation target and type.

Source code in src/ruff_sync/tui/types_.py
def doc_target(self) -> tuple[str, Literal["rule", "config", "none"]]:
    """Returns the documentation target and type."""
    ...

DictNode

A node representing a dictionary in the configuration.

Source code in src/ruff_sync/tui/types_.py
class DictNode:
    """A node representing a dictionary in the configuration."""

    def __init__(self, key: str, path: str, data: dict[str, Any]) -> None:
        """Initialize the Dictionary Node."""
        self._key = key
        self._path = path
        self.data = data

    @property
    def key(self) -> str:
        """Get the node's key."""
        return self._key

    @property
    def path(self) -> str:
        """Get the node's configuration path."""
        return self._path

    def children(self) -> list[ConfigNode]:
        """Return the dictionary children wrapped as ConfigNodes."""
        return [wrap_data(k, v, f"{self.path}.{k}") for k, v in sorted(self.data.items())]

    def doc_target(self) -> tuple[str, Literal["rule", "config", "none"]]:
        """Resolve the primary target string and type for documentation."""
        if self._path == "tool.ruff":
            return ("", "none")
        return (self._path, "config")

data instance-attribute

data = data

key property

key

Get the node's key.

path property

path

Get the node's configuration path.

__init__

__init__(key, path, data)

Initialize the Dictionary Node.

Source code in src/ruff_sync/tui/types_.py
def __init__(self, key: str, path: str, data: dict[str, Any]) -> None:
    """Initialize the Dictionary Node."""
    self._key = key
    self._path = path
    self.data = data

children

children()

Return the dictionary children wrapped as ConfigNodes.

Source code in src/ruff_sync/tui/types_.py
def children(self) -> list[ConfigNode]:
    """Return the dictionary children wrapped as ConfigNodes."""
    return [wrap_data(k, v, f"{self.path}.{k}") for k, v in sorted(self.data.items())]

doc_target

doc_target()

Resolve the primary target string and type for documentation.

Source code in src/ruff_sync/tui/types_.py
def doc_target(self) -> tuple[str, Literal["rule", "config", "none"]]:
    """Resolve the primary target string and type for documentation."""
    if self._path == "tool.ruff":
        return ("", "none")
    return (self._path, "config")

ListNode

A node representing a list in the configuration.

Source code in src/ruff_sync/tui/types_.py
class ListNode:
    """A node representing a list in the configuration."""

    def __init__(self, key: str, path: str, data: list[Any]) -> None:
        """Initialize the List Node."""
        self._key = key
        self._path = path
        self.data = data

    @property
    def key(self) -> str:
        """Get the node's key."""
        return self._key

    @property
    def path(self) -> str:
        """Get the node's configuration path."""
        return self._path

    def children(self) -> list[ConfigNode]:
        """Return the list children wrapped as ConfigNodes."""
        return [
            wrap_data(
                str(v) if isinstance(v, str) and RULE_PATTERN.match(v) else f"[{i}]",
                v,
                f"{self.path}[{i}]",
            )
            for i, v in enumerate(self.data)
        ]

    def doc_target(self) -> tuple[str, Literal["rule", "config", "none"]]:
        """Resolve the primary target string and type for documentation."""
        return (self._path, "config")

data instance-attribute

data = data

key property

key

Get the node's key.

path property

path

Get the node's configuration path.

__init__

__init__(key, path, data)

Initialize the List Node.

Source code in src/ruff_sync/tui/types_.py
def __init__(self, key: str, path: str, data: list[Any]) -> None:
    """Initialize the List Node."""
    self._key = key
    self._path = path
    self.data = data

children

children()

Return the list children wrapped as ConfigNodes.

Source code in src/ruff_sync/tui/types_.py
def children(self) -> list[ConfigNode]:
    """Return the list children wrapped as ConfigNodes."""
    return [
        wrap_data(
            str(v) if isinstance(v, str) and RULE_PATTERN.match(v) else f"[{i}]",
            v,
            f"{self.path}[{i}]",
        )
        for i, v in enumerate(self.data)
    ]

doc_target

doc_target()

Resolve the primary target string and type for documentation.

Source code in src/ruff_sync/tui/types_.py
def doc_target(self) -> tuple[str, Literal["rule", "config", "none"]]:
    """Resolve the primary target string and type for documentation."""
    return (self._path, "config")

ScalarNode

A node representing a scalar value in the configuration.

Source code in src/ruff_sync/tui/types_.py
class ScalarNode:
    """A node representing a scalar value in the configuration."""

    def __init__(self, key: str, path: str, value: Any) -> None:
        """Initialize the Scalar Node."""
        self._key = key
        self._path = path
        self.value = value

    @property
    def key(self) -> str:
        """Get the node's key."""
        return self._key

    @property
    def path(self) -> str:
        """Get the node's configuration path."""
        return self._path

    def children(self) -> list[ConfigNode]:
        """Return empty list, as scalars have no children."""
        return []

    def doc_target(self) -> tuple[str, Literal["rule", "config", "none"]]:
        """Resolve the primary target string and type for documentation."""
        if isinstance(self.value, str) and RULE_PATTERN.match(self.value):
            return (self.value, "rule")
        return (self._path, "config")

value instance-attribute

value = value

key property

key

Get the node's key.

path property

path

Get the node's configuration path.

__init__

__init__(key, path, value)

Initialize the Scalar Node.

Source code in src/ruff_sync/tui/types_.py
def __init__(self, key: str, path: str, value: Any) -> None:
    """Initialize the Scalar Node."""
    self._key = key
    self._path = path
    self.value = value

children

children()

Return empty list, as scalars have no children.

Source code in src/ruff_sync/tui/types_.py
def children(self) -> list[ConfigNode]:
    """Return empty list, as scalars have no children."""
    return []

doc_target

doc_target()

Resolve the primary target string and type for documentation.

Source code in src/ruff_sync/tui/types_.py
def doc_target(self) -> tuple[str, Literal["rule", "config", "none"]]:
    """Resolve the primary target string and type for documentation."""
    if isinstance(self.value, str) and RULE_PATTERN.match(self.value):
        return (self.value, "rule")
    return (self._path, "config")

RulesCollectionNode

A node representing the root 'Effective Rule Status' section.

Source code in src/ruff_sync/tui/types_.py
class RulesCollectionNode:
    """A node representing the root 'Effective Rule Status' section."""

    def __init__(self, linters: list[RuffLinter], effective_rules: list[RuffRule]) -> None:
        """Initialize the Rules Collection Node."""
        self._key = "Effective Rule Status"
        self._path = "__rules__"
        self.linters = linters
        self.effective_rules = effective_rules

    @property
    def key(self) -> str:
        """Get the node's key."""
        return self._key

    @property
    def path(self) -> str:
        """Get the node's configuration path."""
        return self._path

    def children(self) -> list[ConfigNode]:
        """Return Linters as children."""
        return _build_linter_nodes(self.linters, self.effective_rules)

    def doc_target(self) -> tuple[str, Literal["rule", "config", "none"]]:
        """No documentation target for root collection."""
        return ("", "none")

linters instance-attribute

linters = linters

effective_rules instance-attribute

effective_rules = effective_rules

key property

key

Get the node's key.

path property

path

Get the node's configuration path.

__init__

__init__(linters, effective_rules)

Initialize the Rules Collection Node.

Source code in src/ruff_sync/tui/types_.py
def __init__(self, linters: list[RuffLinter], effective_rules: list[RuffRule]) -> None:
    """Initialize the Rules Collection Node."""
    self._key = "Effective Rule Status"
    self._path = "__rules__"
    self.linters = linters
    self.effective_rules = effective_rules

children

children()

Return Linters as children.

Source code in src/ruff_sync/tui/types_.py
def children(self) -> list[ConfigNode]:
    """Return Linters as children."""
    return _build_linter_nodes(self.linters, self.effective_rules)

doc_target

doc_target()

No documentation target for root collection.

Source code in src/ruff_sync/tui/types_.py
def doc_target(self) -> tuple[str, Literal["rule", "config", "none"]]:
    """No documentation target for root collection."""
    return ("", "none")

LinterNode

A node representing a category or linter group.

Source code in src/ruff_sync/tui/types_.py
class LinterNode:
    """A node representing a category or linter group."""

    def __init__(self, linter: RuffLinter, effective_rules: list[RuffRule]) -> None:
        """Initialize a Linter Node."""
        self.linter = linter
        name = linter["name"]
        prefix = linter.get("prefix")
        self._key = f"{name} ({prefix})" if prefix else name
        self._path = f"__linter__:{prefix}"
        self.effective_rules = effective_rules

    @property
    def key(self) -> str:
        """Get the node's key."""
        return self._key

    @property
    def path(self) -> str:
        """Get the node's configuration path."""
        return self._path

    def children(self) -> list[ConfigNode]:
        """Return subcategories of this Linter as children if they exist."""
        if "categories" in self.linter:
            return _build_linter_nodes(self.linter["categories"], self.effective_rules)
        return []

    def doc_target(self) -> tuple[str, Literal["rule", "config", "none"]]:
        """No documentation target for linter group itself."""
        return ("", "none")

linter instance-attribute

linter = linter

effective_rules instance-attribute

effective_rules = effective_rules

key property

key

Get the node's key.

path property

path

Get the node's configuration path.

__init__

__init__(linter, effective_rules)

Initialize a Linter Node.

Source code in src/ruff_sync/tui/types_.py
def __init__(self, linter: RuffLinter, effective_rules: list[RuffRule]) -> None:
    """Initialize a Linter Node."""
    self.linter = linter
    name = linter["name"]
    prefix = linter.get("prefix")
    self._key = f"{name} ({prefix})" if prefix else name
    self._path = f"__linter__:{prefix}"
    self.effective_rules = effective_rules

children

children()

Return subcategories of this Linter as children if they exist.

Source code in src/ruff_sync/tui/types_.py
def children(self) -> list[ConfigNode]:
    """Return subcategories of this Linter as children if they exist."""
    if "categories" in self.linter:
        return _build_linter_nodes(self.linter["categories"], self.effective_rules)
    return []

doc_target

doc_target()

No documentation target for linter group itself.

Source code in src/ruff_sync/tui/types_.py
def doc_target(self) -> tuple[str, Literal["rule", "config", "none"]]:
    """No documentation target for linter group itself."""
    return ("", "none")

RuleNode

A node representing an individual Ruff rule.

NOTE: Currently unused. In the read-only TUI, rule items are rendered directly as DataTable rows rather than populated as polymorphic ConfigNode tree elements, effectively stopping the tree hierarchy at the Linter/Category level to prevent UX clutter.

This class is retained as structural scaffolding for the future "Read-Write Interactive" phase. When building the Local Modification Engine, RuleNode will be necessary as an abstraction to hold state (e.g. toggled enabled/disabled, upstream drift provenance, and attached tomlkit inline comments) mapped back to the TOML tree.

Source code in src/ruff_sync/tui/types_.py
class RuleNode:
    """A node representing an individual Ruff rule.

    NOTE: Currently unused. In the read-only TUI, rule items are rendered
    directly as `DataTable` rows rather than populated as polymorphic
    `ConfigNode` tree elements, effectively stopping the tree hierarchy
    at the Linter/Category level to prevent UX clutter.

    This class is retained as structural scaffolding for the future
    "Read-Write Interactive" phase. When building the Local Modification
    Engine, `RuleNode` will be necessary as an abstraction to hold state
    (e.g. toggled enabled/disabled, upstream drift provenance, and
    attached `tomlkit` inline comments) mapped back to the TOML tree.
    """

    def __init__(self, rule: RuffRule) -> None:
        """Initialize a Rule Node."""
        self.rule = rule
        self._key = rule["code"]
        self._path = f"__rule__:{rule['code']}"

    @property
    def key(self) -> str:
        """Get the node's key."""
        return self._key

    @property
    def path(self) -> str:
        """Get the node's configuration path."""
        return self._path

    def children(self) -> list[ConfigNode]:
        """Return empty list; rules have no children."""
        return []

    def doc_target(self) -> tuple[str, Literal["rule", "config", "none"]]:
        """Target the rule exactly for documentation."""
        return (self.rule["code"], "rule")

rule instance-attribute

rule = rule

key property

key

Get the node's key.

path property

path

Get the node's configuration path.

__init__

__init__(rule)

Initialize a Rule Node.

Source code in src/ruff_sync/tui/types_.py
def __init__(self, rule: RuffRule) -> None:
    """Initialize a Rule Node."""
    self.rule = rule
    self._key = rule["code"]
    self._path = f"__rule__:{rule['code']}"

children

children()

Return empty list; rules have no children.

Source code in src/ruff_sync/tui/types_.py
def children(self) -> list[ConfigNode]:
    """Return empty list; rules have no children."""
    return []

doc_target

doc_target()

Target the rule exactly for documentation.

Source code in src/ruff_sync/tui/types_.py
def doc_target(self) -> tuple[str, Literal["rule", "config", "none"]]:
    """Target the rule exactly for documentation."""
    return (self.rule["code"], "rule")

wrap_data

wrap_data(key, data, path='tool.ruff')

Wrap raw configuration data into strongly-typed ConfigNode instances.

Source code in src/ruff_sync/tui/types_.py
def wrap_data(key: str, data: Any, path: str = "tool.ruff") -> ConfigNode:
    """Wrap raw configuration data into strongly-typed ConfigNode instances."""
    if isinstance(data, dict):
        return DictNode(key, path, data)
    if isinstance(data, list):
        return ListNode(key, path, data)
    return ScalarNode(key, path, data)