Skip to content

Commit e94aea9

Browse files
committed
Merge pull request #578 from nOkuda/master
Translate pylint output column to 1-based index
1 parent 64b56f8 commit e94aea9

File tree

2 files changed

+87
-1
lines changed

2 files changed

+87
-1
lines changed

ale_linters/python/pylint.vim

+34-1
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,43 @@ function! ale_linters#python#pylint#GetCommand(buffer) abort
3232
\ . ' %s'
3333
endfunction
3434

35+
function! ale_linters#python#pylint#Handle(buffer, lines) abort
36+
" Matches patterns like the following:
37+
"
38+
" test.py:4:4: W0101 (unreachable) Unreachable code
39+
let l:pattern = '\v^[^:]+:(\d+):(\d+): ([[:alnum:]]+) \((.*)\) (.*)$'
40+
let l:output = []
41+
42+
for l:match in ale#util#GetMatches(a:lines, l:pattern)
43+
"let l:failed = append(0, l:match)
44+
let l:code = l:match[3]
45+
46+
if (l:code ==# 'C0303')
47+
\ && !ale#Var(a:buffer, 'warn_about_trailing_whitespace')
48+
" Skip warnings for trailing whitespace if the option is off.
49+
continue
50+
endif
51+
52+
if l:code ==# 'I0011'
53+
" Skip 'Locally disabling' message
54+
continue
55+
endif
56+
57+
call add(l:output, {
58+
\ 'lnum': l:match[1] + 0,
59+
\ 'col': l:match[2] + 1,
60+
\ 'text': l:code . ': ' . l:match[5],
61+
\ 'type': l:code[:0] ==# 'E' ? 'E' : 'W',
62+
\})
63+
endfor
64+
65+
return l:output
66+
endfunction
67+
3568
call ale#linter#Define('python', {
3669
\ 'name': 'pylint',
3770
\ 'executable_callback': 'ale_linters#python#pylint#GetExecutable',
3871
\ 'command_callback': 'ale_linters#python#pylint#GetCommand',
39-
\ 'callback': 'ale#handlers#python#HandlePEP8Format',
72+
\ 'callback': 'ale_linters#python#pylint#Handle',
4073
\ 'lint_file': 1,
4174
\})
+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
Before:
2+
runtime ale_linters/python/pylint.vim
3+
4+
After:
5+
call ale#linter#Reset()
6+
silent file something_else.py
7+
8+
Execute(pylint handler parsing, translating columns to 1-based index):
9+
AssertEqual
10+
\ [
11+
\ {
12+
\ 'lnum': 4,
13+
\ 'col': 1,
14+
\ 'text': 'C0303: Trailing whitespace',
15+
\ 'type': 'W',
16+
\ },
17+
\ {
18+
\ 'lnum': 1,
19+
\ 'col': 1,
20+
\ 'text': 'C0111: Missing module docstring',
21+
\ 'type': 'W',
22+
\ },
23+
\ {
24+
\ 'lnum': 2,
25+
\ 'col': 1,
26+
\ 'text': 'C0111: Missing function docstring',
27+
\ 'type': 'W',
28+
\ },
29+
\ {
30+
\ 'lnum': 3,
31+
\ 'col': 5,
32+
\ 'text': 'E0103: ''break'' not properly in loop',
33+
\ 'type': 'E',
34+
\ },
35+
\ {
36+
\ 'lnum': 4,
37+
\ 'col': 5,
38+
\ 'text': 'W0101: Unreachable code',
39+
\ 'type': 'W',
40+
\ },
41+
\ ],
42+
\ ale_linters#python#pylint#Handle(bufnr(''), [
43+
\ 'No config file found, using default configuration',
44+
\ '************* Module test',
45+
\ 'test.py:4:0: C0303 (trailing-whitespace) Trailing whitespace',
46+
\ 'test.py:1:0: C0111 (missing-docstring) Missing module docstring',
47+
\ 'test.py:2:0: C0111 (missing-docstring) Missing function docstring',
48+
\ 'test.py:3:4: E0103 (not-in-loop) ''break'' not properly in loop',
49+
\ 'test.py:4:4: W0101 (unreachable) Unreachable code',
50+
\ '',
51+
\ '------------------------------------------------------------------',
52+
\ 'Your code has been rated at 0.00/10 (previous run: 2.50/10, -2.50)',
53+
\ ])

0 commit comments

Comments
 (0)