]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/ale/ale_linters/ruby/packwerk.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:

Do not set EDITOR/VISUAL for shell
[etc/vim.git] / .vim / bundle / ale / ale_linters / ruby / packwerk.vim
1 " Author: ymap - https://github.com/ymap
2 " Description: Packwerk, a static analyzer used to enforce boundaries and modularize Rails applications.
3
4 call ale#Set('ruby_packwerk_executable', 'packwerk')
5 call ale#Set('ruby_packwerk_options', '')
6
7 function! ale_linters#ruby#packwerk#Handle(buffer, lines) abort
8     let l:pattern = '\v^[^:]+:(\d+):(\d+)$'
9     let l:index = 0
10     let l:output = []
11
12     while l:index < len(a:lines) - 1
13         let l:cleaned_line = substitute(a:lines[l:index], '\v\e\[[0-9;]*m', '', 'g')
14         let l:match = matchlist(l:cleaned_line, l:pattern)
15
16         if len(l:match) > 0
17             call add(l:output, {
18             \   'lnum': l:match[1] + 0,
19             \   'col': l:match[2] + 0,
20             \   'text': a:lines[l:index + 1],
21             \})
22         endif
23
24         let l:index += 1
25     endwhile
26
27     return l:output
28 endfunction
29
30 function! ale_linters#ruby#packwerk#GetCommand(buffer) abort
31     let l:rails_root = ale#ruby#FindRailsRoot(a:buffer)
32
33     if l:rails_root is? ''
34         return ''
35     endif
36
37     let l:executable = ale#Var(a:buffer, 'ruby_packwerk_executable')
38     let l:sep = has('win32') ? '\' : '/'
39     let l:abs_path = expand('#' . a:buffer . ':p')
40     let l:rel_path = substitute(l:abs_path, escape(l:rails_root . l:sep, '\'), '', '')
41
42     return ale#ruby#EscapeExecutable(l:executable, 'packwerk')
43     \   . ' check'
44     \   . ale#Pad(ale#Var(a:buffer, 'ruby_packwerk_options'))
45     \   . ' '
46     \   . ale#Escape(rel_path)
47 endfunction
48
49 call ale#linter#Define('ruby', {
50 \   'name': 'packwerk',
51 \   'executable': {b -> ale#Var(b, 'ruby_packwerk_executable')},
52 \   'command': function('ale_linters#ruby#packwerk#GetCommand'),
53 \   'callback': 'ale_linters#ruby#packwerk#Handle',
54 \   'lint_file': 1,
55 \})