From a6a8c90126e83378280a21a01f947ef0a8f1af8a Mon Sep 17 00:00:00 2001 From: Horacio Sanson Date: Mon, 10 Dec 2018 23:38:03 +0900 Subject: Fix 368 - Lacheck reports errors from input{} files. This PR adds additional check to lacheck linter to exclude any warnings related to sourced files via latex \input{} command. Closes: #368 --- ale_linters/tex/lacheck.vim | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/ale_linters/tex/lacheck.vim b/ale_linters/tex/lacheck.vim index 5e5a94f1..1d615c59 100644 --- a/ale_linters/tex/lacheck.vim +++ b/ale_linters/tex/lacheck.vim @@ -8,20 +8,26 @@ function! ale_linters#tex#lacheck#Handle(buffer, lines) abort " " "book.tex", line 37: possible unwanted space at "{" " "book.tex", line 38: missing `\ ' after "etc." - let l:pattern = '^".\+", line \(\d\+\): \(.\+\)$' + let l:pattern = '^"\(.\+\)", line \(\d\+\): \(.\+\)$' let l:output = [] for l:match in ale#util#GetMatches(a:lines, l:pattern) " lacheck follows `\input{}` commands. If the cwd is not the same as the " file in the buffer then it will fail to find the inputed items. We do not " want warnings from those items anyway - if !empty(matchstr(l:match[2], '^Could not open ".\+"$')) + if !empty(matchstr(l:match[3], '^Could not open ".\+"$')) + continue + endif + + " lacheck follows `\input{}` commands. We are only interested in + " reporting errors for the current buffer only. + if empty(matchstr(fnamemodify(l:match[1], ':t'), bufname(a:buffer))) continue endif call add(l:output, { - \ 'lnum': l:match[1] + 0, - \ 'text': l:match[2], + \ 'lnum': l:match[2] + 0, + \ 'text': l:match[3], \ 'type': 'W', \}) endfor -- cgit v1.2.3 From 5052eca5cb59389275ff1341525214228bad324a Mon Sep 17 00:00:00 2001 From: Horacio Sanson Date: Tue, 11 Dec 2018 23:44:06 +0900 Subject: Add tests to lacheck linter --- ale_linters/tex/lacheck.vim | 2 +- .../test_tex_lacheck_command_callback.vader | 13 ++++++++ test/command_callback/tex_paths/sample1.tex | 0 test/command_callback/tex_paths/sample2.tex | 0 test/handler/test_lacheck_handler.vader | 36 ++++++++++++++++++++++ 5 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 test/command_callback/test_tex_lacheck_command_callback.vader create mode 100644 test/command_callback/tex_paths/sample1.tex create mode 100644 test/command_callback/tex_paths/sample2.tex create mode 100644 test/handler/test_lacheck_handler.vader diff --git a/ale_linters/tex/lacheck.vim b/ale_linters/tex/lacheck.vim index 1d615c59..ee09fb41 100644 --- a/ale_linters/tex/lacheck.vim +++ b/ale_linters/tex/lacheck.vim @@ -21,7 +21,7 @@ function! ale_linters#tex#lacheck#Handle(buffer, lines) abort " lacheck follows `\input{}` commands. We are only interested in " reporting errors for the current buffer only. - if empty(matchstr(fnamemodify(l:match[1], ':t'), bufname(a:buffer))) + if empty(matchstr(fnamemodify(l:match[1], ':t'), fnamemodify(bufname(a:buffer), ':t'))) continue endif diff --git a/test/command_callback/test_tex_lacheck_command_callback.vader b/test/command_callback/test_tex_lacheck_command_callback.vader new file mode 100644 index 00000000..b404cc78 --- /dev/null +++ b/test/command_callback/test_tex_lacheck_command_callback.vader @@ -0,0 +1,13 @@ +Before: + call ale#assert#SetUpLinterTest('tex', 'lacheck') + +After: + call ale#assert#TearDownLinterTest() + +Execute(Executable should default to lacheck): + AssertLinter 'lacheck', ale#Escape('lacheck') . ' %t' + +Execute(Should be able to set a custom executable): + let g:ale_tex_lacheck_executable = 'bin/foo' + + AssertLinter 'bin/foo' , ale#Escape('bin/foo') . ' %t' diff --git a/test/command_callback/tex_paths/sample1.tex b/test/command_callback/tex_paths/sample1.tex new file mode 100644 index 00000000..e69de29b diff --git a/test/command_callback/tex_paths/sample2.tex b/test/command_callback/tex_paths/sample2.tex new file mode 100644 index 00000000..e69de29b diff --git a/test/handler/test_lacheck_handler.vader b/test/handler/test_lacheck_handler.vader new file mode 100644 index 00000000..0bcc3be8 --- /dev/null +++ b/test/handler/test_lacheck_handler.vader @@ -0,0 +1,36 @@ +Before: + runtime ale_linters/tex/lacheck.vim + call ale#test#SetDirectory('/testplugin/test') + +After: + call ale#linter#Reset() + call ale#test#RestoreDirectory() + +Execute(The lacheck handler should parse lines correctly): + + call ale#test#SetFilename('command_callback/tex_paths/sample1.tex') + + AssertEqual + \ [ + \ { + \ 'lnum': 1, + \ 'type': 'W', + \ 'text': 'perhaps you should insert a `~'' before "\ref"' + \ } + \ ], + \ ale_linters#tex#lacheck#Handle(bufnr(''), [ + \ "** sample1:", + \ "\"sample1.tex\", line 1: perhaps you should insert a `~' before \"\\ref\"" + \ ]) + +Execute(The lacheck handler should ignore errors from input files): + + call ale#test#SetFilename('ale_test.tex') + + AssertEqual + \ [ + \ ], + \ ale_linters#tex#lacheck#Handle(255, [ + \ "** ale_input:", + \ "\"ale_input.tex\", line 1: perhaps you should insert a `~' before \"\\ref\"" + \ ]) -- cgit v1.2.3