]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/ale/ale_linters/erlang/dialyzer.vim

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Merge commit 'a39f715c13be3352193ffd9c5b7536b8786eff64' as '.vim/bundle/vim-lsp'
[etc/vim.git] / .vim / bundle / ale / ale_linters / erlang / dialyzer.vim
1 " Author: Autoine Gagne - https://github.com/AntoineGagne
2 " Description: Define a checker that runs dialyzer on Erlang files.
3
4 let g:ale_erlang_dialyzer_executable =
5 \   get(g:, 'ale_erlang_dialyzer_executable', 'dialyzer')
6 let g:ale_erlang_dialyzer_options =
7 \   get(g:, 'ale_erlang_dialyzer_options', '-Wunmatched_returns'
8 \                                        . ' -Werror_handling'
9 \                                        . ' -Wrace_conditions'
10 \                                        . ' -Wunderspecs')
11 let g:ale_erlang_dialyzer_plt_file =
12 \   get(g:, 'ale_erlang_dialyzer_plt_file', '')
13 let g:ale_erlang_dialyzer_rebar3_profile =
14 \   get(g:, 'ale_erlang_dialyzer_rebar3_profile', 'default')
15
16 function! ale_linters#erlang#dialyzer#GetRebar3Profile(buffer) abort
17     return ale#Var(a:buffer, 'erlang_dialyzer_rebar3_profile')
18 endfunction
19
20 function! ale_linters#erlang#dialyzer#FindPlt(buffer) abort
21     let l:plt_file = ''
22     let l:rebar3_profile = ale_linters#erlang#dialyzer#GetRebar3Profile(a:buffer)
23     let l:plt_file_directory = ale#path#FindNearestDirectory(a:buffer, '_build/' . l:rebar3_profile)
24
25     if !empty(l:plt_file_directory)
26         let l:plt_file = globpath(l:plt_file_directory, '*_plt', 0, 1)
27     endif
28
29     if !empty(l:plt_file)
30         return l:plt_file[0]
31     endif
32
33     if !empty($REBAR_PLT_DIR)
34         return expand('$REBAR_PLT_DIR/dialyzer/plt')
35     endif
36
37     return expand('$HOME/.dialyzer_plt')
38 endfunction
39
40 function! ale_linters#erlang#dialyzer#GetPlt(buffer) abort
41     let l:plt_file = ale#Var(a:buffer, 'erlang_dialyzer_plt_file')
42
43     if !empty(l:plt_file)
44         return l:plt_file
45     endif
46
47     return ale_linters#erlang#dialyzer#FindPlt(a:buffer)
48 endfunction
49
50 function! ale_linters#erlang#dialyzer#GetExecutable(buffer) abort
51     return ale#Var(a:buffer, 'erlang_dialyzer_executable')
52 endfunction
53
54 function! ale_linters#erlang#dialyzer#GetCommand(buffer) abort
55     let l:options = ale#Var(a:buffer, 'erlang_dialyzer_options')
56
57     let l:command = ale#Escape(ale_linters#erlang#dialyzer#GetExecutable(a:buffer))
58     \   . ' -n'
59     \   . ' --plt ' . ale#Escape(ale_linters#erlang#dialyzer#GetPlt(a:buffer))
60     \   . ' ' . l:options
61     \   . ' %s'
62
63     return l:command
64 endfunction
65
66 function! ale_linters#erlang#dialyzer#Handle(buffer, lines) abort
67     " Match patterns like the following:
68     "
69     " erl_tidy_prv_fmt.erl:3: Callback info about the provider behaviour is not available
70     let l:pattern = '^\S\+:\(\d\+\): \(.\+\)$'
71     let l:output = []
72
73     for l:line in a:lines
74         let l:match = matchlist(l:line, l:pattern)
75
76         if len(l:match) != 0
77             let l:code = l:match[2]
78
79             call add(l:output, {
80             \   'lnum': str2nr(l:match[1]),
81             \   'lcol': 0,
82             \   'text': l:code,
83             \   'type': 'W'
84             \})
85         endif
86     endfor
87
88     return l:output
89 endfunction
90
91 call ale#linter#Define('erlang', {
92 \   'name': 'dialyzer',
93 \   'executable': function('ale_linters#erlang#dialyzer#GetExecutable'),
94 \   'command': function('ale_linters#erlang#dialyzer#GetCommand'),
95 \   'callback': function('ale_linters#erlang#dialyzer#Handle'),
96 \   'lint_file': 1
97 \})