SanderRonde / phpstan-vscode

PHPStan plugin for VSCode
https://marketplace.visualstudio.com/items?itemName=SanderRonde.phpstan-vscode
MIT License
40 stars 9 forks source link

Option to ignore errors from stderr instead of erroring out #17

Closed maxcohn closed 1 year ago

maxcohn commented 1 year ago

I saw #16 and figured that maybe a configuration setting where you can specify an array of "ignore strings" that a user can supply themselves so that way it's not hard coding something like 'XDebug' or 'Warning:'. I'm running into a similar situation because my execution environment is different than my development environment.

If you're open to the idea but don't want to work on it, I can give it a go.

SanderRonde commented 1 year ago

I actually like the idea of making it entirely userconfigurable instead of hardcoded so I've implemented it. Should be in the next release :)

maxcohn commented 1 year ago

I can't get over how fast you are! I'm very grateful for your work :)

maxcohn commented 1 year ago

Just an idea: maybe it could support substrings so one could just specify Warning: and have all errors caught. PHP likes to throw line numbers and absolute paths in some of these errors, so small changes to the file's location or just line number the errors was on will prevent the error from being caught. Since a string is also a substring of itself, the current functionality would just be altered slightly.

For example, this

PHP Warning:  Optional parameter $numFields declared before required parameter $condensedField is implicitly treated as a required parameter

becomes this:

PHP   Optional parameter $numFields declared before required parameter $condensedField is implicitly treated as a required parameter

since there's only a find and replace happening. I believe this can be updated right here (https://github.com/SanderRonde/phpstan-vscode/commit/9a53527fe9d6e4e8b10eab802e49b2955de0a0bf#diff-cb9065f770e90db317f3d505d67589dc098bab45986df0aaaa32d2f192cc558eR185) to ignore the entire error instead of just removing a bit of it. Not sure if the current implementation bases the output on lines, but that would probably be necessary given this case, or you could jerryrig regex to work per line instead.

All of this is assuming this is the path you want to take here - I don't want to impose, this just something I thought would be beneficial for myself and other users of this extension.

SanderRonde commented 1 year ago

Thanks for the suggestion. After thinking about it I've gone for something that is pretty close to this namely regexes. That way you can just do PHP Warning: .* and be done (or in the Xdebug case Xdebug: .*). This way it also doesn't happen that errors are ignored while they shouldn't be (which will get me a lot of "the extension doesn't work" issues). It also allows for more flexibility by just making stuff like the line number a \d.

maxcohn commented 1 year ago

Great call, just allowing regular expressions really gives as much (or as little) power as anyone could want.