From eeea72e16740bb1dfa5bd554a927e6bbee76a9b5 Mon Sep 17 00:00:00 2001 From: w0rp Date: Tue, 6 Jun 2017 20:37:04 +0100 Subject: [PATCH] Fix #625 Ignore Perl errors from other files --- ale_linters/perl/perl.vim | 14 +++++++++----- test/handler/test_perl_handler.vader | 25 +++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 test/handler/test_perl_handler.vader diff --git a/ale_linters/perl/perl.vim b/ale_linters/perl/perl.vim index ab4defb..53c91d3 100644 --- a/ale_linters/perl/perl.vim +++ b/ale_linters/perl/perl.vim @@ -20,17 +20,21 @@ endfunction function! ale_linters#perl#perl#Handle(buffer, lines) abort let l:pattern = '\(.\+\) at \(.\+\) line \(\d\+\)' let l:output = [] + let l:basename = expand('#' . a:buffer . ':t') for l:match in ale#util#GetMatches(a:lines, l:pattern) let l:line = l:match[3] let l:text = l:match[1] let l:type = 'E' - call add(l:output, { - \ 'lnum': l:line, - \ 'text': l:text, - \ 'type': l:type, - \}) + if l:match[2][-len(l:basename):] ==# l:basename + \&& l:text !=# 'BEGIN failed--compilation aborted' + call add(l:output, { + \ 'lnum': l:line, + \ 'text': l:text, + \ 'type': l:type, + \}) + endif endfor return l:output diff --git a/test/handler/test_perl_handler.vader b/test/handler/test_perl_handler.vader new file mode 100644 index 0000000..2961b26 --- /dev/null +++ b/test/handler/test_perl_handler.vader @@ -0,0 +1,25 @@ +Before: + " Switch to the test rails directory. + let b:path = getcwd() + silent! cd /testplugin/test/handler + + runtime ale_linters/perl/perl.vim + +After: + silent! 'cd ' . fnameescape(b:path) + unlet! b:path + + call ale#linter#Reset() + +Execute(The Perl linter should ignore errors from other files): + silent! noautocmd file bar.pl + + AssertEqual + \ [ + \ {'lnum': '2', 'type': 'E', 'text': 'Compilation failed in require'}, + \ ], + \ ale_linters#perl#perl#Handle(bufnr(''), [ + \ 'syntax error at ' . b:path . '/foo.pm line 4, near "aklsdfjmy "', + \ 'Compilation failed in require at ' . b:path . '/bar.pl line 2.', + \ 'BEGIN failed--compilation aborted at ' . b:path . '/bar.pl line 2.', + \ ])