summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2017-11-28 10:08:34 +0000
committerw0rp <devw0rp@gmail.com>2017-11-28 10:08:34 +0000
commit0ab689db0a137f7f62a3856eeba7c0ad235a625a (patch)
treeea80ba1bfb220de9a0aa55c60c7fac0cf8c13522
parent4e821e64c7292ba635e55c409a015023d7549374 (diff)
downloadale-0ab689db0a137f7f62a3856eeba7c0ad235a625a.zip
Allow warnings about trailing blank lines to be hidden for flake8 and pycodestyle
-rw-r--r--ale_linters/python/flake8.vim6
-rw-r--r--ale_linters/python/pycodestyle.vim6
-rw-r--r--doc/ale.txt19
-rw-r--r--plugin/ale.vim5
-rw-r--r--test/handler/test_flake8_handler.vader40
-rw-r--r--test/handler/test_pycodestyle_handler.vader34
6 files changed, 101 insertions, 9 deletions
diff --git a/ale_linters/python/flake8.vim b/ale_linters/python/flake8.vim
index 480e6058..400e60f0 100644
--- a/ale_linters/python/flake8.vim
+++ b/ale_linters/python/flake8.vim
@@ -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,
diff --git a/ale_linters/python/pycodestyle.vim b/ale_linters/python/pycodestyle.vim
index 0382e9d0..1958f37f 100644
--- a/ale_linters/python/pycodestyle.vim
+++ b/ale_linters/python/pycodestyle.vim
@@ -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,
diff --git a/doc/ale.txt b/doc/ale.txt
index 7d870774..184912ce 100644
--- a/doc/ale.txt
+++ b/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.
diff --git a/plugin/ale.vim b/plugin/ale.vim
index a8bce1b4..8c97e39f 100644
--- a/plugin/ale.vim
+++ b/plugin/ale.vim
@@ -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)
diff --git a/test/handler/test_flake8_handler.vader b/test/handler/test_flake8_handler.vader
index d8cb51b3..655f02a3 100644
--- a/test/handler/test_flake8_handler.vader
+++ b/test/handler/test_flake8_handler.vader
@@ -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',
+ \ ])
diff --git a/test/handler/test_pycodestyle_handler.vader b/test/handler/test_pycodestyle_handler.vader
index 856f4295..cb92eb3b 100644
--- a/test/handler/test_pycodestyle_handler.vader
+++ b/test/handler/test_pycodestyle_handler.vader
@@ -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',
+ \ ])