summaryrefslogtreecommitdiff
path: root/ale_linters
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2018-08-03 00:42:15 +0100
committerw0rp <devw0rp@gmail.com>2018-08-03 00:42:15 +0100
commit65880fec780b2daa01f62cd8a665ecc8df0c9aca (patch)
tree1c78ee66317b8022f32ae03f7581480d5b1199d2 /ale_linters
parent217284360d35711b751859ed27a7a3c3da300e85 (diff)
downloadale-65880fec780b2daa01f62cd8a665ecc8df0c9aca.zip
Add a linter for checking ALE code itself
Diffstat (limited to 'ale_linters')
-rw-r--r--ale_linters/vim/ale_custom_linting_rules.vim47
1 files changed, 47 insertions, 0 deletions
diff --git a/ale_linters/vim/ale_custom_linting_rules.vim b/ale_linters/vim/ale_custom_linting_rules.vim
new file mode 100644
index 00000000..9981c54f
--- /dev/null
+++ b/ale_linters/vim/ale_custom_linting_rules.vim
@@ -0,0 +1,47 @@
+" Author: w0rp <devw0rp@gmail.com>
+" Description: A linter for checking ALE project code itself.
+
+function! ale_linters#vim#ale_custom_linting_rules#GetExecutable(buffer) abort
+ " Look for the custom-linting-rules script.
+ return ale#path#FindNearestFile(a:buffer, 'test/script/custom-linting-rules')
+endfunction
+
+function! s:GetALEProjectDir(buffer) abort
+ let l:executable = ale_linters#vim#ale_custom_linting_rules#GetExecutable(a:buffer)
+
+ return ale#path#Dirname(ale#path#Dirname(ale#path#Dirname(l:executable)))
+endfunction
+
+function! ale_linters#vim#ale_custom_linting_rules#GetCommand(buffer) abort
+ let l:dir = s:GetALEProjectDir(a:buffer)
+
+ return ale#path#CdString(l:dir) . '%e .'
+endfunction
+
+function! ale_linters#vim#ale_custom_linting_rules#Handle(buffer, lines) abort
+ let l:dir = s:GetALEProjectDir(a:buffer)
+ let l:output = []
+ let l:pattern = '\v^([a-zA-Z]?:?[^:]+):(\d+) (.+)$'
+
+ for l:match in ale#util#GetMatches(a:lines, l:pattern)
+ let l:filename = ale#path#GetAbsPath(l:dir, l:match[1])
+
+ if bufnr(l:filename) is a:buffer
+ call add(l:output, {
+ \ 'lnum': l:match[2],
+ \ 'text': l:match[3],
+ \ 'type': 'W',
+ \})
+ endif
+ endfor
+
+ return l:output
+endfunction
+
+call ale#linter#Define('vim', {
+\ 'name': 'ale_custom_linting_rules',
+\ 'executable_callback': 'ale_linters#vim#ale_custom_linting_rules#GetExecutable',
+\ 'command_callback': 'ale_linters#vim#ale_custom_linting_rules#GetCommand',
+\ 'callback': 'ale_linters#vim#ale_custom_linting_rules#Handle',
+\ 'lint_file': 1,
+\})