]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/ale/ale_linters/vim/ale_custom_linting_rules.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 '76265755a1add77121c8f9dabb3e9bb70fe9a972' as '.vim/bundle/ale'
[etc/vim.git] / .vim / bundle / ale / ale_linters / vim / ale_custom_linting_rules.vim
1 " Author: w0rp <devw0rp@gmail.com>
2 " Description: A linter for checking ALE project code itself.
3
4 function! ale_linters#vim#ale_custom_linting_rules#GetExecutable(buffer) abort
5     let l:filename = expand('#' . a:buffer . ':p')
6     let l:dir_list = []
7
8     for l:dir in split(&runtimepath, ',')
9         if l:filename[:len(l:dir) - 1] is# l:dir
10             call add(l:dir_list, l:dir)
11         endif
12     endfor
13
14     return !empty(l:dir_list)
15     \   ? findfile('test/script/custom-linting-rules', join(l:dir_list, ','))
16     \   : ''
17 endfunction
18
19 function! s:GetALEProjectDir(buffer) abort
20     let l:executable = ale_linters#vim#ale_custom_linting_rules#GetExecutable(a:buffer)
21
22     return ale#path#Dirname(ale#path#Dirname(ale#path#Dirname(l:executable)))
23 endfunction
24
25 function! ale_linters#vim#ale_custom_linting_rules#GetCwd(buffer) abort
26     let l:executable = ale_linters#vim#ale_custom_linting_rules#GetExecutable(a:buffer)
27
28     return ale#path#Dirname(ale#path#Dirname(ale#path#Dirname(l:executable)))
29 endfunction
30
31 function! ale_linters#vim#ale_custom_linting_rules#GetCommand(buffer) abort
32     let l:temp_dir = ale#command#CreateDirectory(a:buffer)
33     let l:temp_file = l:temp_dir . '/example.vim'
34
35     let l:lines = getbufline(a:buffer, 1, '$')
36     call ale#util#Writefile(a:buffer, l:lines, l:temp_file)
37
38     return '%e ' . ale#Escape(l:temp_dir)
39 endfunction
40
41 function! ale_linters#vim#ale_custom_linting_rules#Handle(buffer, lines) abort
42     let l:dir = s:GetALEProjectDir(a:buffer)
43     let l:output = []
44     let l:pattern = '\v^([a-zA-Z]?:?[^:]+):(\d+) (.+)$'
45
46     for l:match in ale#util#GetMatches(a:lines, l:pattern)
47         " Ignore trailing whitespace errors if we've turned them off.
48         if !ale#Var(a:buffer, 'warn_about_trailing_whitespace')
49         \&& l:match[3] is# 'Trailing whitespace'
50             continue
51         endif
52
53         call add(l:output, {
54         \   'lnum': l:match[2],
55         \   'text': l:match[3],
56         \   'type': 'W',
57         \})
58     endfor
59
60     return l:output
61 endfunction
62
63 call ale#linter#Define('vim', {
64 \   'name': 'ale_custom_linting_rules',
65 \   'executable': function('ale_linters#vim#ale_custom_linting_rules#GetExecutable'),
66 \   'cwd': function('ale_linters#vim#ale_custom_linting_rules#GetCwd'),
67 \   'command': function('ale_linters#vim#ale_custom_linting_rules#GetCommand'),
68 \   'callback': 'ale_linters#vim#ale_custom_linting_rules#Handle',
69 \   'read_buffer': 0,
70 \})