Skip to content

Commit 6df5180

Browse files
committed
Added error_stream so we can capture linter exceptions. Defer defining the Report class until runtime, at import time we don't have access to the module path.
1 parent 65ff0d1 commit 6df5180

1 file changed

Lines changed: 35 additions & 30 deletions

File tree

linter.py

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,7 @@
1212

1313
import os
1414

15-
try:
16-
from pep8 import StandardReport
17-
except ImportError:
18-
StandardReport = None
19-
20-
from SublimeLinter.lint import persist, PythonLinter
21-
22-
23-
if StandardReport is not None:
24-
25-
class Report(StandardReport):
26-
27-
"""Provides a report in the form of a single multiline string, without printing."""
28-
29-
def get_file_results(self):
30-
"""Collect and return the results for this file."""
31-
self._deferred_print.sort()
32-
results = ''
33-
34-
for line_number, offset, code, text, doc in self._deferred_print:
35-
results += '{path}:{row}:{col}: {code} {text}\n'.format_map({
36-
'path': self.filename,
37-
'row': self.line_offset + line_number,
38-
'col': offset + 1,
39-
'code': code,
40-
'text': text
41-
})
42-
43-
return results
15+
from SublimeLinter.lint import persist, PythonLinter, util
4416

4517

4618
class PEP8(PythonLinter):
@@ -56,15 +28,19 @@ class PEP8(PythonLinter):
5628
'--ignore=,': '',
5729
'--max-line-length=': None
5830
}
31+
error_stream = util.STREAM_BOTH
5932
inline_settings = 'max-line-length'
6033
inline_overrides = ('select', 'ignore')
6134
module = 'pep8'
6235

36+
# Internal
37+
report = None
38+
6339
def check(self, code, filename):
6440
"""Run pep8 on code and return the output."""
6541

6642
options = {
67-
'reporter': Report
43+
'reporter': self.get_report()
6844
}
6945

7046
type_map = {
@@ -85,3 +61,32 @@ def check(self, code, filename):
8561
filename=os.path.basename(filename),
8662
lines=code.splitlines(keepends=True)
8763
)
64+
65+
def get_report(self):
66+
"""Return the Report class for use by flake8."""
67+
if self.report is None:
68+
from pep8 import StandardReport
69+
70+
class Report(StandardReport):
71+
72+
"""Provides a report in the form of a single multiline string, without printing."""
73+
74+
def get_file_results(self):
75+
"""Collect and return the results for this file."""
76+
self._deferred_print.sort()
77+
results = ''
78+
79+
for line_number, offset, code, text, doc in self._deferred_print:
80+
results += '{path}:{row}:{col}: {code} {text}\n'.format_map({
81+
'path': self.filename,
82+
'row': self.line_offset + line_number,
83+
'col': offset + 1,
84+
'code': code,
85+
'text': text
86+
})
87+
88+
return results
89+
90+
self.__class__.report = Report
91+
92+
return self.report

0 commit comments

Comments
 (0)