summaryrefslogtreecommitdiff
path: root/ale_linters
diff options
context:
space:
mode:
authorw0rp <w0rp@users.noreply.github.com>2018-06-20 22:47:56 +0100
committerGitHub <noreply@github.com>2018-06-20 22:47:56 +0100
commit11f303f8532863fb03e21e1b6f77b9ebcf7b0704 (patch)
tree469b21214fd5f530c72cd4b98d98dddf4eef93bb /ale_linters
parent0e1528ec34dbd025712f46a6e556b430c45c8173 (diff)
parentb8be25adb408bffc7af9f2f92c8c5cc7a6813601 (diff)
downloadale-11f303f8532863fb03e21e1b6f77b9ebcf7b0704.zip
Merge pull request #1618 from colbydehart/master
[new linter] Add mix linter for elixir
Diffstat (limited to 'ale_linters')
-rw-r--r--ale_linters/elixir/mix.vim61
1 files changed, 61 insertions, 0 deletions
diff --git a/ale_linters/elixir/mix.vim b/ale_linters/elixir/mix.vim
new file mode 100644
index 00000000..1a95e37f
--- /dev/null
+++ b/ale_linters/elixir/mix.vim
@@ -0,0 +1,61 @@
+" Author: evnu - https://github.com/evnu
+" Author: colbydehart - https://github.com/colbydehart
+" Description: Mix compile checking for Elixir files
+
+function! ale_linters#elixir#mix#Handle(buffer, lines) abort
+ " Matches patterns like the following:
+ "
+ " Error format
+ " ** (CompileError) apps/sim/lib/sim/server.ex:87: undefined function update_in/4
+ "
+ " TODO: Warning format
+ " warning: variable "foobar" does not exist and is being expanded to "foobar()", please use parentheses to remove the ambiguity or change the variable name
+
+ let l:pattern = '\v\(([^\)]+Error)\) ([^:]+):([^:]+): (.+)$'
+ let l:output = []
+
+ for l:match in ale#util#GetMatches(a:lines, l:pattern)
+ let l:type = 'E'
+ let l:text = l:match[4]
+
+ call add(l:output, {
+ \ 'bufnr': a:buffer,
+ \ 'lnum': l:match[3] + 0,
+ \ 'col': 0,
+ \ 'type': l:type,
+ \ 'text': l:text,
+ \})
+ endfor
+
+ return l:output
+endfunction
+
+function! ale_linters#elixir#mix#FindProjectRoot(buffer) abort
+ let l:mix_file = ale#path#FindNearestFile(a:buffer, 'mix.exs')
+ if !empty(l:mix_file)
+ return fnamemodify(l:mix_file, ':p:h')
+ endif
+ return '.'
+endfunction
+
+function! ale_linters#elixir#mix#GetCommand(buffer) abort
+ let l:project_root = ale_linters#elixir#mix#FindProjectRoot(a:buffer)
+
+ let l:temp_dir = ale#engine#CreateDirectory(a:buffer)
+
+ let l:mix_build_path = has('win32')
+ \ ? 'set MIX_BUILD_PATH=' . ale#Escape(l:temp_dir) . ' &&'
+ \ : 'MIX_BUILD_PATH=' . ale#Escape(l:temp_dir)
+
+ return ale#path#CdString(l:project_root)
+ \ . l:mix_build_path
+ \ . ' mix compile %s'
+endfunction
+
+call ale#linter#Define('elixir', {
+\ 'name': 'mix',
+\ 'executable': 'mix',
+\ 'command_callback': 'ale_linters#elixir#mix#GetCommand',
+\ 'callback': 'ale_linters#elixir#mix#Handle',
+\ 'lint_file': 1,
+\})