diff --git a/pyls/plugins/pycodestyle_lint.py b/pyls/plugins/pycodestyle_lint.py index 96efafd1..c12f9f48 100644 --- a/pyls/plugins/pycodestyle_lint.py +++ b/pyls/plugins/pycodestyle_lint.py @@ -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__) diff --git a/test/plugins/test_pycodestyle_lint.py b/test/plugins/test_pycodestyle_lint.py index f11cfdec..eb1429b5 100644 --- a/test/plugins/test_pycodestyle_lint.py +++ b/test/plugins/test_pycodestyle_lint.py @@ -10,6 +10,9 @@ def hello( ): \tpass +print("hello" + ,"world" +) import json @@ -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] @@ -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. @@ -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) }