Allow warnings about trailing blank lines to be hidden for flake8 and pycodestyle
This commit is contained in:
parent
4e821e64c7
commit
0ab689db0a
@ -91,6 +91,12 @@ function! ale_linters#python#flake8#Handle(buffer, lines) abort
|
||||
continue
|
||||
endif
|
||||
|
||||
if l:code is# 'W391'
|
||||
\&& !ale#Var(a:buffer, 'warn_about_trailing_blank_lines')
|
||||
" Skip warnings for trailing blank lines if the option is off
|
||||
continue
|
||||
endif
|
||||
|
||||
let l:item = {
|
||||
\ 'lnum': l:match[1] + 0,
|
||||
\ 'col': l:match[2] + 0,
|
||||
|
@ -23,6 +23,12 @@ function! ale_linters#python#pycodestyle#Handle(buffer, lines) abort
|
||||
" lines are formatted as follows:
|
||||
" file.py:21:26: W291 trailing whitespace
|
||||
for l:match in ale#util#GetMatches(a:lines, l:pattern)
|
||||
if l:match[4] is# 'W391'
|
||||
\&& !ale#Var(a:buffer, 'warn_about_trailing_blank_lines')
|
||||
" Skip warnings for trailing blank lines if the option is off
|
||||
continue
|
||||
endif
|
||||
|
||||
let l:item = {
|
||||
\ 'lnum': l:match[2] + 0,
|
||||
\ 'col': l:match[3] + 0,
|
||||
|
19
doc/ale.txt
19
doc/ale.txt
@ -1387,6 +1387,18 @@ b:ale_virtualenv_dir_names *b:ale_virtualenv_dir_names*
|
||||
directory containing the Python file to find virtualenv paths.
|
||||
|
||||
|
||||
g:ale_warn_about_trailing_blank_lines *g:ale_warn_about_trailing_blank_lines*
|
||||
b:ale_warn_about_trailing_blank_lines *b:ale_warn_about_trailing_blank_lines*
|
||||
|
||||
Type: |Number|
|
||||
Default: `1`
|
||||
|
||||
When this option is set to `1`, warnings about trailing blank lines will be
|
||||
shown.
|
||||
|
||||
This option behaves similarly to |g:ale_warn_about_trailing_whitespace|.
|
||||
|
||||
|
||||
g:ale_warn_about_trailing_whitespace *g:ale_warn_about_trailing_whitespace*
|
||||
b:ale_warn_about_trailing_whitespace *b:ale_warn_about_trailing_whitespace*
|
||||
|
||||
@ -1394,10 +1406,9 @@ b:ale_warn_about_trailing_whitespace *b:ale_warn_about_trailing_whitespace*
|
||||
Default: `1`
|
||||
|
||||
When this option is set to `1`, warnings relating to trailing whitespace on
|
||||
lines will be shown in signs, the loclist, and echo messages, etc. If these
|
||||
errors are found to be too irritating while edits are being made, and you
|
||||
have configured Vim to automatically remove trailing whitespace, then you
|
||||
can disable these warnings for some linters by setting this option to `0`.
|
||||
lines will be shown. If warnings are too irritating while editing buffers,
|
||||
and you have configured Vim to automatically remove trailing whitespace,
|
||||
you can disable these warnings by setting this option to `0`.
|
||||
|
||||
Not all linters may respect this option. If a linter does not, please file a
|
||||
bug report, and it may be possible to add such support.
|
||||
|
@ -175,8 +175,9 @@ let g:ale_statusline_format = get(g:, 'ale_statusline_format',
|
||||
\)
|
||||
|
||||
" This flag can be set to 0 to disable warnings for trailing whitespace
|
||||
let g:ale_warn_about_trailing_whitespace =
|
||||
\ get(g:, 'ale_warn_about_trailing_whitespace', 1)
|
||||
call ale#Set('warn_about_trailing_whitespace', 1)
|
||||
" This flag can be set to 0 to disable warnings for trailing blank lines
|
||||
call ale#Set('warn_about_trailing_blank_lines', 1)
|
||||
|
||||
" A flag for controlling the maximum size of the command history to store.
|
||||
let g:ale_max_buffer_history_size = get(g:, 'ale_max_buffer_history_size', 20)
|
||||
|
@ -1,8 +1,16 @@
|
||||
Before:
|
||||
runtime ale_linters/python/flake8.vim
|
||||
Save g:ale_warn_about_trailing_blank_lines
|
||||
|
||||
let g:ale_warn_about_trailing_blank_lines = 1
|
||||
|
||||
runtime ale_linters/python/flake8.vim
|
||||
|
||||
After:
|
||||
call ale#linter#Reset()
|
||||
Restore
|
||||
|
||||
unlet! b:ale_warn_about_trailing_blank_lines
|
||||
|
||||
call ale#linter#Reset()
|
||||
|
||||
Execute(The flake8 handler should handle basic warnings and syntax errors):
|
||||
AssertEqual
|
||||
@ -126,7 +134,7 @@ Execute(The flake8 handler should handle stack traces):
|
||||
\ 'ImportError: No module named parser',
|
||||
\ ])
|
||||
|
||||
Execute (The flake8 handler should handle names with spaces):
|
||||
Execute(The flake8 handler should handle names with spaces):
|
||||
AssertEqual
|
||||
\ [
|
||||
\ {
|
||||
@ -141,3 +149,29 @@ Execute (The flake8 handler should handle names with spaces):
|
||||
\ ale_linters#python#flake8#Handle(42, [
|
||||
\ 'C:\something\with spaces.py:6:6: E111 indentation is not a multiple of four',
|
||||
\ ])
|
||||
|
||||
Execute(Warnings about trailing blank lines should be reported by default):
|
||||
AssertEqual
|
||||
\ [
|
||||
\ {
|
||||
\ 'lnum': 6,
|
||||
\ 'col': 1,
|
||||
\ 'code': 'W391',
|
||||
\ 'type': 'W',
|
||||
\ 'sub_type': 'style',
|
||||
\ 'text': 'blank line at end of file',
|
||||
\ },
|
||||
\ ],
|
||||
\ ale_linters#python#flake8#Handle(bufnr(''), [
|
||||
\ 'foo.py:6:1: W391 blank line at end of file',
|
||||
\ ])
|
||||
|
||||
Execute(Disabling trailing blank line warnings should work):
|
||||
let b:ale_warn_about_trailing_blank_lines = 0
|
||||
|
||||
AssertEqual
|
||||
\ [
|
||||
\ ],
|
||||
\ ale_linters#python#flake8#Handle(bufnr(''), [
|
||||
\ 'foo.py:6:1: W391 blank line at end of file',
|
||||
\ ])
|
||||
|
@ -1,7 +1,15 @@
|
||||
Before:
|
||||
Save g:ale_warn_about_trailing_blank_lines
|
||||
|
||||
let g:ale_warn_about_trailing_blank_lines = 1
|
||||
|
||||
runtime ale_linters/python/pycodestyle.vim
|
||||
|
||||
After:
|
||||
Restore
|
||||
|
||||
unlet! b:ale_warn_about_trailing_blank_lines
|
||||
|
||||
call ale#linter#Reset()
|
||||
silent file something_else.py
|
||||
|
||||
@ -64,3 +72,29 @@ Execute(The pycodestyle handler should parse output):
|
||||
\ 'stdin:222:34: W602 deprecated form of raising exception',
|
||||
\ 'example.py:544:21: W601 .has_key() is deprecated, use ''in''',
|
||||
\ ])
|
||||
|
||||
Execute(Warnings about trailing blank lines should be reported by default):
|
||||
AssertEqual
|
||||
\ [
|
||||
\ {
|
||||
\ 'lnum': 6,
|
||||
\ 'col': 1,
|
||||
\ 'code': 'W391',
|
||||
\ 'type': 'W',
|
||||
\ 'sub_type': 'style',
|
||||
\ 'text': 'blank line at end of file',
|
||||
\ },
|
||||
\ ],
|
||||
\ ale_linters#python#pycodestyle#Handle(bufnr(''), [
|
||||
\ 'foo.py:6:1: W391 blank line at end of file',
|
||||
\ ])
|
||||
|
||||
Execute(Disabling trailing blank line warnings should work):
|
||||
let b:ale_warn_about_trailing_blank_lines = 0
|
||||
|
||||
AssertEqual
|
||||
\ [
|
||||
\ ],
|
||||
\ ale_linters#python#pycodestyle#Handle(bufnr(''), [
|
||||
\ 'foo.py:6:1: W391 blank line at end of file',
|
||||
\ ])
|
||||
|
Loading…
Reference in New Issue
Block a user