1
0
Fork 0
mirror of synced 2024-10-18 09:49:00 -04:00
ultimate-vim/sources_non_forked/ale/ale_linters/erlang/elvis.vim

60 lines
1.6 KiB
VimL
Raw Normal View History

2020-12-04 16:15:32 -05:00
" Author: Dmitri Vereshchagin <dmitri.vereshchagin@gmail.com>
" Description: Elvis linter for Erlang files
call ale#Set('erlang_elvis_executable', 'elvis')
function! ale_linters#erlang#elvis#Handle(buffer, lines) abort
let l:pattern = '\v:(\d+):[^:]+:(.+)'
let l:loclist = []
for l:match in ale#util#GetMatches(a:lines, l:pattern)
call add(l:loclist, {
\ 'lnum': str2nr(l:match[1]),
\ 'text': s:AbbreviateMessage(l:match[2]),
\ 'type': 'W',
2022-08-08 09:45:56 -04:00
\ 'sub_type': 'style',
2020-12-04 16:15:32 -05:00
\})
endfor
return l:loclist
endfunction
function! s:AbbreviateMessage(text) abort
let l:pattern = '\v\c^(line \d+ is too long):.*$'
return substitute(a:text, l:pattern, '\1.', '')
endfunction
function! s:GetCommand(buffer) abort
2024-10-06 04:25:50 -04:00
let l:cwd = s:GetCwd(a:buffer)
2020-12-04 16:15:32 -05:00
2024-10-06 04:25:50 -04:00
let l:file = !empty(l:cwd)
\ ? expand('#' . a:buffer . ':p')[len(l:cwd) + 1:]
\ : expand('#' . a:buffer . ':.')
return '%e rock --output-format=parsable ' . ale#Escape(l:file)
endfunction
function! s:GetCwd(buffer) abort
let l:markers = ['elvis.config', 'rebar.lock', 'erlang.mk']
for l:path in ale#path#Upwards(expand('#' . a:buffer . ':p:h'))
for l:marker in l:markers
if filereadable(l:path . '/' . l:marker)
return l:path
endif
endfor
endfor
return ''
2020-12-04 16:15:32 -05:00
endfunction
call ale#linter#Define('erlang', {
\ 'name': 'elvis',
\ 'callback': 'ale_linters#erlang#elvis#Handle',
\ 'executable': {b -> ale#Var(b, 'erlang_elvis_executable')},
\ 'command': function('s:GetCommand'),
2024-10-06 04:25:50 -04:00
\ 'cwd': function('s:GetCwd'),
2020-12-04 16:15:32 -05:00
\ 'lint_file': 1,
\})