Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_register_ast_check(self):
pycodestyle.register_check(DummyChecker, ['Z701'])
self.assertTrue(DummyChecker in pycodestyle._checks['tree'])
codes, args = pycodestyle._checks['tree'][DummyChecker]
self.assertTrue('Z701' in codes)
self.assertTrue(args is None)
options = pycodestyle.StyleGuide().options
self.assertTrue(any(cls == DummyChecker
for name, cls, args in options.ast_checks))
def test_register_logical_check(self):
def check_dummy(logical_line, tokens):
if False:
yield
pycodestyle.register_check(check_dummy, ['Z401'])
self.assertTrue(check_dummy in pycodestyle._checks['logical_line'])
codes, args = pycodestyle._checks['logical_line'][check_dummy]
self.assertTrue('Z401' in codes)
self.assertEqual(args, ['logical_line', 'tokens'])
pycodestyle.register_check(check_dummy, [])
pycodestyle.register_check(check_dummy, ['Z402', 'Z403'])
codes, args = pycodestyle._checks['logical_line'][check_dummy]
self.assertEqual(codes, ['Z401', 'Z402', 'Z403'])
self.assertEqual(args, ['logical_line', 'tokens'])
options = pycodestyle.StyleGuide().options
self.assertTrue(any(func == check_dummy
for name, func, args in options.logical_checks))
def setUp(self):
self._saved_stdout = sys.stdout
self._saved_stderr = sys.stderr
self._saved_checks = pycodestyle._checks
sys.stdout = PseudoFile()
sys.stderr = PseudoFile()
pycodestyle._checks = dict(
(k, dict((f, (vals[0][:], vals[1])) for (f, vals) in v.items()))
for (k, v) in self._saved_checks.items()
)
def tearDown(self):
sys.stdout = self._saved_stdout
sys.stderr = self._saved_stderr
pycodestyle._checks = self._saved_checks
def setUp(self):
self._saved_stdout = sys.stdout
self._saved_stderr = sys.stderr
self._saved_checks = pycodestyle._checks
sys.stdout = PseudoFile()
sys.stderr = PseudoFile()
pycodestyle._checks = dict(
(k, dict((f, (vals[0][:], vals[1])) for (f, vals) in v.items()))
for (k, v) in self._saved_checks.items()
)
def setUp(self):
self._saved_stdout = sys.stdout
self._saved_stderr = sys.stderr
self._saved_checks = pycodestyle._checks
sys.stdout = PseudoFile()
sys.stderr = PseudoFile()
pycodestyle._checks = {
k: {f: (vals[0][:], vals[1]) for (f, vals) in v.items()}
for k, v in self._saved_checks.items()
}
def tearDown(self):
sys.stdout = self._saved_stdout
sys.stderr = self._saved_stderr
pycodestyle._checks = self._saved_checks
last_line = line
if (
indent_next and
not last_line_begins_with_multiline and
pycodestyle.expand_indent(line) == indent_level + DEFAULT_INDENT_SIZE
):
pos = (start[0], indent[0] + 4)
desired_indent = indent_level + 2 * DEFAULT_INDENT_SIZE
if visual_indent:
yield (pos, 'E129 {0}'.format(desired_indent))
else:
yield (pos, 'E125 {0}'.format(desired_indent))
del pycodestyle._checks['logical_line'][pycodestyle.continued_indentation]
pycodestyle.register_check(continued_indentation)
class FixPEP8(object):
"""Fix invalid code.
Fixer methods are prefixed "fix_". The _fix_source() method looks for these
automatically.
The fixer method can take either one or two arguments (in addition to
self). The first argument is "result", which is the error information from
pycodestyle. The second argument, "logical", is required only for
logical-line fixes.
The fixer method can return the list of modified lines or None. An empty
last_line = line
if (
indent_next and
not last_line_begins_with_multiline and
pycodestyle.expand_indent(line) == indent_level + DEFAULT_INDENT_SIZE
):
pos = (start[0], indent[0] + 4)
desired_indent = indent_level + 2 * DEFAULT_INDENT_SIZE
if visual_indent:
yield (pos, 'E129 {0}'.format(desired_indent))
else:
yield (pos, 'E125 {0}'.format(desired_indent))
del pycodestyle._checks['logical_line'][pycodestyle.continued_indentation]
pycodestyle.register_check(continued_indentation)
class FixPEP8(object):
"""Fix invalid code.
Fixer methods are prefixed "fix_". The _fix_source() method looks for these
automatically.
The fixer method can take either one or two arguments (in addition to
self). The first argument is "result", which is the error information from
pycodestyle. The second argument, "logical", is required only for
logical-line fixes.
The fixer method can return the list of modified lines or None. An empty
# Copyright 2017 Palantir Technologies, Inc.
import logging
import pycodestyle
from autopep8 import continued_indentation as autopep8_c_i
from pyls import hookimpl, lsp
# Check if autopep8's continued_indentation implementation
# is overriding pycodestyle's and if so, re-register
# the check using pycodestyle's implementation as expected
if autopep8_c_i in pycodestyle._checks['logical_line']:
del pycodestyle._checks['logical_line'][autopep8_c_i]
pycodestyle.register_check(pycodestyle.continued_indentation)
log = logging.getLogger(__name__)
@hookimpl
def pyls_lint(config, document):
settings = config.plugin_settings('pycodestyle')
log.debug("Got pycodestyle settings: %s", settings)
opts = {
'exclude': settings.get('exclude'),
'filename': settings.get('filename'),
'hang_closing': settings.get('hangClosing'),
'ignore': settings.get('ignore'),