Skip to content

Only strip the trailing source location from messages - #57

Merged
kaste merged 1 commit into
SublimeLinter:masterfrom
dpc00:fix-message-filter
Sep 29, 2026
Merged

kaste merged 1 commit into
SublimeLinter:masterfrom
dpc00:fix-message-filter

Conversation

@dpc00

@dpc00 dpc00 commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

Fixes #55.

_filter_message() replaced every on and in in the message, so ordinary PHP messages were garbled, e.g. Cannot use isset() on the result of an expression became Cannot use isset()the result of an expression, and 'break' not in the 'loop' or 'switch' context became 'break' notthe 'loop' or 'switch' context.

As you said in the issue, only the trailing in Standard input code / in - (what PHP appends and regex lets through in message) should be removed. This replaces the four replace() calls with one regex anchored at the end of the message:

TRAILING_SOURCE_RE = re.compile(r'\s+in\s+(?:Standard input code|-)\s*$')

I added a test, test_issue_55_message_filter_only_strips_trailing_source, with three messages from php -l on PHP 8.4 (the isset() one, the break one, and Cannot redeclare f() (previously declared in Standard input code:2), where the in Standard input code:2 inside the parentheses now stays since it is not trailing). I ran the test module with UnitTesting in Sublime Text 4215: the new test fails before the change (with the garbled text above) and all four tests pass after it, including the three existing ones.

One behaviour change to be aware of: a standalone on that is not at the end is no longer removed. regex already consumes the on line N part, so I could not find a case where the old replacement was needed, but if you know of one, tell me and I'll add a test for it.

The filter removed every ' on ' and ' in ' in the message, turning
'Cannot use isset() on the result of an expression' into
'Cannot use isset()the result of an expression' and
"'break' not in the 'loop' or 'switch' context" into
"'break' notthe 'loop' or 'switch' context".

Only the trailing ' in Standard input code' / ' in -' that PHP appends
should go. Add tests for messages that contain ' on ' and ' in '.

Fixes SublimeLinter#55

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@kaste
kaste merged commit 2a05bd7 into SublimeLinter:master Sep 29, 2026
@kaste

kaste commented Sep 29, 2026

Copy link
Copy Markdown
Member

Looks legit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants