Skip to content

Instantly share code, notes, and snippets.

@softwaredoug
Created May 18, 2024 12:12
Show Gist options
  • Save softwaredoug/abc2404ada475d458a580fe62a22b4a3 to your computer and use it in GitHub Desktop.
Save softwaredoug/abc2404ada475d458a580fe62a22b4a3 to your computer and use it in GitHub Desktop.
Adds Cython-lint to ALE
" cython-lint ALE linter (assumes you have cython lint installedhttps://github.com/MarcoGorelli/cython-lint)
"
" Usage, place under ale_linters/pyrex/cython-lint.vim
" Configure the following in your vim config (e.g. .vimrc)
"
" let g:ale_linters = {
" \ 'pyrex': ['cython-lint', 'cython'],
" \}
" let g:ale_cython_cython_lint_executable = 'cython-lint'
call ale#Set('pyrex_cython_executable', 'cython-lint')
function! ALE_cython_lint_handle(buffer, lines) abort
" Regex from flake8
let l:pattern = '\v^[a-zA-Z]?:?[^:]+:(\d+):?(\d+)?: ([[:alnum:]]+):? (.*)$'
let l:output = []
for l:match in ale#util#GetMatches(a:lines, l:pattern)
call add(l:output, {
\ 'lnum': l:match[1] + 0,
\ 'col': l:match[2] + 0,
\ 'text': l:match[4],
\ 'type': 'W',
\})
endfor
return l:output
endfunction
function! s:build_cython_lint_command(buffer) abort
let l:executable = ale#Var(a:buffer, 'pyrex_cython_lint_executable')
return l:executable . ' %t 2>&1'
endfunction
call ale#linter#Define('pyrex', {
\ 'name': 'cython-lint',
\ 'output_stream': 'stdout',
\ 'executable': {b -> ale#Var(b, 'pyrex_cython_lint_executable')},
\ 'command': function('s:build_cython_lint_command'),
\ 'callback': 'ALE_cython_lint_handle',
\})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment