Skip to content

Commit 91b5e4e

Browse files
authored
Allow configuring pycodestyle options from the PYLS config (#146)
* Options for pycodestlye * Options for pycodestlye
1 parent a1bbd40 commit 91b5e4e

File tree

3 files changed

+71
-2
lines changed

3 files changed

+71
-2
lines changed

pyls/plugins/pycodestyle_lint.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,29 @@ def pyls_lint(config, document):
2121
conf_to_use = pycodestyle_conf if pycodestyle_conf else pep8_conf
2222

2323
conf = {k.replace("-", "_"): v for k, v in conf_to_use.items()}
24-
log.debug("Got pycodestyle config: %s", conf)
2524

2625
# Grab the pycodestyle parser and set the defaults based on the config we found
2726
parser = pycodestyle.get_parser()
2827
parser.set_defaults(**conf)
29-
opts, _args = parser.parse_args([])
28+
29+
# Override with any options set in the language server config
30+
argv = []
31+
ls_conf = config.plugin_settings('pycodestyle')
32+
if ls_conf.get('exclude') is not None:
33+
argv.extend(['--exclude', ','.join(ls_conf['exclude'])])
34+
if ls_conf.get('filename') is not None:
35+
argv.extend(['--filename', ','.join(ls_conf['filename'])])
36+
if ls_conf.get('select') is not None:
37+
argv.extend(['--select', ','.join(ls_conf['select'])])
38+
if ls_conf.get('ignore') is not None:
39+
argv.extend(['--ignore', ','.join(ls_conf['ignore'])])
40+
if ls_conf.get('maxLineLength') is not None:
41+
argv.extend(['--max-line-length', str(ls_conf['maxLineLength'])])
42+
if ls_conf.get('hangClosing'):
43+
argv.extend(['--hang-closing'])
44+
45+
opts, _args = parser.parse_args(argv)
46+
log.debug("Got pycodestyle config: %s", opts)
3047
styleguide = pycodestyle.StyleGuide(vars(opts))
3148

3249
c = pycodestyle.Checker(

test/plugins/test_lint.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ def test_pycodestyle_config(workspace):
9696

9797
os.unlink(os.path.join(workspace.root_path, conf_file))
9898

99+
# Make sure we can ignore via the PYLS config as well
100+
config.update({'plugins': {'pycodestyle': {'ignore': ['W191']}}})
101+
# And make sure we don't get any warnings
102+
diags = pycodestyle_lint.pyls_lint(config, doc)
103+
assert not [d for d in diags if d['code'] == 'W191']
104+
99105

100106
def test_pydocstyle():
101107
doc = Document(DOC_URI, DOC)

vscode-client/package.json

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,52 @@
7070
"default": true,
7171
"description": "Enable or disable the plugin."
7272
},
73+
"pyls.plugins.pycodestyle.exclude": {
74+
"type": "array",
75+
"default": null,
76+
"items": {
77+
"type": "string"
78+
},
79+
"uniqueItems": true,
80+
"description": "Exclude files or directories which match these patterns."
81+
},
82+
"pyls.plugins.pycodestyle.filename": {
83+
"type": "array",
84+
"default": null,
85+
"items": {
86+
"type": "string"
87+
},
88+
"uniqueItems": true,
89+
"description": "When parsing directories, only check filenames matching these patterns."
90+
},
91+
"pyls.plugins.pycodestyle.select": {
92+
"type": "array",
93+
"default": null,
94+
"items": {
95+
"type": "string"
96+
},
97+
"uniqueItems": true,
98+
"description": "Select errors and warnings"
99+
},
100+
"pyls.plugins.pycodestyle.ignore": {
101+
"type": "array",
102+
"default": null,
103+
"items": {
104+
"type": "string"
105+
},
106+
"uniqueItems": true,
107+
"description": "Ignore errors and warnings"
108+
},
109+
"pyls.plugins.pycodestyle.hangClosing": {
110+
"type": "boolean",
111+
"default": null,
112+
"description": "Hang closing bracket instead of matching indentation of opening bracket's line."
113+
},
114+
"pyls.plugins.pycodestyle.maxLineLength": {
115+
"type": "number",
116+
"default": null,
117+
"description": "Set maximum allowed line length."
118+
},
73119
"pyls.plugins.pydocstyle.enabled": {
74120
"type": "boolean",
75121
"default": false,

0 commit comments

Comments
 (0)