summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2017-11-28 10:12:49 +0000
committerw0rp <devw0rp@gmail.com>2017-11-28 10:12:49 +0000
commita43ada93e40b8286dde3cd62f10369876787ddc1 (patch)
tree067757a8ef5946d59b9ac6717012aee8f466883c
parent0ab689db0a137f7f62a3856eeba7c0ad235a625a (diff)
downloadale-a43ada93e40b8286dde3cd62f10369876787ddc1.zip
Allow warnings about trailing whitespace to be disabled for pycodestyle, and cover the flake8 code with tests
-rw-r--r--ale_linters/python/pycodestyle.vim6
-rw-r--r--test/handler/test_flake8_handler.vader39
-rw-r--r--test/handler/test_pycodestyle_handler.vader39
3 files changed, 84 insertions, 0 deletions
diff --git a/ale_linters/python/pycodestyle.vim b/ale_linters/python/pycodestyle.vim
index 1958f37f..bbecdf03 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# 'W291' || l:match[4] is# 'W293')
+ \&& !ale#Var(a:buffer, 'warn_about_trailing_whitespace')
+ " Skip warnings for trailing whitespace if the option is off.
+ continue
+ endif
+
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
diff --git a/test/handler/test_flake8_handler.vader b/test/handler/test_flake8_handler.vader
index 655f02a3..8b440392 100644
--- a/test/handler/test_flake8_handler.vader
+++ b/test/handler/test_flake8_handler.vader
@@ -1,7 +1,9 @@
Before:
Save g:ale_warn_about_trailing_blank_lines
+ Save g:ale_warn_about_trailing_whitespace
let g:ale_warn_about_trailing_blank_lines = 1
+ let g:ale_warn_about_trailing_whitespace = 1
runtime ale_linters/python/flake8.vim
@@ -9,6 +11,7 @@ After:
Restore
unlet! b:ale_warn_about_trailing_blank_lines
+ unlet! b:ale_warn_about_trailing_whitespace
call ale#linter#Reset()
@@ -150,6 +153,42 @@ Execute(The flake8 handler should handle names with spaces):
\ 'C:\something\with spaces.py:6:6: E111 indentation is not a multiple of four',
\ ])
+Execute(Warnings about trailing whitespace should be reported by default):
+ AssertEqual
+ \ [
+ \ {
+ \ 'lnum': 6,
+ \ 'col': 1,
+ \ 'code': 'W291',
+ \ 'type': 'W',
+ \ 'sub_type': 'style',
+ \ 'text': 'who cares',
+ \ },
+ \ {
+ \ 'lnum': 6,
+ \ 'col': 1,
+ \ 'code': 'W293',
+ \ 'type': 'W',
+ \ 'sub_type': 'style',
+ \ 'text': 'who cares',
+ \ },
+ \ ],
+ \ ale_linters#python#flake8#Handle(bufnr(''), [
+ \ 'foo.py:6:1: W291 who cares',
+ \ 'foo.py:6:1: W293 who cares',
+ \ ])
+
+Execute(Disabling trailing whitespace warnings should work):
+ let b:ale_warn_about_trailing_whitespace = 0
+
+ AssertEqual
+ \ [
+ \ ],
+ \ ale_linters#python#flake8#Handle(bufnr(''), [
+ \ 'foo.py:6:1: W291 who cares',
+ \ 'foo.py:6:1: W293 who cares',
+ \ ])
+
Execute(Warnings about trailing blank lines should be reported by default):
AssertEqual
\ [
diff --git a/test/handler/test_pycodestyle_handler.vader b/test/handler/test_pycodestyle_handler.vader
index cb92eb3b..0fd885d6 100644
--- a/test/handler/test_pycodestyle_handler.vader
+++ b/test/handler/test_pycodestyle_handler.vader
@@ -1,7 +1,9 @@
Before:
Save g:ale_warn_about_trailing_blank_lines
+ Save g:ale_warn_about_trailing_whitespace
let g:ale_warn_about_trailing_blank_lines = 1
+ let g:ale_warn_about_trailing_whitespace = 1
runtime ale_linters/python/pycodestyle.vim
@@ -9,6 +11,7 @@ After:
Restore
unlet! b:ale_warn_about_trailing_blank_lines
+ unlet! b:ale_warn_about_trailing_whitespace
call ale#linter#Reset()
silent file something_else.py
@@ -73,6 +76,42 @@ Execute(The pycodestyle handler should parse output):
\ 'example.py:544:21: W601 .has_key() is deprecated, use ''in''',
\ ])
+Execute(Warnings about trailing whitespace should be reported by default):
+ AssertEqual
+ \ [
+ \ {
+ \ 'lnum': 6,
+ \ 'col': 1,
+ \ 'code': 'W291',
+ \ 'type': 'W',
+ \ 'sub_type': 'style',
+ \ 'text': 'who cares',
+ \ },
+ \ {
+ \ 'lnum': 6,
+ \ 'col': 1,
+ \ 'code': 'W293',
+ \ 'type': 'W',
+ \ 'sub_type': 'style',
+ \ 'text': 'who cares',
+ \ },
+ \ ],
+ \ ale_linters#python#pycodestyle#Handle(bufnr(''), [
+ \ 'foo.py:6:1: W291 who cares',
+ \ 'foo.py:6:1: W293 who cares',
+ \ ])
+
+Execute(Disabling trailing whitespace warnings should work):
+ let b:ale_warn_about_trailing_whitespace = 0
+
+ AssertEqual
+ \ [
+ \ ],
+ \ ale_linters#python#pycodestyle#Handle(bufnr(''), [
+ \ 'foo.py:6:1: W291 who cares',
+ \ 'foo.py:6:1: W293 who cares',
+ \ ])
+
Execute(Warnings about trailing blank lines should be reported by default):
AssertEqual
\ [