Coverage for tests / unit / parsers / test_prettier_parser.py: 100%
45 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"""Unit tests for prettier parser."""
3from __future__ import annotations
5import pytest
6from assertpy import assert_that
8from lintro.parsers.prettier.prettier_parser import parse_prettier_output
11@pytest.mark.parametrize(
12 "output",
13 [
14 "",
15 "Checking formatting...\nAll matched files use Prettier code style!",
16 ],
17 ids=["empty", "no_issues"],
18)
19def test_parse_prettier_output_returns_empty_for_no_issues(output: str) -> None:
20 """Parse output with no issues returns empty list.
22 Args:
23 output: The prettier output to parse.
24 """
25 result = parse_prettier_output(output)
26 assert_that(result).is_empty()
29def test_parse_prettier_output_single_file_issue() -> None:
30 """Parse single file with formatting issue."""
31 output = """Checking formatting...
32[warn] src/main.js
33[warn] Code style issues found in the above file. Run Prettier with --write to fix."""
34 result = parse_prettier_output(output)
35 assert_that(result).is_length(1)
36 assert_that(result[0].file).is_equal_to("src/main.js")
37 assert_that(result[0].code).is_equal_to("FORMAT")
38 assert_that(result[0].message).is_equal_to("Code style issues found")
41def test_parse_prettier_output_multiple_file_issues() -> None:
42 """Parse multiple files with formatting issues."""
43 output = """Checking formatting...
44[warn] src/a.js
45[warn] src/b.ts
46[warn] src/c.json
47[warn] Code style issues found in the above files. Run Prettier with --write to fix."""
48 result = parse_prettier_output(output)
49 assert_that(result).is_length(3)
50 assert_that(result[0].file).is_equal_to("src/a.js")
51 assert_that(result[1].file).is_equal_to("src/b.ts")
52 assert_that(result[2].file).is_equal_to("src/c.json")
55def test_parse_prettier_output_ansi_escape_codes_stripped() -> None:
56 """Strip ANSI escape codes from output."""
57 output = "[\x1b[33mwarn\x1b[39m] src/file.js"
58 result = parse_prettier_output(output)
59 assert_that(result).is_length(1)
60 assert_that(result[0].file).is_equal_to("src/file.js")
63def test_parse_prettier_output_ignores_code_style_message() -> None:
64 """Ignore the 'Code style issues' summary line."""
65 output = """[warn] src/file.js
66[warn] Code style issues found in the above file. Run Prettier with --write to fix."""
67 result = parse_prettier_output(output)
68 assert_that(result).is_length(1)
69 assert_that(result[0].file).is_equal_to("src/file.js")
72def test_parse_prettier_output_blank_lines_ignored() -> None:
73 """Blank lines are ignored."""
74 output = """[warn] src/a.js
76[warn] src/b.js"""
77 result = parse_prettier_output(output)
78 assert_that(result).is_length(2)
81def test_parse_prettier_output_default_line_and_column() -> None:
82 """Default line and column are 1."""
83 output = "[warn] src/file.js"
84 result = parse_prettier_output(output)
85 assert_that(result[0].line).is_equal_to(1)
86 assert_that(result[0].column).is_equal_to(1)
89def test_parse_prettier_output_non_warn_lines_ignored() -> None:
90 """Lines not starting with [warn] are ignored."""
91 output = """Checking formatting...
92[info] Some info message
93[warn] src/file.js
94All done!"""
95 result = parse_prettier_output(output)
96 assert_that(result).is_length(1)