1"""Pattern mappings builder for Crackerjack output parsing.

2

3 This module provides a builder pattern for creating pattern mapping configurations

4 used in parsing Crackerjack tool output.

5"""

6

7 from __future__ import annotations

8

9

10 class PatternMappingsBuilder:

11 """Builder for creating pattern mappings configuration."""

12

13 def __init__(self) -> None:

14 """Initialize pattern mappings builder."""

15 self._patterns: dict[str, str] = {}

16

17 def add_test_patterns(self) -> PatternMappingsBuilder:

18 """Add test-related patterns."""

19 test_patterns = {

20 "pytest_result": "pytest_result",

21 "pytest_summary": "pytest_result",

22 "pytest_coverage": "coverage_summary",

23 }

24 self._patterns.update(test_patterns)

25 return self

26

27 def add_lint_patterns(self) -> PatternMappingsBuilder:

28 """Add linting-related patterns."""

29 lint_patterns = {

30 "ruff_error": "ruff_error",

31 "pyright_error": "mypy_error",

32 }

33 self._patterns.update(lint_patterns)

34 return self

35

36 def add_security_patterns(self) -> PatternMappingsBuilder:

37 """Add security-related patterns."""

38 security_patterns = {

39 "bandit_issue": "bandit_finding",

40 "bandit_severity": "bandit_finding",

41 }

42 self._patterns.update(security_patterns)

43 return self

44

45 def add_quality_patterns(self) -> PatternMappingsBuilder:

46 """Add quality-related patterns."""

47 quality_patterns = {

48 "quality_score": "quality_score",

49 "complexity_score": "quality_score",

50 }

51 self._patterns.update(quality_patterns)

52 return self

53

54 def add_progress_patterns(self) -> PatternMappingsBuilder:

55 """Add progress-related patterns."""

56 progress_patterns = {

57 "progress_indicator": "progress_indicator",

58 "percentage": "progress_indicator",

59 "task_completion": "progress_indicator",

60 "task_failure": "progress_indicator",

61 }

62 self._patterns.update(progress_patterns)

63 return self

64

65 def add_coverage_patterns(self) -> PatternMappingsBuilder:

66 """Add coverage-related patterns."""

67 coverage_patterns = {

68 "coverage_line": "coverage_summary",

69 }

70 self._patterns.update(coverage_patterns)

71 return self

72

73 def add_misc_patterns(self) -> PatternMappingsBuilder:

74 """Add miscellaneous patterns."""

75 misc_patterns = {

76 "git_commit": "git_commit_hash",

77 "file_path_line": "file_path_with_line",

78 "execution_time": "execution_time",

79 }

80 self._patterns.update(misc_patterns)

81 return self

82

83 def build(self) -> dict[str, str]:

84 """Build the final pattern mappings dictionary."""

85 return self._patterns.copy()