SublimeLinter-php icon indicating copy to clipboard operation
SublimeLinter-php copied to clipboard

Message filter removes ' on ' and ' in ' anywhere in the message: 'notthe loop', 'isset()the result'

Open dpc00 opened this issue 2 months ago • 1 comments

_filter_message() removes every occurrence of " on " and " in " from the message, not just the trailing in Standard input code on line N part, so ordinary PHP messages come out garbled.

Repro (Sublime Text 4215, SublimeLinter-php 1.5.0, PHP 8.4.25). isset.php:

<?php
if (isset(foo())) {}

php -l says:

Fatal error: Cannot use isset() on the result of an expression (you can use "null !== expression" instead) in Standard input code on line 2

SublimeLinter shows: Cannot use isset()the result of an expression (you can use "null !== expression" instead) (the word "on" and the spaces around it are gone).

break.php:

<?php
$x = 1;
break 2;

php -l: 'break' not in the 'loop' or 'switch' context. SublimeLinter shows: 'break' notthe 'loop' or 'switch' context.

Same for Cannot redeclare function f() (previously declared in Standard input code:2), which is shown as (previously declared:2).

Cause:

message = message.replace('Standard input code', '')
message = message.replace(' on ', '')
message = message.replace(' in -', '')
message = message.replace(' in ', '')

The intent is to strip the trailing in Standard input code that PHP appends (it ends up in the captured message because of the .*), but the ' on ' and ' in ' replaces hit the whole message. Suggest removing only a trailing in Standard input code (for example a regex anchored at the end of the message) instead of replacing everywhere.

dpc00 avatar Sep 29 '26 13:09 dpc00

#50 says "Removes trailing text like "Standard input code", " in -", " on ", in error messages in the status message"

So the intention was obviously "trailing" occurrences which the code clearly does not follow. But not just "in Standard input code".

This is test driven, at least I see tests, so I welcome a PR.

kaste avatar Sep 29 '26 17:09 kaste