Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tip message to JSON error formatter #1727

Merged
merged 2 commits into from Oct 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/Command/ErrorFormatter/JsonErrorFormatter.php
Expand Up @@ -36,11 +36,17 @@ public function formatErrors(AnalysisResult $analysisResult, Output $output): in
}
$errorsArray['files'][$file]['errors']++;

$errorsArray['files'][$file]['messages'][] = [
$message = [
'message' => $fileSpecificError->getMessage(),
'line' => $fileSpecificError->getLine(),
'ignorable' => $fileSpecificError->canBeIgnored(),
];

if ($fileSpecificError->getTip() !== null) {
$message['tip'] = $fileSpecificError->getTip();
}

$errorsArray['files'][$file]['messages'][] = $message;
}

foreach ($analysisResult->getNotFileSpecificErrors() as $notFileSpecificError) {
Expand Down
2 changes: 1 addition & 1 deletion src/Testing/ErrorFormatterTestCase.php
Expand Up @@ -81,7 +81,7 @@ protected function getAnalysisResult(int $numFileErrors, int $numGenericErrors):
$fileErrors = array_slice([
new Error('Foo', self::DIRECTORY_PATH . '/folder with unicode 😃/file name with "spaces" and unicode 😃.php', 4),
new Error('Foo', self::DIRECTORY_PATH . '/foo.php', 1),
new Error("Bar\nBar2", self::DIRECTORY_PATH . '/foo.php', 5),
new Error("Bar\nBar2", self::DIRECTORY_PATH . '/foo.php', 5, true, null, null, 'a tip'),
new Error("Bar\nBar2", self::DIRECTORY_PATH . '/folder with unicode 😃/file name with "spaces" and unicode 😃.php', 2),
new Error("Bar\nBar2", self::DIRECTORY_PATH . '/foo.php', null),
], 0, $numFileErrors);
Expand Down
4 changes: 4 additions & 0 deletions src/Testing/LevelsTestCase.php
Expand Up @@ -110,6 +110,8 @@ public function testLevels(
}
}

unset($message['tip']);

$messages[] = $message;
}

Expand All @@ -124,6 +126,8 @@ public function testLevels(
}
}

unset($previousMessage['tip']);

$missingMessages[] = $previousMessage;
}

Expand Down
Expand Up @@ -109,7 +109,8 @@ public function dataFormatterOutputProvider(): iterable
{
"message": "Bar\nBar2",
"line": 5,
"ignorable": true
"ignorable": true,
"tip": "a tip"
}
]
}
Expand Down Expand Up @@ -175,7 +176,8 @@ public function dataFormatterOutputProvider(): iterable
{
"message": "Bar\nBar2",
"line": 5,
"ignorable": true
"ignorable": true,
"tip": "a tip"
}
]
}
Expand Down
14 changes: 8 additions & 6 deletions tests/PHPStan/Command/ErrorFormatter/TableErrorFormatterTest.php
Expand Up @@ -85,13 +85,14 @@ public function dataFormatterOutputProvider(): iterable
4 Foo
------ -------------------------------------------------------------------

------ ---------
------ ----------
Line foo.php
------ ---------
------ ----------
1 Foo
5 Bar
Bar2
------ ---------
💡 a tip
------ ----------

[ERROR] Found 4 errors

Expand Down Expand Up @@ -129,13 +130,14 @@ public function dataFormatterOutputProvider(): iterable
4 Foo
------ -------------------------------------------------------------------

------ ---------
------ ----------
Line foo.php
------ ---------
------ ----------
1 Foo
5 Bar
Bar2
------ ---------
💡 a tip
------ ----------

-- ----------------------
Error
Expand Down
Expand Up @@ -49,7 +49,7 @@ public function dataFormatterOutputProvider(): iterable
##teamcity[inspection typeId=\'phpstan\' message=\'Bar||nBar2\' file=\'folder with unicode 😃/file name with "spaces" and unicode 😃.php\' line=\'2\' SEVERITY=\'ERROR\' ignorable=\'1\' tip=\'\']
##teamcity[inspection typeId=\'phpstan\' message=\'Foo\' file=\'folder with unicode 😃/file name with "spaces" and unicode 😃.php\' line=\'4\' SEVERITY=\'ERROR\' ignorable=\'1\' tip=\'\']
##teamcity[inspection typeId=\'phpstan\' message=\'Foo\' file=\'foo.php\' line=\'1\' SEVERITY=\'ERROR\' ignorable=\'1\' tip=\'\']
##teamcity[inspection typeId=\'phpstan\' message=\'Bar||nBar2\' file=\'foo.php\' line=\'5\' SEVERITY=\'ERROR\' ignorable=\'1\' tip=\'\']
##teamcity[inspection typeId=\'phpstan\' message=\'Bar||nBar2\' file=\'foo.php\' line=\'5\' SEVERITY=\'ERROR\' ignorable=\'1\' tip=\'a tip\']
',
];

Expand All @@ -73,7 +73,7 @@ public function dataFormatterOutputProvider(): iterable
##teamcity[inspection typeId=\'phpstan\' message=\'Bar||nBar2\' file=\'folder with unicode 😃/file name with "spaces" and unicode 😃.php\' line=\'2\' SEVERITY=\'ERROR\' ignorable=\'1\' tip=\'\']
##teamcity[inspection typeId=\'phpstan\' message=\'Foo\' file=\'folder with unicode 😃/file name with "spaces" and unicode 😃.php\' line=\'4\' SEVERITY=\'ERROR\' ignorable=\'1\' tip=\'\']
##teamcity[inspection typeId=\'phpstan\' message=\'Foo\' file=\'foo.php\' line=\'1\' SEVERITY=\'ERROR\' ignorable=\'1\' tip=\'\']
##teamcity[inspection typeId=\'phpstan\' message=\'Bar||nBar2\' file=\'foo.php\' line=\'5\' SEVERITY=\'ERROR\' ignorable=\'1\' tip=\'\']
##teamcity[inspection typeId=\'phpstan\' message=\'Bar||nBar2\' file=\'foo.php\' line=\'5\' SEVERITY=\'ERROR\' ignorable=\'1\' tip=\'a tip\']
##teamcity[inspection typeId=\'phpstan\' message=\'first generic error\' file=\'.\' SEVERITY=\'ERROR\']
##teamcity[inspection typeId=\'phpstan\' message=\'second generic error\' file=\'.\' SEVERITY=\'ERROR\']
',
Expand Down