diff options
author | w0rp <w0rp@users.noreply.github.com> | 2018-06-27 21:39:36 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-27 21:39:36 +0100 |
commit | 980aa35566f1a5c66c7b9939bb07ec68deebccb2 (patch) | |
tree | 0639cd27bfd5a562de4a69e4e06b415be846ac63 | |
parent | b047271051d8ef448bf4bac120234205310b232a (diff) | |
parent | 4d935ff32a1ac8618c8afbf3104cf1864f633300 (diff) | |
download | ale-980aa35566f1a5c66c7b9939bb07ec68deebccb2.zip |
Merge pull request #1675 from nicopauss/master
Improve pyrex cython linter.
-rw-r--r-- | ale_linters/pyrex/cython.vim | 41 | ||||
-rw-r--r-- | doc/ale-pyrex.txt | 25 | ||||
-rw-r--r-- | doc/ale.txt | 2 | ||||
-rw-r--r-- | test/command_callback/test_pyrex_cython_command_callback.vader | 50 | ||||
-rw-r--r-- | test/handler/test_pyrex_cython_handler.vader | 26 |
5 files changed, 140 insertions, 4 deletions
diff --git a/ale_linters/pyrex/cython.vim b/ale_linters/pyrex/cython.vim index bd5a447f..9b6b39d7 100644 --- a/ale_linters/pyrex/cython.vim +++ b/ale_linters/pyrex/cython.vim @@ -1,10 +1,43 @@ -" Author: w0rp <devw0rp@gmail.com> +" Author: w0rp <devw0rp@gmail.com>, +" Nicolas Pauss <https://github.com/nicopauss> " Description: cython syntax checking for cython files. +call ale#Set('pyrex_cython_executable', 'cython') +call ale#Set('pyrex_cython_options', '--warning-extra') + +function! ale_linters#pyrex#cython#GetExecutable(buffer) abort + return ale#Var(a:buffer, 'pyrex_cython_executable') +endfunction + +function! ale_linters#pyrex#cython#GetCommand(buffer) abort + let l:local_dir = ale#Escape(fnamemodify(bufname(a:buffer), ':p:h')) + + return ale#Escape(ale_linters#pyrex#cython#GetExecutable(a:buffer)) + \ . ' --working ' . l:local_dir . ' --include-dir ' . l:local_dir + \ . ' ' . ale#Var(a:buffer, 'pyrex_cython_options') + \ . ' --output-file ' . g:ale#util#nul_file . ' %t' +endfunction + +function! ale_linters#pyrex#cython#Handle(buffer, lines) abort + let l:pattern = '\v^(\w+: )?[^:]+:(\d+):?(\d+)?:? ?(.+)$' + let l:output = [] + + for l:match in ale#util#GetMatches(a:lines, l:pattern) + call add(l:output, { + \ 'lnum': l:match[2] + 0, + \ 'col': l:match[3] + 0, + \ 'text': l:match[4], + \ 'type': l:match[1][0] is# 'w' ? 'W' : 'E', + \}) + endfor + + return l:output +endfunction + call ale#linter#Define('pyrex', { \ 'name': 'cython', \ 'output_stream': 'stderr', -\ 'executable': 'cython', -\ 'command': 'cython --warning-extra -o ' . g:ale#util#nul_file . ' %t', -\ 'callback': 'ale#handlers#unix#HandleAsError', +\ 'executable_callback': 'ale_linters#pyrex#cython#GetExecutable', +\ 'command_callback': 'ale_linters#pyrex#cython#GetCommand', +\ 'callback': 'ale_linters#pyrex#cython#Handle', \}) diff --git a/doc/ale-pyrex.txt b/doc/ale-pyrex.txt new file mode 100644 index 00000000..245e611f --- /dev/null +++ b/doc/ale-pyrex.txt @@ -0,0 +1,25 @@ +=============================================================================== +ALE Pyrex (Cython) Integration *ale-pyrex-options* + + +=============================================================================== +cython *ale-pyrex-cython* + +g:ale_pyrex_cython_executable *g:ale_pyrex_cython_executable* + *b:ale_pyrex_cython_executable* + Type: |String| + Default: `'cython'` + + This variable can be changed to use a different executable for cython. + + +g:ale_pyrex_cython_options *g:ale_pyrex_cython_options* + *b:ale_pyrex_cython_options* + Type: |String| + Default: `'--warning-extra --warning-errors'` + + This variable can be changed to modify flags given to cython. + + +=============================================================================== + vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl: diff --git a/doc/ale.txt b/doc/ale.txt index 6c0b3ccf..a24098f3 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -185,6 +185,8 @@ CONTENTS *ale-contents* puglint.............................|ale-pug-puglint| puppet................................|ale-puppet-options| puppetlint..........................|ale-puppet-puppetlint| + pyrex (cython)........................|ale-pyrex-options| + cython..............................|ale-pyrex-cython| python................................|ale-python-options| autopep8............................|ale-python-autopep8| black...............................|ale-python-black| diff --git a/test/command_callback/test_pyrex_cython_command_callback.vader b/test/command_callback/test_pyrex_cython_command_callback.vader new file mode 100644 index 00000000..527ed2dd --- /dev/null +++ b/test/command_callback/test_pyrex_cython_command_callback.vader @@ -0,0 +1,50 @@ +Before: + Save g:ale_pyrex_cython_executable + Save g:ale_pyrex_cython_options + + unlet! g:ale_pyrex_cython_executable + unlet! b:ale_pyrex_cython_executable + unlet! g:ale_pyrex_cython_options + unlet! b:ale_pyrex_cython_options + + runtime ale_linters/pyrex/cython.vim + + call ale#test#SetDirectory('/testplugin/test/command_callback') + +After: + Restore + unlet! b:ale_pyrex_cython_options + unlet! b:ale_pyrex_cython_executable + call ale#linter#Reset() + call ale#test#RestoreDirectory() + +Execute(The default cython command should be correct): + AssertEqual + \ ale#Escape('cython') + \ . ' --working ' . ale#Escape(g:dir) + \ . ' --include-dir ' . ale#Escape(g:dir) + \ . ' --warning-extra' + \ . ' --output-file ' . g:ale#util#nul_file . ' %t', + \ ale_linters#pyrex#cython#GetCommand(bufnr('')) + +Execute(The cython executable should be configurable): + let b:ale_pyrex_cython_executable = 'cython_foobar' + + AssertEqual + \ ale#Escape('cython_foobar') + \ . ' --working ' . ale#Escape(g:dir) + \ . ' --include-dir ' . ale#Escape(g:dir) + \ . ' --warning-extra' + \ . ' --output-file ' . g:ale#util#nul_file . ' %t', + \ ale_linters#pyrex#cython#GetCommand(bufnr('')) + +Execute(Additional cython options should be configurable): + let b:ale_pyrex_cython_options = '--foobar' + + AssertEqual + \ ale#Escape('cython') + \ . ' --working ' . ale#Escape(g:dir) + \ . ' --include-dir ' . ale#Escape(g:dir) + \ . ' --foobar' + \ . ' --output-file ' . g:ale#util#nul_file . ' %t', + \ ale_linters#pyrex#cython#GetCommand(bufnr('')) diff --git a/test/handler/test_pyrex_cython_handler.vader b/test/handler/test_pyrex_cython_handler.vader new file mode 100644 index 00000000..fd0f9a8b --- /dev/null +++ b/test/handler/test_pyrex_cython_handler.vader @@ -0,0 +1,26 @@ +Before: + runtime ale_linters/pyrex/cython.vim + +After: + call ale#linter#Reset() + +Execute(The cython handler should handle warnings and errors): + AssertEqual + \ [ + \ { + \ 'lnum': 42, + \ 'col': 7, + \ 'text': 'some warning', + \ 'type': 'W', + \ }, + \ { + \ 'lnum': 777, + \ 'col': 21, + \ 'text': 'some error', + \ 'type': 'E', + \ }, + \ ], + \ ale_linters#pyrex#cython#Handle(347, [ + \ 'warning: file:42:7: some warning', + \ 'file:777:21: some error', + \ ]) |