Coverage for lintro / enums / yamllint_format.py: 82%
17 statements
« prev ^ index » next coverage.py v7.13.0, created at 2026-04-03 18:53 +0000
« prev ^ index » next coverage.py v7.13.0, created at 2026-04-03 18:53 +0000
1"""Yamllint format enum."""
3from __future__ import annotations
5from enum import StrEnum, auto
7from loguru import logger
10class YamllintFormat(StrEnum):
11 """Output styles supported by Yamllint's CLI."""
13 PARSABLE = auto()
14 STANDARD = auto()
15 COLORED = auto()
16 GITHUB = auto()
17 AUTO = auto()
20def normalize_yamllint_format(value: str | YamllintFormat) -> YamllintFormat:
21 """Normalize a value to a YamllintFormat enum member.
23 Args:
24 value: Existing enum member or string name of the format.
26 Returns:
27 YamllintFormat: Canonical enum value, defaulting to ``PARSABLE`` when
28 parsing fails.
29 """
30 if isinstance(value, YamllintFormat):
31 return value
32 try:
33 return YamllintFormat[value.upper()]
34 except (KeyError, AttributeError) as e:
35 logger.debug(
36 f"Invalid YamllintFormat value '{value}': {e}. Defaulting to PARSABLE.",
37 )
38 return YamllintFormat.PARSABLE