Coverage for lintro / ai / display / validation.py: 96%

26 statements  

« prev     ^ index     » next       coverage.py v7.13.0, created at 2026-04-03 18:53 +0000

1"""Fix validation rendering for terminal output.""" 

2 

3from __future__ import annotations 

4 

5import io 

6 

7from rich.console import Console 

8from rich.markup import escape 

9 

10from lintro.ai.validation import ValidationResult 

11from lintro.utils.console.constants import BORDER_LENGTH 

12 

13 

14def render_validation_terminal(result: ValidationResult) -> str: 

15 """Render fix validation results for terminal output. 

16 

17 Args: 

18 result: Validation result to render. 

19 

20 Returns: 

21 Formatted string for terminal display. 

22 """ 

23 buf = io.StringIO() 

24 console = Console( 

25 file=buf, 

26 force_terminal=True, 

27 highlight=False, 

28 width=BORDER_LENGTH, 

29 ) 

30 

31 total = result.verified + result.unverified + result.new_issues 

32 if total == 0 and not result.details: 

33 return "" 

34 

35 parts: list[str] = [] 

36 if result.verified: 

37 parts.append(f"[green]{result.verified} resolved[/green]") 

38 if result.unverified: 

39 parts.append(f"[yellow]{result.unverified} still present[/yellow]") 

40 if result.new_issues: 

41 parts.append(f"[red]{result.new_issues} remaining unmatched issues[/red]") 

42 sep = " \u00b7 " 

43 console.print(f" [bold]Fix validation:[/bold] {sep.join(parts)}") 

44 

45 for detail in result.details: 

46 console.print(f" [yellow]![/yellow] {escape(detail)}") 

47 

48 return buf.getvalue() 

49 

50 

51def render_validation(result: ValidationResult) -> str: 

52 """Render validation as terminal-formatted output. 

53 

54 Args: 

55 result: Validation result to render. 

56 

57 Returns: 

58 Formatted validation string for terminal display. 

59 """ 

60 return render_validation_terminal(result)