Coverage for lintro / utils / console / constants.py: 89%
18 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"""Console constants and helper functions.
3This module contains shared constants and utility functions used by
4console output classes.
5"""
7from __future__ import annotations
9import re
10from typing import Any
12# =============================================================================
13# Emoji and Formatting Constants
14# =============================================================================
16TOOL_EMOJIS: dict[str, str] = {
17 "ruff": "🦀",
18 "pydoclint": "📝",
19 "hadolint": "🐳",
20 "yamllint": "📄",
21 "black": "🖤",
22 "pytest": "🧪",
23 "markdownlint": "🔧",
24 "actionlint": "🔧",
25 "bandit": "🔧",
26 "oxlint": "⚡",
27 "oxfmt": "✨",
28 "prettier": "💅",
29}
30DEFAULT_EMOJI: str = "🔧"
31BORDER_LENGTH: int = 70
32INFO_BORDER_LENGTH: int = 70
33DEFAULT_REMAINING_COUNT: str = "?"
35# =============================================================================
36# Regex Patterns
37# =============================================================================
39# Regex patterns used to parse tool outputs for remaining issue counts
40RE_CANNOT_AUTOFIX: re.Pattern[str] = re.compile(
41 r"Found\s+(\d+)\s+issue(?:s)?\s+that\s+cannot\s+be\s+auto-fixed",
42)
43RE_REMAINING_OR_CANNOT: re.Pattern[str] = re.compile(
44 r"(\d+)\s+(?:issue\(s\)\s+)?(?:that\s+cannot\s+be\s+auto-fixed|remaining)",
45)
48# =============================================================================
49# Helper Functions
50# =============================================================================
53def get_tool_emoji(tool_name: str) -> str:
54 """Get emoji for a tool.
56 Args:
57 tool_name: str: Name of the tool.
59 Returns:
60 str: Emoji for the tool.
61 """
62 return TOOL_EMOJIS.get(tool_name, DEFAULT_EMOJI)
65def get_summary_value(
66 summary: dict[str, Any] | object,
67 key: str,
68 default: int | float = 0,
69) -> int | float:
70 """Extract value from summary dict or object.
72 Args:
73 summary: Summary data as dict or dataclass.
74 key: Attribute/key name.
75 default: Default value if not found.
77 Returns:
78 int | float: The extracted value or default.
79 """
80 if isinstance(summary, dict):
81 value = summary.get(key, default)
82 return value if isinstance(value, (int, float)) else default
83 value = getattr(summary, key, default)
84 return value if isinstance(value, (int, float)) else default