Coverage for lintro / formatters / styles / plain.py: 100%

14 statements  

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

1"""Plain text output style implementation.""" 

2 

3from typing import Any 

4 

5from lintro.formatters.core.format_registry import OutputStyle 

6 

7 

8class PlainStyle(OutputStyle): 

9 """Output format that renders data as plain text.""" 

10 

11 def format( 

12 self, 

13 columns: list[str], 

14 rows: list[list[Any]], 

15 tool_name: str | None = None, 

16 **kwargs: Any, 

17 ) -> str: 

18 """Format a table given columns and rows as plain text. 

19 

20 Args: 

21 columns: List of column header names. 

22 rows: List of row values (each row is a list of cell values). 

23 tool_name: Optional tool name to include in context. 

24 **kwargs: Extra options ignored by this formatter. 

25 

26 Returns: 

27 Formatted data as plain text string. 

28 """ 

29 if not rows: 

30 return "No issues found." 

31 

32 # Build the header 

33 header = " | ".join(columns) 

34 separator = "-" * len(header) 

35 

36 # Build the rows 

37 formatted_rows = [] 

38 for row in rows: 

39 # Ensure row has same number of elements as columns 

40 padded_row = row + [""] * (len(columns) - len(row)) 

41 formatted_rows.append(" | ".join(str(cell) for cell in padded_row)) 

42 

43 # Combine all parts 

44 result = [header, separator] + formatted_rows 

45 return "\n".join(result)