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.
1 " Author: w0rp <devw0rp@gmail.com>
2 " Description: A linter for checking ALE project code itself.
4 function! ale_linters#vim#ale_custom_linting_rules#GetExecutable(buffer) abort
5 let l:filename = expand('#' . a:buffer . ':p')
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)
14 return !empty(l:dir_list)
15 \ ? findfile('test/script/custom-linting-rules', join(l:dir_list, ','))
19 function! s:GetALEProjectDir(buffer) abort
20 let l:executable = ale_linters#vim#ale_custom_linting_rules#GetExecutable(a:buffer)
22 return ale#path#Dirname(ale#path#Dirname(ale#path#Dirname(l:executable)))
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)
28 return ale#path#Dirname(ale#path#Dirname(ale#path#Dirname(l:executable)))
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'
35 let l:lines = getbufline(a:buffer, 1, '$')
36 call ale#util#Writefile(a:buffer, l:lines, l:temp_file)
38 return '%e ' . ale#Escape(l:temp_dir)
41 function! ale_linters#vim#ale_custom_linting_rules#Handle(buffer, lines) abort
42 let l:dir = s:GetALEProjectDir(a:buffer)
44 let l:pattern = '\v^([a-zA-Z]?:?[^:]+):(\d+) (.+)$'
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'
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',