Allow warnings about trailing blank lines to be hidden for flake8 and pycodestyle

This commit is contained in:
w0rp 2017-11-28 10:08:34 +00:00
parent 4e821e64c7
commit 0ab689db0a
6 changed files with 101 additions and 9 deletions

View File

@ -91,6 +91,12 @@ function! ale_linters#python#flake8#Handle(buffer, lines) abort
continue continue
endif 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 = { let l:item = {
\ 'lnum': l:match[1] + 0, \ 'lnum': l:match[1] + 0,
\ 'col': l:match[2] + 0, \ 'col': l:match[2] + 0,

View File

@ -23,6 +23,12 @@ function! ale_linters#python#pycodestyle#Handle(buffer, lines) abort
" lines are formatted as follows: " lines are formatted as follows:
" file.py:21:26: W291 trailing whitespace " file.py:21:26: W291 trailing whitespace
for l:match in ale#util#GetMatches(a:lines, l:pattern) 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 = { let l:item = {
\ 'lnum': l:match[2] + 0, \ 'lnum': l:match[2] + 0,
\ 'col': l:match[3] + 0, \ 'col': l:match[3] + 0,

View File

@ -1387,6 +1387,18 @@ b:ale_virtualenv_dir_names *b:ale_virtualenv_dir_names*
directory containing the Python file to find virtualenv paths. 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* g:ale_warn_about_trailing_whitespace *g:ale_warn_about_trailing_whitespace*
b:ale_warn_about_trailing_whitespace *b: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` Default: `1`
When this option is set to `1`, warnings relating to trailing whitespace on 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 lines will be shown. If warnings are too irritating while editing buffers,
errors are found to be too irritating while edits are being made, and you and you have configured Vim to automatically remove trailing whitespace,
have configured Vim to automatically remove trailing whitespace, then you you can disable these warnings by setting this option to `0`.
can disable these warnings for some linters by setting this option to `0`.
Not all linters may respect this option. If a linter does not, please file a 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. bug report, and it may be possible to add such support.

View File

@ -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 " This flag can be set to 0 to disable warnings for trailing whitespace
let g:ale_warn_about_trailing_whitespace = call ale#Set('warn_about_trailing_whitespace', 1)
\ get(g:, 'ale_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. " 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) let g:ale_max_buffer_history_size = get(g:, 'ale_max_buffer_history_size', 20)

View File

@ -1,8 +1,16 @@
Before: 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: 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): Execute(The flake8 handler should handle basic warnings and syntax errors):
AssertEqual AssertEqual
@ -126,7 +134,7 @@ Execute(The flake8 handler should handle stack traces):
\ 'ImportError: No module named parser', \ 'ImportError: No module named parser',
\ ]) \ ])
Execute (The flake8 handler should handle names with spaces): Execute(The flake8 handler should handle names with spaces):
AssertEqual AssertEqual
\ [ \ [
\ { \ {
@ -141,3 +149,29 @@ Execute (The flake8 handler should handle names with spaces):
\ ale_linters#python#flake8#Handle(42, [ \ ale_linters#python#flake8#Handle(42, [
\ 'C:\something\with spaces.py:6:6: E111 indentation is not a multiple of four', \ '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',
\ ])

View File

@ -1,7 +1,15 @@
Before: Before:
Save g:ale_warn_about_trailing_blank_lines
let g:ale_warn_about_trailing_blank_lines = 1
runtime ale_linters/python/pycodestyle.vim runtime ale_linters/python/pycodestyle.vim
After: After:
Restore
unlet! b:ale_warn_about_trailing_blank_lines
call ale#linter#Reset() call ale#linter#Reset()
silent file something_else.py 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', \ 'stdin:222:34: W602 deprecated form of raising exception',
\ 'example.py:544:21: W601 .has_key() is deprecated, use ''in''', \ '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',
\ ])