Skip to content

Commit 0114c6c

Browse files
johnhany97ccordoba12
authored andcommitted
Address autopep8 overriding pycodestyle's continued_indentation (#719)
1 parent 914d4e1 commit 0114c6c

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

pyls/plugins/pycodestyle_lint.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
# Copyright 2017 Palantir Technologies, Inc.
22
import logging
33
import pycodestyle
4+
from autopep8 import continued_indentation as autopep8_c_i
45
from pyls import hookimpl, lsp
56

7+
# Check if autopep8's continued_indentation implementation
8+
# is overriding pycodestyle's and if so, re-register
9+
# the check using pycodestyle's implementation as expected
10+
if autopep8_c_i in pycodestyle._checks['logical_line']:
11+
del pycodestyle._checks['logical_line'][autopep8_c_i]
12+
pycodestyle.register_check(pycodestyle.continued_indentation)
13+
614
log = logging.getLogger(__name__)
715

816

test/plugins/test_pycodestyle_lint.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
1111
def hello( ):
1212
\tpass
13+
print("hello"
14+
,"world"
15+
)
1316
1417
import json
1518
@@ -37,8 +40,8 @@ def test_pycodestyle(config):
3740

3841
assert mod_import['code'] == 'W391'
3942
assert mod_import['severity'] == lsp.DiagnosticSeverity.Warning
40-
assert mod_import['range']['start'] == {'line': 7, 'character': 0}
41-
assert mod_import['range']['end'] == {'line': 7, 'character': 1}
43+
assert mod_import['range']['start'] == {'line': 10, 'character': 0}
44+
assert mod_import['range']['end'] == {'line': 10, 'character': 1}
4245

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

54+
msg = "E128 continuation line under-indented for visual indent"
55+
mod_import = [d for d in diags if d['message'] == msg][0]
56+
57+
assert mod_import['code'] == 'E128'
58+
assert mod_import['severity'] == lsp.DiagnosticSeverity.Warning
59+
assert mod_import['range']['start'] == {'line': 5, 'character': 1}
60+
assert mod_import['range']['end'] == {'line': 5, 'character': 10}
61+
5162

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

7687
content = {
77-
'setup.cfg': ('[pycodestyle]\nignore = W191, E201', True),
88+
'setup.cfg': ('[pycodestyle]\nignore = W191, E201, E128', True),
7889
'tox.ini': ('', False)
7990
}
8091

0 commit comments

Comments
 (0)