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

1"""Yamllint format enum.""" 

2 

3from __future__ import annotations 

4 

5from enum import StrEnum, auto 

6 

7from loguru import logger 

8 

9 

10class YamllintFormat(StrEnum): 

11 """Output styles supported by Yamllint's CLI.""" 

12 

13 PARSABLE = auto() 

14 STANDARD = auto() 

15 COLORED = auto() 

16 GITHUB = auto() 

17 AUTO = auto() 

18 

19 

20def normalize_yamllint_format(value: str | YamllintFormat) -> YamllintFormat: 

21 """Normalize a value to a YamllintFormat enum member. 

22 

23 Args: 

24 value: Existing enum member or string name of the format. 

25 

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