#538 - Set some end column indexes for flake8
This commit is contained in:
parent
6f858590c2
commit
f472e04b09
@ -1,6 +1,13 @@
|
|||||||
" Author: w0rp <devw0rp@gmail.com>
|
" Author: w0rp <devw0rp@gmail.com>
|
||||||
" Description: Error handling for flake8, etc.
|
" Description: Error handling for flake8, etc.
|
||||||
|
|
||||||
|
let s:end_col_pattern_map = {
|
||||||
|
\ 'F405': '\(.\+\) may be undefined',
|
||||||
|
\ 'F821': 'undefined name ''\([^'']\+\)''',
|
||||||
|
\ 'F999': '^''\([^'']\+\)''',
|
||||||
|
\ 'F841': 'local variable ''\([^'']\+\)''',
|
||||||
|
\}
|
||||||
|
|
||||||
function! ale#handlers#python#HandlePEP8Format(buffer, lines) abort
|
function! ale#handlers#python#HandlePEP8Format(buffer, lines) abort
|
||||||
for l:line in a:lines[:10]
|
for l:line in a:lines[:10]
|
||||||
if match(l:line, '^Traceback') >= 0
|
if match(l:line, '^Traceback') >= 0
|
||||||
@ -35,12 +42,24 @@ function! ale#handlers#python#HandlePEP8Format(buffer, lines) abort
|
|||||||
continue
|
continue
|
||||||
endif
|
endif
|
||||||
|
|
||||||
call add(l:output, {
|
let l:item = {
|
||||||
\ 'lnum': l:match[1] + 0,
|
\ 'lnum': l:match[1] + 0,
|
||||||
\ 'col': l:match[2] + 0,
|
\ 'col': l:match[2] + 0,
|
||||||
\ 'text': l:code . ': ' . l:match[4],
|
\ 'text': l:code . ': ' . l:match[4],
|
||||||
\ 'type': l:code[:0] ==# 'E' ? 'E' : 'W',
|
\ 'type': l:code[:0] ==# 'E' ? 'E' : 'W',
|
||||||
\})
|
\}
|
||||||
|
|
||||||
|
let l:end_col_pattern = get(s:end_col_pattern_map, l:code, '')
|
||||||
|
|
||||||
|
if !empty(l:end_col_pattern)
|
||||||
|
let l:end_col_match = matchlist(l:match[4], l:end_col_pattern)
|
||||||
|
|
||||||
|
if !empty(l:end_col_match)
|
||||||
|
let l:item.end_col = l:item.col + len(l:end_col_match[1]) - 1
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
call add(l:output, l:item)
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
return l:output
|
return l:output
|
||||||
|
47
test/handler/test_flake8_handler.vader
Normal file
47
test/handler/test_flake8_handler.vader
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
|
||||||
|
Execute(End column indexes should be set for certain errors):
|
||||||
|
AssertEqual
|
||||||
|
\ [
|
||||||
|
\ {
|
||||||
|
\ 'lnum': 25,
|
||||||
|
\ 'col': 1,
|
||||||
|
\ 'type': 'W',
|
||||||
|
\ 'end_col': 3,
|
||||||
|
\ 'text': 'F821: undefined name ''foo''',
|
||||||
|
\ },
|
||||||
|
\ {
|
||||||
|
\ 'lnum': 28,
|
||||||
|
\ 'col': 5,
|
||||||
|
\ 'type': 'W',
|
||||||
|
\ 'end_col': 9,
|
||||||
|
\ 'text': 'F405: hello may be undefined, or defined from star imports: x',
|
||||||
|
\ },
|
||||||
|
\ {
|
||||||
|
\ 'lnum': 104,
|
||||||
|
\ 'col': 5,
|
||||||
|
\ 'type': 'W',
|
||||||
|
\ 'end_col': 12,
|
||||||
|
\ 'text': 'F999: ''continue'' not properly in loop',
|
||||||
|
\ },
|
||||||
|
\ {
|
||||||
|
\ 'lnum': 106,
|
||||||
|
\ 'col': 5,
|
||||||
|
\ 'type': 'W',
|
||||||
|
\ 'end_col': 9,
|
||||||
|
\ 'text': 'F999: ''break'' outside loop',
|
||||||
|
\ },
|
||||||
|
\ {
|
||||||
|
\ 'lnum': 109,
|
||||||
|
\ 'col': 5,
|
||||||
|
\ 'type': 'W',
|
||||||
|
\ 'end_col': 8,
|
||||||
|
\ 'text': 'F841: local variable ''test'' is assigned to but never used',
|
||||||
|
\ },
|
||||||
|
\ ],
|
||||||
|
\ ale#handlers#python#HandlePEP8Format(1, [
|
||||||
|
\ 'foo.py:25:1: F821 undefined name ''foo''',
|
||||||
|
\ 'foo.py:28:5: F405 hello may be undefined, or defined from star imports: x',
|
||||||
|
\ 'foo.py:104:5: F999 ''continue'' not properly in loop',
|
||||||
|
\ 'foo.py:106:5: F999 ''break'' outside loop',
|
||||||
|
\ 'foo.py:109:5: F841 local variable ''test'' is assigned to but never used',
|
||||||
|
\ ])
|
Loading…
Reference in New Issue
Block a user