Skip to content

Commit

Permalink
Address autopep8 overriding pycodestyle's continued_indentation (#719)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnhany97 authored and ccordoba12 committed Dec 24, 2019
1 parent 914d4e1 commit 0114c6c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
8 changes: 8 additions & 0 deletions pyls/plugins/pycodestyle_lint.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
# 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__)


Expand Down
17 changes: 14 additions & 3 deletions test/plugins/test_pycodestyle_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
def hello( ):
\tpass
print("hello"
,"world"
)
import json
Expand Down Expand Up @@ -37,8 +40,8 @@ def test_pycodestyle(config):

assert mod_import['code'] == 'W391'
assert mod_import['severity'] == lsp.DiagnosticSeverity.Warning
assert mod_import['range']['start'] == {'line': 7, 'character': 0}
assert mod_import['range']['end'] == {'line': 7, 'character': 1}
assert mod_import['range']['start'] == {'line': 10, 'character': 0}
assert mod_import['range']['end'] == {'line': 10, 'character': 1}

msg = "E201 whitespace after '('"
mod_import = [d for d in diags if d['message'] == msg][0]
Expand All @@ -48,6 +51,14 @@ def test_pycodestyle(config):
assert mod_import['range']['start'] == {'line': 2, 'character': 10}
assert mod_import['range']['end'] == {'line': 2, 'character': 14}

msg = "E128 continuation line under-indented for visual indent"
mod_import = [d for d in diags if d['message'] == msg][0]

assert mod_import['code'] == 'E128'
assert mod_import['severity'] == lsp.DiagnosticSeverity.Warning
assert mod_import['range']['start'] == {'line': 5, 'character': 1}
assert mod_import['range']['end'] == {'line': 5, 'character': 10}


def test_pycodestyle_config(workspace):
""" Test that we load config files properly.
Expand All @@ -74,7 +85,7 @@ def test_pycodestyle_config(workspace):
assert [d for d in diags if d['code'] == 'W191']

content = {
'setup.cfg': ('[pycodestyle]\nignore = W191, E201', True),
'setup.cfg': ('[pycodestyle]\nignore = W191, E201, E128', True),
'tox.ini': ('', False)
}

Expand Down

0 comments on commit 0114c6c

Please sign in to comment.