From 08ef6ce4e4bcbfd8692fb5354a49ecba390bdbf1 Mon Sep 17 00:00:00 2001 From: Felix Bernhard Date: Wed, 12 Feb 2025 12:18:40 +0100 Subject: [PATCH 1/4] improve table error formatting --- src/Command/ErrorFormatter/TableErrorFormatter.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Command/ErrorFormatter/TableErrorFormatter.php b/src/Command/ErrorFormatter/TableErrorFormatter.php index 7da56bdff1..87fffce867 100644 --- a/src/Command/ErrorFormatter/TableErrorFormatter.php +++ b/src/Command/ErrorFormatter/TableErrorFormatter.php @@ -92,10 +92,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)) { From 1a5b7be1b17890176eb96de2be18a0dc6a141a0f Mon Sep 17 00:00:00 2001 From: Felix Bernhard Date: Wed, 12 Feb 2025 12:39:49 +0100 Subject: [PATCH 2/4] fix table error formatter test --- .../TableErrorFormatterTest.php | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/PHPStan/Command/ErrorFormatter/TableErrorFormatterTest.php b/tests/PHPStan/Command/ErrorFormatter/TableErrorFormatterTest.php index 40db6547a8..1622363910 100644 --- a/tests/PHPStan/Command/ErrorFormatter/TableErrorFormatterTest.php +++ b/tests/PHPStan/Command/ErrorFormatter/TableErrorFormatterTest.php @@ -94,14 +94,14 @@ public function dataFormatterOutputProvider(): iterable 4 Foo ------ ------------------------------------------------------------------- - ------ ---------- + ------ ----------- Line foo.php - ------ ---------- + ------ ----------- 1 Foo 5 Bar Bar2 - šŸ’” a tip - ------ ---------- + šŸ’” a tip + ------ ----------- [ERROR] Found 4 errors @@ -143,14 +143,14 @@ public function dataFormatterOutputProvider(): iterable 4 Foo ------ ------------------------------------------------------------------- - ------ ---------- + ------ ----------- Line foo.php - ------ ---------- + ------ ----------- 1 Foo 5 Bar Bar2 - šŸ’” a tip - ------ ---------- + šŸ’” a tip + ------ ----------- -- ----------------------- Error @@ -195,7 +195,7 @@ public function dataFormatterOutputProvider(): iterable ------ ---------------- 5 Foobar\Buz 🪪 foobar.buz - šŸ’” a tip + šŸ’” a tip ------ ---------------- @@ -216,7 +216,7 @@ public function dataFormatterOutputProvider(): iterable ------ ---------------- 5 Foobar\Buz 🪪 foobar.buz - šŸ’” a tip + šŸ’” a tip ------ ---------------- From 0d642a5bff7f2a7ff628f72d91acfade76bed387 Mon Sep 17 00:00:00 2001 From: Felix Bernhard Date: Wed, 12 Feb 2025 12:55:26 +0100 Subject: [PATCH 3/4] use function rtrim --- src/Command/ErrorFormatter/TableErrorFormatter.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Command/ErrorFormatter/TableErrorFormatter.php b/src/Command/ErrorFormatter/TableErrorFormatter.php index 87fffce867..17ae3c1da8 100644 --- a/src/Command/ErrorFormatter/TableErrorFormatter.php +++ b/src/Command/ErrorFormatter/TableErrorFormatter.php @@ -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; From 59a003a4bf84b319d94fd2a4ff43a5870c316923 Mon Sep 17 00:00:00 2001 From: Felix Bernhard Date: Mon, 5 May 2025 10:44:45 +0200 Subject: [PATCH 4/4] use one instead of two spaces --- .../ErrorFormatter/TableErrorFormatter.php | 8 ++--- .../TableErrorFormatterTest.php | 36 +++++++++---------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/Command/ErrorFormatter/TableErrorFormatter.php b/src/Command/ErrorFormatter/TableErrorFormatter.php index 17ae3c1da8..b0cf5f90fc 100644 --- a/src/Command/ErrorFormatter/TableErrorFormatter.php +++ b/src/Command/ErrorFormatter/TableErrorFormatter.php @@ -83,7 +83,7 @@ public function formatErrors( $filePath = $error->getTraitFilePath() ?? $error->getFilePath(); if ($error->getIdentifier() !== null && $error->canBeIgnored()) { $message .= "\n"; - $message .= '🪪 ' . $error->getIdentifier(); + $message .= '🪪 ' . $error->getIdentifier(); } if ($error->getTip() !== null) { $tip = $error->getTip(); @@ -93,11 +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)) { @@ -117,7 +117,7 @@ public function formatErrors( $title = $this->relativePathHelper->getRelativePath($filePath); } - $message .= "\nāœļø ' . $title . ''; + $message .= "\nāœļø ' . $title . ''; } $rows[] = [ $this->formatLineNumber($error->getLine()), diff --git a/tests/PHPStan/Command/ErrorFormatter/TableErrorFormatterTest.php b/tests/PHPStan/Command/ErrorFormatter/TableErrorFormatterTest.php index 1622363910..1ada3c4624 100644 --- a/tests/PHPStan/Command/ErrorFormatter/TableErrorFormatterTest.php +++ b/tests/PHPStan/Command/ErrorFormatter/TableErrorFormatterTest.php @@ -94,14 +94,14 @@ public function dataFormatterOutputProvider(): iterable 4 Foo ------ ------------------------------------------------------------------- - ------ ----------- + ------ ---------- Line foo.php - ------ ----------- + ------ ---------- 1 Foo 5 Bar Bar2 - šŸ’” a tip - ------ ----------- + šŸ’” a tip + ------ ---------- [ERROR] Found 4 errors @@ -143,14 +143,14 @@ public function dataFormatterOutputProvider(): iterable 4 Foo ------ ------------------------------------------------------------------- - ------ ----------- + ------ ---------- Line foo.php - ------ ----------- + ------ ---------- 1 Foo 5 Bar Bar2 - šŸ’” a tip - ------ ----------- + šŸ’” a tip + ------ ---------- -- ----------------------- Error @@ -190,13 +190,13 @@ public function dataFormatterOutputProvider(): iterable 'numGenericErrors' => 0, 'verbose' => false, 'extraEnvVars' => [], - 'expected' => ' ------ ---------------- + 'expected' => ' ------ --------------- Line foo.php - ------ ---------------- + ------ --------------- 5 Foobar\Buz - 🪪 foobar.buz - šŸ’” a tip - ------ ---------------- + 🪪 foobar.buz + šŸ’” a tip + ------ --------------- [ERROR] Found 1 error @@ -211,13 +211,13 @@ public function dataFormatterOutputProvider(): iterable 'numGenericErrors' => 0, 'verbose' => true, 'extraEnvVars' => [], - 'expected' => ' ------ ---------------- + 'expected' => ' ------ --------------- Line foo.php - ------ ---------------- + ------ --------------- 5 Foobar\Buz - 🪪 foobar.buz - šŸ’” a tip - ------ ---------------- + 🪪 foobar.buz + šŸ’” a tip + ------ --------------- [ERROR] Found 1 error