Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,23 @@
"""This module exports the PHP plugin class."""

import logging
import re
from SublimeLinter.lint import Linter, util


logger = logging.getLogger('SublimeLinter.plugin.php')

# PHP appends where it read the code from, e.g. `... in Standard input code`
# or `... in -`. Only that trailing part is noise; ` in ` and ` on ` inside the
# message itself (`Cannot use isset() on the result of an expression`) are not.
TRAILING_SOURCE_RE = re.compile(r'\s+in\s+(?:Standard input code|-)\s*$')


def _filter_message(message):
if not message:
message = 'parse error'
else:
message = message.replace('Standard input code', '')
message = message.replace(' on ', '')
message = message.replace(' in -', '')
message = message.replace(' in ', '')
message = message.strip()
message = TRAILING_SOURCE_RE.sub('', message).strip()

return message

Expand Down
33 changes: 33 additions & 0 deletions tests/test_regex.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,36 @@ def test_issue_29(self):
'near': None,
},
)

def test_issue_55_message_filter_only_strips_trailing_source(self):
# " on " and " in " inside the message must survive
self.assertMatch(
'Fatal error: Cannot use isset() on the result of an expression '
'(you can use "null !== expression" instead) in Standard input code on line 2',
{
'error': 'Fatal',
'line': 1,
'message': 'Cannot use isset() on the result of an expression '
'(you can use "null !== expression" instead)',
},
)

self.assertMatch(
"Fatal error: 'break' not in the 'loop' or 'switch' context "
'in Standard input code on line 3',
{
'error': 'Fatal',
'line': 2,
'message': "'break' not in the 'loop' or 'switch' context",
},
)

self.assertMatch(
'Fatal error: Cannot redeclare f() (previously declared in Standard input code:2) '
'in Standard input code on line 3',
{
'error': 'Fatal',
'line': 2,
'message': 'Cannot redeclare f() (previously declared in Standard input code:2)',
},
)