Skip to content

Commit

Permalink
Merge pull request #1 from kaste/sl4
Browse files Browse the repository at this point in the history
Remove cruft from SL3
  • Loading branch information
ergdev authored Mar 8, 2018
2 parents 3568487 + 4443369 commit d028ff5
Showing 1 changed file with 2 additions and 89 deletions.
91 changes: 2 additions & 89 deletions linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,15 @@

"""This module exports the PYCODESTYLE plugin linter class."""

import os

from SublimeLinter.lint import persist, PythonLinter
from SublimeLinter.lint import PythonLinter


class PYCODESTYLE(PythonLinter):
"""Provides an interface to the pep8 python module/script."""

syntax = 'python'
cmd = ('pycodestyle@python', '*', '-')
cmd = ('pycodestyle', '*', '-')
version_args = '--version'
version_re = r'(?P<version>\d+\.\d+\.\d+)'
version_requirement = '>= 1.4.6'
Expand All @@ -31,89 +30,3 @@ class PYCODESTYLE(PythonLinter):
'--ignore=,': '',
'--max-line-length=': None
}
module = 'pycodestyle'
check_version = True

# Internal
report = None

def check(self, code, filename):
"""Run pycodestyle on code and return the output."""
options = {
'reporter': self.get_report()
}

type_map = {
'select': [],
'ignore': [],
'max-line-length': 0,
'max-complexity': 0
}

self.build_options(options, type_map, transform=lambda s: s.replace('-', '_'))

final_options = options.copy()

# Try to read options from pycodestyle default configuration files (.pycodestyle, tox.ini).
# If present, they will override the ones defined by Sublime Linter's config.
try:
# `onError` will be called by `process_options` when no pycodestyle configuration file is found.
# Override needed to supress OptionParser.error() output in the default parser.
def onError(msg):
pass

from pycodestyle import process_options, get_parser
parser = get_parser()
parser.error = onError
pycodestyle_options, _ = process_options([os.curdir], True, True, parser=parser)

if pycodestyle_options.config:
pycodestyle_options = vars(pycodestyle_options)
pycodestyle_options.pop('reporter', None)
for opt_n, opt_v in pycodestyle_options.items():
if isinstance(final_options.get(opt_n, None), list):
final_options[opt_n] += opt_v
else:
final_options[opt_n] = opt_v
except SystemExit:
# Catch and ignore parser.error() when no config files are found.
pass

if persist.debug_mode():
persist.printf('{} ST options: {}'.format(self.name, options))
persist.printf('{} options: {}'.format(self.name, final_options))

checker = self.module.StyleGuide(**final_options)

return checker.input_file(
filename=os.path.basename(filename),
lines=code.splitlines(keepends=True)
)

def get_report(self):
"""Return the Report class for use by flake8."""
if self.report is None:
from pycodestyle import StandardReport

class Report(StandardReport):
"""Provides a report in the form of a single multiline string, without printing."""

def get_file_results(self):
"""Collect and return the results for this file."""
self._deferred_print.sort()
results = ''

for line_number, offset, code, text, _ in self._deferred_print:
results += '{path}:{row}:{col}: {code} {text}\n'.format_map({
'path': self.filename,
'row': self.line_offset + line_number,
'col': offset + 1,
'code': code,
'text': text
})

return results

self.__class__.report = Report

return self.report

0 comments on commit d028ff5

Please sign in to comment.