Configuration Models¶
Defines all data structures and configuration models for the validator.
This module contains Enum classes for standardized codes and several frozen dataclasses that represent the structured configuration loaded from JSON files and command-line arguments. These models ensure type safety and provide a clear “shape” for the application’s data.
- class code_validator.config.AppConfig(solution_path: Path, rules_path: Path, log_level: LogLevel, is_quiet: bool, exit_on_first_error: bool, max_messages: int = 0)¶
Bases:
objectStores the main application configuration from CLI arguments.
- solution_path¶
The file path to the Python solution to be validated.
- Type:
pathlib.Path
- rules_path¶
The file path to the JSON rules file.
- Type:
pathlib.Path
- log_level¶
The minimum logging level for console output.
- is_quiet¶
If True, suppresses all non-log output to stdout.
- Type:
bool
- exit_on_first_error¶
If True, halts validation after the first failed rule.
- Type:
bool
- max_messages¶
Maximum number of error messages to display. 0 for no limit. Default: 0.
- Type:
int
- exit_on_first_error: bool¶
- is_quiet: bool¶
- max_messages: int = 0¶
- rules_path: Path¶
- solution_path: Path¶
- class code_validator.config.ConstraintConfig(type: str, count: int | None = None, parent_name: str | None = None, expected_type: str | None = None, allowed_names: list[str] | None = None, allowed_values: list[Any] | None = None, names: list[str] | None = None, exact_match: bool | None = None)¶
Bases:
objectRepresents the configuration for a Constraint component from a JSON rule.
This dataclass captures all possible keys within the “constraint” block of a JSON validation rule.
- type¶
The type of the constraint to be applied (e.g., “is_required”).
- Type:
str
- count¶
The exact number of nodes expected. Used by is_required.
- Type:
int | None
- parent_name¶
The expected parent class name. Used by must_inherit_from.
- Type:
str | None
- expected_type¶
The expected Python type name. Used by must_be_type.
- Type:
str | None
- allowed_names¶
A list of permitted names. Used by name_must_be_in.
- Type:
list[str] | None
- allowed_values¶
A list of permitted literal values. Used by value_must_be_in.
- Type:
list[Any] | None
- names¶
A list of expected argument names. Used by must_have_args.
- Type:
list[str] | None
- exact_match¶
A boolean flag for argument matching. Used by must_have_args.
- Type:
bool | None
- allowed_names: list[str] | None = None¶
- allowed_values: list[Any] | None = None¶
- count: int | None = None¶
- exact_match: bool | None = None¶
- expected_type: str | None = None¶
- names: list[str] | None = None¶
- parent_name: str | None = None¶
- type: str¶
- class code_validator.config.ExitCode(value)¶
Bases:
IntEnumDefines standardized exit codes for the command-line application.
- FILE_NOT_FOUND = 2¶
- JSON_ERROR = 3¶
- SUCCESS = 0¶
- UNEXPECTED_ERROR = 10¶
- VALIDATION_FAILED = 1¶
- class code_validator.config.FullRuleCheck(selector: SelectorConfig, constraint: ConstraintConfig)¶
Bases:
objectRepresents the ‘check’ block within a full validation rule.
- selector¶
The configuration for the selector component.
- constraint¶
The configuration for the constraint component.
- constraint: ConstraintConfig¶
- selector: SelectorConfig¶
- class code_validator.config.FullRuleConfig(rule_id: int, message: str, check: FullRuleCheck, is_critical: bool = False)¶
Bases:
objectRepresents a ‘full’ (custom) validation rule with a selector and constraint.
- rule_id¶
The unique integer identifier for the rule.
- Type:
int
- message¶
The error message to display if the rule fails.
- Type:
str
- check¶
An object containing the selector and constraint configurations.
- is_critical¶
If True, validation halts if this rule fails.
- Type:
bool
- check: FullRuleCheck¶
- is_critical: bool = False¶
- message: str¶
- rule_id: int¶
- class code_validator.config.LogLevel(value)¶
Bases:
StrEnumDefines the supported logging levels for the application.
- CRITICAL = 'CRITICAL'¶
- DEBUG = 'DEBUG'¶
- ERROR = 'ERROR'¶
- INFO = 'INFO'¶
- TRACE = 'TRACE'¶
- WARNING = 'WARNING'¶
- class code_validator.config.SelectorConfig(type: str, name: str | None = None, node_type: str | list[str] | None = None, in_scope: str | dict[str, Any] | None = None)¶
Bases:
objectRepresents the configuration for a Selector component from a JSON rule.
This dataclass captures all possible keys within the “selector” block of a JSON validation rule.
- type¶
The type of the selector to be used (e.g., “function_def”).
- Type:
str
- name¶
A generic name parameter used by many selectors (e.g., the name of a function, class, or module).
- Type:
str | None
- node_type¶
The AST node type name for the ast_node selector.
- Type:
str | list[str] | None
- in_scope¶
The scope in which to apply the selector.
- Type:
str | dict[str, Any] | None
- in_scope: str | dict[str, Any] | None = None¶
- name: str | None = None¶
- node_type: str | list[str] | None = None¶
- type: str¶
- class code_validator.config.ShortRuleConfig(rule_id: int, type: str, message: str, params: dict[str, ~typing.Any] = <factory>)¶
Bases:
objectRepresents a ‘short’ (pre-defined) validation rule from JSON.
- rule_id¶
The unique integer identifier for the rule.
- Type:
int
- type¶
The string identifier for the short rule (e.g., “check_syntax”).
- Type:
str
- message¶
The error message to display if the rule fails.
- Type:
str
- params¶
A dictionary of optional parameters for the rule.
- Type:
dict[str, Any]
- message: str¶
- params: dict[str, Any]¶
- rule_id: int¶
- type: str¶