Skip to content

TableErrorFormatter: improve formatting of error tips #3821

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

Open
wants to merge 3 commits into
base: 2.1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/Command/ErrorFormatter/TableErrorFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use function getenv;
use function is_string;
use function ltrim;
use function rtrim;
use function sprintf;
use function str_contains;
use function str_replace;
Expand Down Expand Up @@ -92,10 +93,11 @@ public function formatErrors(
if (str_contains($tip, "\n")) {
$lines = explode("\n", $tip);
foreach ($lines as $line) {
$message .= '💡 ' . ltrim($line, ' •') . "\n";
$message .= '💡 ' . ltrim($line, ' •') . "\n";
}
$message = rtrim($message, "\n");
} else {
$message .= '💡 ' . $tip;
$message .= '💡 ' . $tip;
}
}
if (is_string($this->editorUrl)) {
Expand Down
20 changes: 10 additions & 10 deletions tests/PHPStan/Command/ErrorFormatter/TableErrorFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ public function dataFormatterOutputProvider(): iterable
4 Foo
------ -------------------------------------------------------------------

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

[ERROR] Found 4 errors

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

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

-- -----------------------
Error
Expand Down Expand Up @@ -195,7 +195,7 @@ public function dataFormatterOutputProvider(): iterable
------ ----------------
5 Foobar\Buz
🪪 foobar.buz
💡 a tip
💡 a tip
------ ----------------


Expand All @@ -216,7 +216,7 @@ public function dataFormatterOutputProvider(): iterable
------ ----------------
5 Foobar\Buz
🪪 foobar.buz
💡 a tip
💡 a tip
------ ----------------


Expand Down
Loading