diff --git a/linter.py b/linter.py index db845f2..cefffed 100644 --- a/linter.py +++ b/linter.py @@ -1,49 +1,16 @@ -# -# linter.py -# Linter for SublimeLinter3, a code checking framework for Sublime Text 3 -# -# Written by Aparajita Fishman -# Copyright (c) 2015-2016 The SublimeLinter Community -# Copyright (c) 2013-2014 Aparajita Fishman -# -# License: MIT -# - -"""This module exports the Pydocstyle plugin linter class.""" - -from contextlib import contextmanager -from functools import partial -import SublimeLinter.lint -from SublimeLinter.lint import PythonLinter, persist, util - -if getattr(SublimeLinter.lint, 'VERSION', 3) > 3: - from SublimeLinter.lint import const - WARNING = const.WARNING - cmd = 'pydocstyle' - module = None -else: - from SublimeLinter.lint import highlight - WARNING = highlight.WARNING - cmd = 'pydocstyle@python' - module = 'pydocstyle' +from SublimeLinter.lint import PythonLinter, util, const class Pydocstyle(PythonLinter): - """Provides an interface to the pydocstyle python module/script.""" - - syntax = 'python' - cmd = cmd - version_args = '--version' - version_re = r'(?P\d+\.\d+\.\d+)' - version_requirement = '>= 0.3.0' + cmd = 'pydocstyle' regex = r'^.+?:(?P\d+).*:\r?\n\s*(?PD\d{3}):\s(?P.+)$' multiline = True - default_type = WARNING + default_type = const.WARNING error_stream = util.STREAM_BOTH line_col_base = (1, 0) # uses one-based line and zero-based column numbers tempfile_suffix = 'py' - module = module defaults = { + 'selector': 'source.python', '--add-ignore=': '', '--add-select=': '', '--ignore=': '', @@ -52,47 +19,3 @@ class Pydocstyle(PythonLinter): '--convention=': '', '--ignore-decorators=': '' } - inline_overrides = [ - 'add-ignore', - 'add-select', - 'ignore', - 'select', - 'config', - 'convention', - 'ignore-decorators' - ] - - if getattr(SublimeLinter.lint, 'VERSION', 3) < 4: - def check(self, code, filename): - """Run pydocstyle on code and return the output.""" - args = self.build_args(self.get_view_settings(inline=True)) - - if persist.settings.get('debug'): - persist.printf('{} args: {}'.format(self.name, args)) - - conf = self.module.config.ConfigurationParser() - with partialpatched(conf, - '_parse_args', - args=args + [filename], - values=None): - conf.parse() - - errors = [] - for fname, checked_codes, ignore_decorators in \ - conf.get_files_to_check(): - errors.extend( - self.module.check( - [fname], - select=checked_codes, - ignore_decorators=ignore_decorators)) - - return errors - - -@contextmanager -def partialpatched(obj, name, **kwargs): - """Monkey patch instance method with partial application.""" - pre_patched_value = getattr(obj, name) - setattr(obj, name, partial(pre_patched_value, **kwargs)) - yield - setattr(obj, name, pre_patched_value)