-
Notifications
You must be signed in to change notification settings - Fork 29
/
linter.py
62 lines (48 loc) · 1.66 KB
/
linter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#
# linter.py
# Linter for SublimeLinter3, a code checking framework for Sublime Text 3
#
# Written by Ryan Hileman, Aparajita Fishman and Anthony Pidden
# Copyright (c) 2013 Ryan Hileman, Aparajita Fishman and Anthony Pidden
#
# License: MIT
#
"""This module exports the PHP plugin class."""
import logging
from SublimeLinter.lint import Linter, util
logger = logging.getLogger('SublimeLinter.plugin.php')
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()
return message
class PHP(Linter):
"""Provides an interface to php -l."""
defaults = {
'selector': 'embedding.php, source.php'
}
regex = (
r'^(?P<error>Parse|Fatal) error:\s*'
r'(?P<message>((?:parse|syntax) error,?)?\s*(?:unexpected \'(?P<near>[^\']+)\')?.*) '
r'(?:in - )?on line (?P<line>\d+)'
)
error_stream = util.STREAM_STDOUT
def split_match(self, match):
"""Return the components of the error."""
result = super().split_match(match)
result['message'] = _filter_message(result.message)
return result
def cmd(self):
"""Read cmd from inline settings."""
if 'cmd' in self.settings:
logger.warning(
'The setting `cmd` has been removed. '
'Use `executable` instead. '
)
return None
return ('php', '-l', '-n', '-d', 'display_errors=On', '-d', 'log_errors=Off')