From 06f61eeeb82f30c0fceea3d1abb231378b445fc3 Mon Sep 17 00:00:00 2001 From: w0rp Date: Sun, 1 Jul 2018 13:49:40 +0100 Subject: [PATCH] Respect ale_warn_about_trailing_whitespace for yamllint --- ale_linters/yaml/yamllint.vim | 6 +++++ test/handler/test_yamllint_handler.vader | 34 +++++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/ale_linters/yaml/yamllint.vim b/ale_linters/yaml/yamllint.vim index 9e075a75..f100667e 100644 --- a/ale_linters/yaml/yamllint.vim +++ b/ale_linters/yaml/yamllint.vim @@ -34,6 +34,12 @@ function! ale_linters#yaml#yamllint#Handle(buffer, lines) abort let l:code_match = matchlist(l:item.text, '\v^(.+) \(([^)]+)\)$') if !empty(l:code_match) + if l:code_match[2] is# 'trailing-spaces' + \&& !ale#Var(a:buffer, 'warn_about_trailing_whitespace') + " Skip warnings for trailing whitespace if the option is off. + continue + endif + let l:item.text = l:code_match[1] let l:item.code = l:code_match[2] endif diff --git a/test/handler/test_yamllint_handler.vader b/test/handler/test_yamllint_handler.vader index 5ba14bc8..1aa0b9f5 100644 --- a/test/handler/test_yamllint_handler.vader +++ b/test/handler/test_yamllint_handler.vader @@ -1,10 +1,18 @@ Before: + Save g:ale_warn_about_trailing_whitespace + + let g:ale_warn_about_trailing_whitespace = 1 + runtime! ale_linters/yaml/yamllint.vim After: + Restore + + unlet! b:ale_warn_about_trailing_whitespace + call ale#linter#Reset() -Execute: +Execute(Problems should be parsed correctly for yamllint): AssertEqual \ [ \ { @@ -25,3 +33,27 @@ Execute: \ 'something.yaml:1:1: [warning] missing document start "---" (document-start)', \ 'something.yml:2:1: [error] syntax error: expected the node content, but found ''''', \ ]) + +Execute(The yamllint handler should respect ale_warn_about_trailing_whitespace): + AssertEqual + \ [ + \ { + \ 'lnum': 5, + \ 'col': 18, + \ 'type': 'E', + \ 'text': 'trailing spaces', + \ 'code': 'trailing-spaces', + \ }, + \ ], + \ ale_linters#yaml#yamllint#Handle(bufnr(''), [ + \ 'something.yml:5:18: [error] trailing spaces (trailing-spaces)', + \ ]) + + let b:ale_warn_about_trailing_whitespace = 0 + + AssertEqual + \ [ + \ ], + \ ale_linters#yaml#yamllint#Handle(bufnr(''), [ + \ 'something.yml:5:18: [error] trailing spaces (trailing-spaces)', + \ ])