Source code for gxformat2.lint_profiles

"""Lint profile catalog loader.

Profiles group lint-rule IDs into named sets (``structural``,
``best-practices``, ``release``). Unknown IDs are tolerated — audit tooling
compares against the registered ``Linter`` subclasses to flag unimplemented
entries as INFO.
"""

import os

import yaml
from pydantic import BaseModel

LINT_PROFILES_PATH = os.path.join(os.path.dirname(__file__), "lint_profiles.yml")


[docs] class LintProfile(BaseModel): """Named set of lint-rule IDs loaded from lint_profiles.yml.""" id: str description: str = "" rules: list[str]
[docs] def load_lint_profiles() -> list[LintProfile]: """Parse lint_profiles.yml into validated ``LintProfile`` models.""" with open(LINT_PROFILES_PATH) as f: raw = yaml.safe_load(f) or {} profiles: list[LintProfile] = [] for profile_id, body in raw.items(): profiles.append(LintProfile(id=profile_id, **body)) return profiles
[docs] def lint_profiles_by_id() -> dict[str, LintProfile]: """Return profiles keyed by id.""" return {p.id: p for p in load_lint_profiles()}
[docs] def rules_for_profile(profile_id: str) -> list[str]: """Return the ordered rule ID list for a named profile.""" return lint_profiles_by_id()[profile_id].rules
[docs] def iwc_rule_ids() -> set[str]: """Union of structural, best-practices, and release rule IDs.""" profiles = lint_profiles_by_id() rule_ids: set[str] = set() for name in ("structural", "best-practices", "release"): if name in profiles: rule_ids.update(profiles[name].rules) return rule_ids