Skip to content

Commit 75a38ca

Browse files
committed
feat(pylint): message ids completion
Complete message ids for `--fail-on`, `--help-msg`, `--enable`, and `--disable`. We scrape the output of `--list-msgs-enabled` instead of `--list-msgs`, because it outputs both enabled and disable message ids and thus allows for one implementation for all cases, even though the output is somewhat less parseable than that of the latter. Curiously, `--list-msgs-enabled` also outputs some message ids that `--list-msgs` does not.
1 parent 236c5e5 commit 75a38ca

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

completions/pylint

+25-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# pylint(1) completion -*- shell-script -*-
22

3+
_comp_cmd_pylint_message_ids()
4+
{
5+
local filter=p
6+
[[ ${2-} ]] && filter="/^$2 messages/,/^$/p"
7+
# 6: arbitrary, assumed no ids shorter than that
8+
_comp_delimited , -W "$(
9+
${1:-pylint} --list-msgs-enabled 2>/dev/null |
10+
command sed -ne "$filter" |
11+
command sed -ne 's/^[[:space:]]\{1,\}\([a-z-]\{6,\}\).*/\1/p'
12+
)"
13+
}
14+
315
_pylint()
416
{
517
local cur prev words cword split
@@ -9,8 +21,8 @@ _pylint()
921
[[ ${1##*/} == *3* ]] && python=python3
1022

1123
case $prev in
12-
--version | --help | --long-help | --help-msg | --init-hook | \
13-
--ignore | --enable | --evaluation | --max-line-length | \
24+
--version | --help | --long-help | --init-hook | \
25+
--ignore | --evaluation | --max-line-length | \
1426
--max-module-lines | --indent-string | --min-similarity-lines | \
1527
--max-args | --ignored-argument-names | --max-locals | \
1628
--max-returns | --max-branches | --max-statements | --max-parents | \
@@ -23,11 +35,20 @@ _pylint()
2335
--ignored-classes | --generated-members | \
2436
--overgeneral-exceptions | --ignore-iface-methods | \
2537
--defining-attr-methods | --valid-classmethod-first-arg | \
26-
--valid-metaclass-classmethod-first-arg | -!(-*)[he])
38+
--valid-metaclass-classmethod-first-arg | -!(-*)[h])
39+
return
40+
;;
41+
--fail-on | --help-msg)
42+
_comp_cmd_pylint_message_ids "$1"
43+
return
44+
;;
45+
--enable | -!(-*)e)
46+
_comp_cmd_pylint_message_ids "$1" Disabled
2747
return
2848
;;
2949
--disable | -!(-*)d)
30-
COMPREPLY=($(compgen -W 'all' -- "$cur"))
50+
_comp_cmd_pylint_message_ids "$1" Enabled
51+
COMPREPLY+=($(compgen -W 'all' -- "$cur"))
3152
return
3253
;;
3354
--rcfile)

test/t/test_pylint.py

+12
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,15 @@ def test_1(self, completion):
99
@pytest.mark.complete("pylint --confidence=HIGH,")
1010
def test_2(self, completion):
1111
assert completion
12+
13+
@pytest.mark.complete("pylint --help-msg=", require_longopt=True)
14+
def test_all_message_ids(self, completion):
15+
assert any("-" in x for x in completion)
16+
17+
@pytest.mark.complete("pylint --disable=", require_longopt=True)
18+
def test_enabled_message_ids(self, completion):
19+
assert any("-" in x for x in completion)
20+
21+
@pytest.mark.complete("pylint --enable=foo,", require_longopt=True)
22+
def test_disabled_message_ids(self, completion):
23+
assert any("-" in x for x in completion)

0 commit comments

Comments
 (0)