Skip to content

Conversation

ruudk
Copy link
Collaborator

@ruudk ruudk commented Oct 3, 2025

I would like to propose using a new (and better) error formatter for PHPStan.

Screenshot

Features

  • Every error has it's own clickable file + line link (default formatter shows the file once, and then displays the line + errors)
  • Errors don't wrap, so they take your while terminal (default formatter wraps in a table)
  • Highlighting of variables, fully qualified class names and other common types. This is done naively and there are cases where it does not work.
  • Long file paths are truncated visually (src/App/../Entity/User.php) while keeping the clickable link intact
  • The filename + line is clickable depending on your terminal and their support for clickable links. For example, in PHPStorm's built-in editor, it doesn't work and there we print file:///Volumes/CS/www/src/App/User.php.

See https://github.com/TicketSwap/phpstan-error-formatter

Curious what you think @spawnia @simPod

@ruudk ruudk marked this pull request as ready for review October 3, 2025 12:12
Comment on lines +5 to +6
errorFormat: ticketswap
editorUrl: 'phpstorm://open?file=%%file%%&line=%%line%%'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I prefer to set these in my phpstan.neon (that includes .dist and overrides individual settings) since other devs may have different preferences.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can still be overridden. Good to have a default?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer default defaults 🙃

E.g. on my projects I often output phpstan in github/gitlab CI and the default error format looks better there.
Then, locally I use ticketswap one.

Also for editorUrl, I use IDEA which is phpstorm:// compatible IIRC. Not sure about e.g. vscode though.
By that I wanted to say that it is also specific for each setup. And IMO that's what phpstan.neon is for.

I agree that those options are generally better for most developers. But there may be other environments where they may not make sense so I wanted to point that out.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My 2c:

  • I prefer the defaults in CI too, as @simPod said

    default error format looks better there

  • personally locally I prefer the raw format:

    Contains one error per line, with path to file, line number, and error description

    Once I discovered this, I knew there was no going back.

    I don't find value in:

    • having an error spawn multiple lines
      when all I need is quickly to read the reason
    • showing the source code
      There's nothing actionable anyway, I need to go to the source directly
      Once side effect of the raw format is that it shows the full path to the file and without ever configuration any terminal (iTerm2, PhpStorm), directly clicking on this and getting my to the file/line "just works ™️".
      No need for anything to configure any subjective editor link anywhere 💪🏼

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants