diff options
author | Dmitri Vereshchagin <dmitri.vereshchagin@gmail.com> | 2024-02-24 09:37:55 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-24 15:37:55 +0900 |
commit | b74cd026488853a3bc936600a03497cbd6587521 (patch) | |
tree | b60b07dde97e1abbee3a0c16b879936ae4f5ddd2 /ale_linters/erlang | |
parent | 5e8904cd3da4565130c09b77179ae7dddd07358f (diff) | |
download | ale-b74cd026488853a3bc936600a03497cbd6587521.zip |
Set working directory for Elvis linter (#4726)
Most of the time it works to assume that the current working
directory is the root of the project. However, this is not the case
for Rebar3 checked out dependencies, for example.
It's also worth noting that because of the way Elvis handles file
patterns, and because directories in configuration are relative to the
project root, the path supplied to command must be also relative.
Diffstat (limited to 'ale_linters/erlang')
-rw-r--r-- | ale_linters/erlang/elvis.vim | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/ale_linters/erlang/elvis.vim b/ale_linters/erlang/elvis.vim index 0fb85c07..321a6c72 100644 --- a/ale_linters/erlang/elvis.vim +++ b/ale_linters/erlang/elvis.vim @@ -26,9 +26,27 @@ function! s:AbbreviateMessage(text) abort endfunction function! s:GetCommand(buffer) abort - let l:file = ale#Escape(expand('#' . a:buffer . ':.')) + let l:cwd = s:GetCwd(a:buffer) - return '%e rock --output-format=parsable ' . l:file + 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 '' endfunction call ale#linter#Define('erlang', { @@ -36,5 +54,6 @@ call ale#linter#Define('erlang', { \ 'callback': 'ale_linters#erlang#elvis#Handle', \ 'executable': {b -> ale#Var(b, 'erlang_elvis_executable')}, \ 'command': function('s:GetCommand'), +\ 'cwd': function('s:GetCwd'), \ 'lint_file': 1, \}) |