-
Notifications
You must be signed in to change notification settings - Fork 4
Use PHPStan's editorUrl
and add example on how to use Symfony's Console Hyperlinks
#18
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
Conversation
@jiripudil What do you think? |
) | ||
{ | ||
$this->relativePathHelper = $relativePathHelper; | ||
$this->format = $format; | ||
$this->editorUrl = $editorUrl ?? ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if this falls back to empty string? I presume symfony prints the escape sequence with an empty href – are terminals ok with it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would assume, that null
variant cannot happen, therefore it should be removed. Because there should be a reasonable default. In case it is missing, maybe write a notice into stderr output?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is fine as it is. If you want to use the editorUrl
then you already know that you need to set it (as per readme). Also, if you are using a custom error formatter, you kind of know what you are doing and also test it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add the error message to phpstan output & reasonable default when editorUrl
is null.
Hi, lgtm! @jkuchar what do you think? |
@@ -48,7 +53,8 @@ public function formatErrors( | |||
$this->format, | |||
[ | |||
'{absolutePath}' => $absolutePath, | |||
'{path}' => $this->relativePathHelper->getRelativePath($fileSpecificError->getFile()), | |||
'{editorUrl}' => str_replace(['%file%', '%line%'], [$absolutePath, $fileSpecificError->getLine() ?? ''], $this->editorUrl), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please extract into closure/function as parametr expansion can be separated:
$formatEditorUrl = fn(string $path, string $line) => str_replace(['%file%', '%line%'], [$path, $line], $this->editorUrl);
'{editorUrl}' => $formatEditorUrl($absolutePath, (string) ($fileSpecificError->getLine() ?? ''));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I decided to not use this package anymore, and use my own formatter because I wanted to do more modifications. Therefore I have no interest in updating the PR anymore. Should I close it? Or do we merge this as is?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also don't agree with that the proposed change is a better one tbh.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are those modifications? Feel free to open another PR for them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Color highlighting phpstan/phpstan-src#841 (comment)
Very opinionated and not in the scope of this library I would say.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no problem with keeping this the way it is. I idea here is to keep the formatting logic separated. No big deal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jiripudil Could you please fix the null param & merge this?
) | ||
{ | ||
$this->relativePathHelper = $relativePathHelper; | ||
$this->format = $format; | ||
$this->editorUrl = $editorUrl ?? ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add the error message to phpstan output & reasonable default when editorUrl
is null.
@@ -48,7 +53,8 @@ public function formatErrors( | |||
$this->format, | |||
[ | |||
'{absolutePath}' => $absolutePath, | |||
'{path}' => $this->relativePathHelper->getRelativePath($fileSpecificError->getFile()), | |||
'{editorUrl}' => str_replace(['%file%', '%line%'], [$absolutePath, $fileSpecificError->getLine() ?? ''], $this->editorUrl), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are those modifications? Feel free to open another PR for them.
Thanks for this simple but amazing error formatter.
I noticed that clicking the file path in my terminal (iTerm2) would open my default editor (VS Code) instead of my configured
editorUrl
PHPStorm.In this PR I added the
editorUrl
so that it's available inside the formatter. The file and line are replaced and then theeditorUrl
variable is available in the formatter.It uses the same replace format as PHPStan does, see: https://github.com/phpstan/phpstan-src/blob/0f2fbfff2d861e17345981f2c02ab7696a2298e3/src/Command/ErrorFormatter/TableErrorFormatter.php#L86
Together with Symfony's Console Hyperlinks you can now easily make the paths clickable for almost all terminals.