oct.linter.rule_registry module#

Purpose#

Provide a structured registry of all lint rules with human-readable documentation for each rule: rationale, correct pattern, common mistake, spec reference, and severity tier. Powers oct lint --explain <rule> and the linter’s three-tier failure classification.

Responsibilities#

  • Define the RuleInfo dataclass that carries rule metadata.

  • Populate RULE_REGISTRY with one entry per rule in _DEFAULT_RULES.

  • Expose get_rule_info() and list_rules() for lookup / enumeration.

  • Expose get_severity() so the linter and quality gate can decide whether a finding blocks the build or is reported as advisory.

Diagnostics#

Domain: OCT-LINTER Levels:

L3 — rule registry queries

Contracts#

  • Every key in _DEFAULT_RULES must have a corresponding RuleInfo.

  • RuleInfo is frozen — registry is immutable after module load.

  • severity is one of "blocking", "advisory", or "info". blocking means a violation flips the run to non-zero exit; advisory is reported but does not affect exit code; info is reserved for future low-priority hints.

Dependencies#

class oct.linter.rule_registry.RuleInfo(name: str, label: str, rationale: str, correct_pattern: str, common_mistake: str, spec_reference: str, fixable: bool, profiles: list[str], severity: str = 'blocking', severity_per_profile: dict[str, str] = <factory>)[source]#

Bases: object

Immutable documentation record for a single lint rule.

The severity field (FS-C4) classifies each rule’s failure mode:

  • "blocking" (default) — a violation flips the linter exit code to 1 and the quality gate to non-zero.

  • "advisory" — a violation is reported in JSON output and logs but does not affect exit codes. AI agents and CI can use this tier to surface improvement opportunities without blocking merges.

  • "info" — reserved for low-priority hints (future use).

The severity_per_profile map allows a rule to be advisory at one profile and blocking at another (e.g. tests_exist is advisory at compact, blocking at strict).

common_mistake: str#
correct_pattern: str#
fixable: bool#
label: str#
name: str#
profiles: list[str]#
rationale: str#
severity: str = 'blocking'#
severity_per_profile: dict[str, str]#
spec_reference: str#
oct.linter.rule_registry.get_rule_info(name: str) RuleInfo | None[source]#

Return the RuleInfo for name, or None if unknown.

oct.linter.rule_registry.get_severity(rule_name: str, profile: str = 'strict') str[source]#

Return the severity tier (blocking / advisory / info) for rule_name under profile (FS-C4).

Resolution order: profile-specific override → rule’s default severity → "blocking" for unknown rules (fail-safe).

oct.linter.rule_registry.is_blocking(rule_name: str, profile: str = 'strict') bool[source]#

Convenience predicate: return True iff a violation of rule_name should flip the linter / quality-gate exit code at profile.

oct.linter.rule_registry.list_rules() list[RuleInfo][source]#

Return all registered rules in registry order.