8000 Fix pycodestyle iterable options (#211) · brandonwillard/python-lsp-server@ff796f8 · GitHub
[go: up one dir, main page]

Skip to content

Commit ff796f8

Browse files
lgeigergatesn
authored andcommitted
Fix pycodestyle iterable options (python-lsp#211)
* pycodestyle test case: ignore multiple error codes * pycodestyle: Pass list instead of a string for iterable options
1 parent 897980b commit ff796f8

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

pyls/plugins/pycodestyle_lint.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ def pyls_lint(config, document):
1212
log.debug("Got pycodestyle settings: %s", settings)
1313

1414
opts = {
15-
'exclude': ','.join(settings.get('exclude') or []),
16-
'filename': ','.join(settings.get('filename') or []),
15+
'exclude': settings.get('exclude'),
16+
'filename': settings.get('filename'),
1717
'hang_closing': settings.get('hangClosing'),
18-
'ignore': ','.join(settings.get('ignore') or []),
18+
'ignore': settings.get('ignore'),
1919
'max_line_length': settings.get('maxLineLength'),
20-
'select': ','.join(settings.get('select') or []),
20+
'select': settings.get('select'),
2121
}
2222
kwargs = {k: v for k, v in opts.items() if v}
2323
styleguide = pycodestyle.StyleGuide(kwargs)

test/plugins/test_pycodestyle_lint.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
DOC_URI = uris.from_fs_path(__file__)
99
DOC = """import sys
1010
11-
def hello():
11+
def hello( ):
1212
\tpass
1313
1414
import json
@@ -40,6 +40,14 @@ def test_pycodestyle(config):
4040
assert mod_import['range']['start'] == {'line': 7, 'character': 0}
4141
assert mod_import['range']['end'] == {'line': 7, 'character': 1}
4242

43+
msg = "E201 whitespace after '('"
44+
mod_import = [d for d in diags if d['message'] == msg][0]
45+
46+
assert mod_import['code'] == 'E201'
47+
assert mod_import['severity'] == lsp.DiagnosticSeverity.Warning
48+
assert mod_import['range']['start'] == {'line': 2, 'character': 10}
49+
assert mod_import['range']['end'] == {'line': 2, 'character': 14}
50+
4351

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

6876
content = {
69-
'setup.cfg': ('[pycodestyle]\nignore = W191', True),
77+
'setup.cfg': ('[pycodestyle]\nignore = W191, E201', True),
7078
'tox.ini': ('', False)
7179
}
7280

@@ -77,18 +85,16 @@ def test_pycodestyle_config(workspace):
7785

7886
# And make sure we don't get any warnings
7987
diags = pycodestyle_lint.pyls_lint(config, doc)
80-
assert len([d for d in diags if d['code'] == 'W191']) == 0 if working else 1
88+
assert len([d for d in diags if d['code'] == 'W191']) == (0 if working else 1)
89+
assert len([d for d in diags if d['code'] == 'E201']) == (0 if working else 1)
90+
assert [d for d in diags if d['code'] == 'W391']
8191

8292
os.unlink(os.path.join(workspace.root_path, conf_file))
8393

8494
# Make sure we can ignore via the PYLS config as well
85-
config.update({'plugins': {'pycodestyle': {'ignore': ['W191']}}})
95+
config.update({'plugins': {'pycodestyle': {'ignore': ['W191', 'E201']}}})
8696
# And make sure we only get one warning
8797
diags = pycodestyle_lint.pyls_lint(config, doc)
8898
assert not [d for d in diags if d['code'] == 'W191']
89-
90-
# Ignore both warnings
91-
config.update({'plugins': {'pycodestyle': {'ignore': ['W191', 'W391']}}})
92-
# And make sure we get neither
93-
assert not [d for d in diags if d['code'] == 'W191']
94-
assert not [d for d in diags if d['code'] == 'W391']
99+
assert not [d for d in diags if d['code'] == 'E201']
100+
assert [d for d in diags if d['code'] == 'W391']

0 commit comments

Comments
 (0)
0