summaryrefslogtreecommitdiff
path: root/ale_linters/dart
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2017-07-18 23:57:33 +0100
committerw0rp <devw0rp@gmail.com>2017-07-18 23:57:33 +0100
commit235fc90e226ccc0430b9faa0cd3a226d9be6f31c (patch)
tree173aa89218f03254c5ccb6e80a5ee6139bd21132 /ale_linters/dart
parentaa94d0902a557bc8d65b51a868cf1e122edd2306 (diff)
downloadale-235fc90e226ccc0430b9faa0cd3a226d9be6f31c.zip
Fix #308 - Check Dart files with dartanalyzer
Diffstat (limited to 'ale_linters/dart')
-rw-r--r--ale_linters/dart/dartanalyzer.vim40
1 files changed, 40 insertions, 0 deletions
diff --git a/ale_linters/dart/dartanalyzer.vim b/ale_linters/dart/dartanalyzer.vim
new file mode 100644
index 00000000..8f440571
--- /dev/null
+++ b/ale_linters/dart/dartanalyzer.vim
@@ -0,0 +1,40 @@
+" Author: w0rp <devw0rp@gmail.com>
+" Description: Check Dart files with dartanalyzer
+
+call ale#Set('dart_dartanalyzer_executable', 'dartanalyzer')
+
+function! ale_linters#dart#dartanalyzer#GetExecutable(buffer) abort
+ return ale#Var(a:buffer, 'dart_dartanalyzer_executable')
+endfunction
+
+function! ale_linters#dart#dartanalyzer#GetCommand(buffer) abort
+ let l:executable = ale_linters#dart#dartanalyzer#GetExecutable(a:buffer)
+ let l:path = ale#path#FindNearestFile(a:buffer, '.packages')
+
+ return ale#Escape(l:executable)
+ \ . (!empty(l:path) ? ' --packages ' . ale#Escape(l:path) : '')
+ \ . ' %t'
+endfunction
+
+function! ale_linters#dart#dartanalyzer#Handle(buffer, lines) abort
+ let l:pattern = '\v^ ([a-z]+) . (.+) at (.+):(\d+):(\d+) . (.+)$'
+ let l:output = []
+
+ for l:match in ale#util#GetMatches(a:lines, l:pattern)
+ call add(l:output, {
+ \ 'type': l:match[1] ==# 'error' ? 'E' : 'W',
+ \ 'text': l:match[6] . ': ' . l:match[2],
+ \ 'lnum': str2nr(l:match[4]),
+ \ 'col': str2nr(l:match[5]),
+ \})
+ endfor
+
+ return l:output
+endfunction
+
+call ale#linter#Define('dart', {
+\ 'name': 'dartanalyzer',
+\ 'executable_callback': 'ale_linters#dart#dartanalyzer#GetExecutable',
+\ 'command_callback': 'ale_linters#dart#dartanalyzer#GetCommand',
+\ 'callback': 'ale_linters#dart#dartanalyzer#Handle',
+\})