Skip to content

Commit c028b74

Browse files
[primer] Switch from JSONReporter to JSON2Reporter
The old JSONReporter is deprecated; use JSON2Reporter which provides confidence, absolutePath, and camelCase messageId fields. Update all primer test fixtures accordingly.
1 parent 3c6ecaa commit c028b74

23 files changed

Lines changed: 152 additions & 43 deletions

File tree

pylint/testutils/_primer/comparator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from collections.abc import Generator
99
from pathlib import Path
1010

11-
from pylint.reporters.json_reporter import OldJsonExport
11+
from pylint.reporters.json_reporter import JSONMessage
1212
from pylint.testutils._primer.primer_command import (
1313
PackageData,
1414
PackageMessages,
@@ -51,7 +51,7 @@ def __iter__(self) -> Generator[tuple[str, PackageData, PackageData]]:
5151

5252
missing_messages: PackageMessages = {}
5353
for package, data in main_data.items():
54-
package_missing_messages: list[OldJsonExport] = []
54+
package_missing_messages: list[JSONMessage] = []
5555
for message in data["messages"]:
5656
try:
5757
pr_data[package]["messages"].remove(message)

pylint/testutils/_primer/primer_command.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
from pathlib import Path
1010
from typing import TypedDict
1111

12-
from pylint.reporters.json_reporter import OldJsonExport
12+
from pylint.reporters.json_reporter import JSONMessage
1313
from pylint.testutils._primer import PackageToLint
1414

1515

1616
class PackageData(TypedDict):
1717
commit: str
18-
messages: list[OldJsonExport]
18+
messages: list[JSONMessage]
1919

2020

2121
PackageMessages = dict[str, PackageData]

pylint/testutils/_primer/primer_run_command.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
from pylint.lint import Run
1515
from pylint.message import Message
16-
from pylint.reporters.json_reporter import JSONReporter, OldJsonExport
16+
from pylint.reporters.json_reporter import JSON2Reporter, JSONMessage
1717
from pylint.testutils._primer.package_to_lint import PackageToLint
1818
from pylint.testutils._primer.primer_command import (
1919
PackageData,
@@ -57,12 +57,12 @@ def run(self) -> None:
5757

5858
@staticmethod
5959
def _filter_fatal_errors(
60-
messages: list[OldJsonExport],
60+
messages: list[JSONMessage],
6161
) -> list[Message]:
6262
"""Separate fatal errors so we can report them independently."""
6363
fatal_msgs: list[Message] = []
6464
for raw_message in messages:
65-
message = JSONReporter.deserialize(raw_message)
65+
message = JSON2Reporter.deserialize(raw_message)
6666
if message.category == "fatal":
6767
if GITHUB_CRASH_TEMPLATE_LOCATION in message.msg:
6868
# Remove the crash template location if we're running on GitHub.
@@ -73,11 +73,11 @@ def _filter_fatal_errors(
7373

7474
@staticmethod
7575
def _print_msgs(msgs: list[Message]) -> str:
76-
return "\n".join(f"- {JSONReporter.serialize(m)}" for m in msgs)
76+
return "\n".join(f"- {JSON2Reporter.serialize(m)}" for m in msgs)
7777

7878
def _lint_package(
7979
self, package_name: str, data: PackageToLint
80-
) -> tuple[list[OldJsonExport], list[Message]]:
80+
) -> tuple[list[JSONMessage], list[Message]]:
8181
# We want to test all the code we can
8282
enables = ["--enable-all-extensions", "--enable=all"]
8383
# Duplicate code takes too long and is relatively safe
@@ -86,15 +86,15 @@ def _lint_package(
8686
additional = ["--clear-cache-post-run=y"]
8787
arguments = data.pylint_args + enables + disables + additional
8888
output = StringIO()
89-
reporter = JSONReporter(output)
89+
reporter = JSON2Reporter(output)
9090
print(f"Running 'pylint {', '.join(arguments)}'")
9191
pylint_exit_code = -1
9292
try:
9393
Run(arguments, reporter=reporter)
9494
except SystemExit as e:
9595
pylint_exit_code = int(e.code) # type: ignore[arg-type]
9696
readable_messages: str = output.getvalue()
97-
messages: list[OldJsonExport] = json.loads(readable_messages)
97+
messages: list[JSONMessage] = json.loads(readable_messages)["messages"]
9898
fatal_msgs: list[Message] = []
9999
if pylint_exit_code % 2 == 0:
100100
print(f"Successfully primed {package_name}.")

tests/testutils/_primer/batched_cases/main_batch1.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
"path": "tests/.pylint_primer_tests/pylint-dev/astroid/astroid/__init__.py",
1414
"symbol": "locally-disabled",
1515
"message": "Locally disabling redefined-builtin (W0622)",
16-
"message-id": "I0011"
16+
"messageId": "I0011",
17+
"confidence": "UNDEFINED",
18+
"absolutePath": "tests/.pylint_primer_tests/pylint-dev/astroid/astroid/__init__.py"
1719
},
1820
{
1921
"type": "warning",
@@ -26,7 +28,9 @@
2628
"path": "tests/.pylint_primer_tests/pylint-dev/astroid/astroid/__init__.py",
2729
"symbol": "unknown-option-value",
2830
"message": "Unknown option value for 'disable', expected a valid pylint message and got 'Ellipsis'",
29-
"message-id": "W0012"
31+
"messageId": "W0012",
32+
"confidence": "UNDEFINED",
33+
"absolutePath": "tests/.pylint_primer_tests/pylint-dev/astroid/astroid/__init__.py"
3034
}
3135
]
3236
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{ "package": "astroid", "missing": 1, "new": 1 }]
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"astroid": {
3+
"commit": "123456789abcdef",
4+
"messages": [
5+
{
6+
"type": "warning",
7+
"module": "astroid.inference",
8+
"obj": "infer_call",
9+
"line": 42,
10+
"column": 0,
11+
"endLine": 42,
12+
"endColumn": 15,
13+
"path": "tests/.pylint_primer_tests/pylint-dev/astroid/astroid/inference.py",
14+
"symbol": "dangerous-default-value",
15+
"message": "Dangerous default value [] as argument",
16+
"messageId": "W0102",
17+
"confidence": "UNDEFINED",
18+
"absolutePath": "tests/.pylint_primer_tests/pylint-dev/astroid/astroid/inference.py"
19+
}
20+
]
21+
}
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"astroid": {
3+
"commit": "123456789abcdef",
4+
"messages": [
5+
{
6+
"type": "warning",
7+
"module": "astroid.inference",
8+
"obj": "infer_call",
9+
"line": 42,
10+
"column": 0,
11+
"endLine": 42,
12+
"endColumn": 15,
13+
"path": "tests/.pylint_primer_tests/pylint-dev/astroid/astroid/inference.py",
14+
"symbol": "dangerous-default-value",
15+
"message": "Dangerous default value [] as argument",
16+
"messageId": "W0102",
17+
"confidence": "HIGH",
18+
"absolutePath": "tests/.pylint_primer_tests/pylint-dev/astroid/astroid/inference.py"
19+
}
20+
]
21+
}
22+
}

tests/testutils/_primer/cases/line_moved/main.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
"path": "tests/.pylint_primer_tests/pylint-dev/astroid/astroid/node_classes.py",
1414
"symbol": "too-complex",
1515
"message": "'my_function' is too complex. The McCabe rating is 18",
16-
"message-id": "R1260"
16+
"messageId": "R1260",
17+
"confidence": "UNDEFINED",
18+
"absolutePath": "tests/.pylint_primer_tests/pylint-dev/astroid/astroid/node_classes.py"
1719
}
1820
]
1921
}

tests/testutils/_primer/cases/line_moved/pr.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
"path": "tests/.pylint_primer_tests/pylint-dev/astroid/astroid/node_classes.py",
1414
"symbol": "too-complex",
1515
"message": "'my_function' is too complex. The McCabe rating is 18",
16-
"message-id": "R1260"
16+
"messageId": "R1260",
17+
"confidence": "UNDEFINED",
18+
"absolutePath": "tests/.pylint_primer_tests/pylint-dev/astroid/astroid/node_classes.py"
1719
}
1820
]
1921
}

tests/testutils/_primer/cases/message_changed/main.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
"path": "tests/.pylint_primer_tests/pylint-dev/astroid/astroid/__init__.py",
1414
"symbol": "locally-disabled",
1515
"message": "Locally disabling redefined-builtin (W0622)",
16-
"message-id": "I0011"
16+
"messageId": "I0011",
17+
"confidence": "UNDEFINED",
18+
"absolutePath": "tests/.pylint_primer_tests/pylint-dev/astroid/astroid/__init__.py"
1719
},
1820
{
1921
"type": "warning",
@@ -26,7 +28,9 @@
2628
"path": "tests/.pylint_primer_tests/pylint-dev/astroid/astroid/__init__.py",
2729
"symbol": "unknown-option-value",
2830
"message": "Unknown option value for 'disable', expected a valid pylint message and got 'Ellipsis'",
29-
"message-id": "W0012"
31+
"messageId": "W0012",
32+
"confidence": "UNDEFINED",
33+
"absolutePath": "tests/.pylint_primer_tests/pylint-dev/astroid/astroid/__init__.py"
3034
}
3135
]
3236
}

0 commit comments

Comments
 (0)