Skip to content

Commit f93b096

Browse files
authored
Check if output is decorated (#9)
* Check if output is decorated When the output is not decorated (`--no-ansi`), we can skip highlighting the error, as it won't have any effect anyway. The filenames will not be clickable and therefore we don't have to trim them. Since `Output::isDecorated` was recently introduced in PHPStan we need to bump the minimum requirement to `1.12.4` * Keep Composer packages sorted
1 parent fa5f462 commit f93b096

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

composer.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"keywords": ["phpstan", "dev"],
55
"type": "phpstan-extension",
66
"require": {
7-
"phpstan/phpstan": "^1.11",
8-
"php": "^8.2"
7+
"php": "^8.2",
8+
"phpstan/phpstan": "^1.12.4"
99
},
1010
"license": "MIT",
1111
"autoload": {
@@ -19,5 +19,8 @@
1919
"extension.neon"
2020
]
2121
}
22+
},
23+
"config": {
24+
"sort-packages": true
2225
}
2326
}

composer.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/TicketSwapErrorFormatter.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public function formatErrors(AnalysisResult $analysisResult, Output $output) : i
7575
$error->getTip()
7676
) : null,
7777
$error->getIdentifier(),
78+
$output->isDecorated(),
7879
),
7980
'{identifier}' => $error->getIdentifier(),
8081
'{links}' => implode([
@@ -84,13 +85,15 @@ public function formatErrors(AnalysisResult $analysisResult, Output $output) : i
8485
$error->getFilePath(),
8586
$this->relativePathHelper->getRelativePath($error->getFilePath()),
8687
$this->editorUrl,
88+
$output->isDecorated(),
8789
),
8890
$error->getTraitFilePath() !== null ? $this::link(
8991
$this->linkFormat,
9092
(int) $error->getLine(),
9193
$error->getTraitFilePath(),
9294
$this->relativePathHelper->getRelativePath($error->getTraitFilePath()),
9395
$this->editorUrl,
96+
$output->isDecorated(),
9497
) : '',
9598
]),
9699
],
@@ -122,9 +125,10 @@ public static function link(
122125
int $line,
123126
string $absolutePath,
124127
string $relativePath,
125-
?string $editorUrl
128+
?string $editorUrl,
129+
bool $isDecorated,
126130
) : string {
127-
if ($editorUrl === null) {
131+
if (!$isDecorated || $editorUrl === null) {
128132
$format = self::LINK_FORMAT_WITHOUT_EDITOR;
129133
}
130134

@@ -161,8 +165,12 @@ private static function trimPath(string $path) : string
161165
);
162166
}
163167

164-
public static function highlight(string $message, ?string $tip, ?string $identifier) : string
168+
public static function highlight(string $message, ?string $tip, ?string $identifier, bool $isDecorated) : string
165169
{
170+
if (!$isDecorated) {
171+
return $message;
172+
}
173+
166174
if (str_starts_with($message, 'Ignored error pattern')) {
167175
return $message;
168176
}

0 commit comments

Comments
 (0)