summaryrefslogtreecommitdiff
path: root/ale_linters/elm
diff options
context:
space:
mode:
authorHéctor Ramón Jiménez <hector0193@gmail.com>2018-05-11 19:15:40 +0200
committerHéctor Ramón Jiménez <hector0193@gmail.com>2018-05-11 19:15:40 +0200
commitd40f44793194ca383a72426738f5a411682bb241 (patch)
tree42e661814ee63583d0ab92df4aad4a399cdbfbf9 /ale_linters/elm
parent38c66d33fe8022803497c49239b06112ccbd0a83 (diff)
downloadale-d40f44793194ca383a72426738f5a411682bb241.zip
Upgrade Elm linter to support 0.19 error reports
Diffstat (limited to 'ale_linters/elm')
-rw-r--r--ale_linters/elm/make.vim115
1 files changed, 78 insertions, 37 deletions
diff --git a/ale_linters/elm/make.vim b/ale_linters/elm/make.vim
index a665cef4..a85e55c4 100644
--- a/ale_linters/elm/make.vim
+++ b/ale_linters/elm/make.vim
@@ -1,46 +1,66 @@
" Author: buffalocoder - https://github.com/buffalocoder, soywod - https://github.com/soywod
" Description: Elm linting in Ale. Closely follows the Syntastic checker in https://github.com/ElmCast/elm-vim.
-call ale#Set('elm_make_executable', 'elm-make')
-call ale#Set('elm_make_use_global', get(g:, 'ale_use_global_executables', 0))
+call ale#Set('elm_executable', 'elm')
+call ale#Set('elm_use_global', get(g:, 'ale_use_global_executables', 0))
function! ale_linters#elm#make#GetExecutable(buffer) abort
- return ale#node#FindExecutable(a:buffer, 'elm_make', [
- \ 'node_modules/.bin/elm-make',
+ return ale#node#FindExecutable(a:buffer, 'elm', [
+ \ 'node_modules/.bin/elm',
\])
endfunction
function! ale_linters#elm#make#Handle(buffer, lines) abort
let l:output = []
- let l:is_windows = has('win32')
- let l:temp_dir = l:is_windows ? $TMP : $TMPDIR
let l:unparsed_lines = []
+
for l:line in a:lines
- if l:line[0] is# '['
- let l:errors = json_decode(l:line)
-
- for l:error in l:errors
- " Check if file is from the temp directory.
- " Filters out any errors not related to the buffer.
- if l:is_windows
- let l:file_is_buffer = l:error.file[0:len(l:temp_dir) - 1] is? l:temp_dir
- else
- let l:file_is_buffer = l:error.file[0:len(l:temp_dir) - 1] is# l:temp_dir
- endif
-
- if l:file_is_buffer
- call add(l:output, {
- \ 'lnum': l:error.region.start.line,
- \ 'col': l:error.region.start.column,
- \ 'end_lnum': l:error.region.end.line,
- \ 'end_col': l:error.region.end.column,
- \ 'type': (l:error.type is? 'error') ? 'E' : 'W',
- \ 'text': l:error.overview,
- \ 'detail': l:error.overview . "\n\n" . l:error.details
- \})
- endif
- endfor
- elseif l:line isnot# 'Successfully generated /dev/null'
+ if l:line[0] is# '{'
+ let l:report = json_decode(l:line)
+
+ if l:report.type is? 'error'
+ " General problem
+ let l:details = map(copy(l:report.message), 'ale_linters#elm#make#ParseMessageItem(v:val)')
+
+ call add(l:output, {
+ \ 'lnum': 1,
+ \ 'type': 'E',
+ \ 'text': l:report.title,
+ \ 'detail': join(l:details, '')
+ \})
+ else
+ " Compilation errors
+ for l:error in l:report.errors
+ let l:file_is_buffer = ale_linters#elm#make#FileIsBuffer(l:error.path)
+
+ for l:problem in l:error.problems
+ let l:details = map(copy(l:problem.message), 'ale_linters#elm#make#ParseMessageItem(v:val)')
+
+ if l:file_is_buffer
+ " Buffer module has problems
+ call add(l:output, {
+ \ 'lnum': l:problem.region.start.line,
+ \ 'col': l:problem.region.start.column,
+ \ 'end_lnum': l:problem.region.end.line,
+ \ 'end_col': l:problem.region.end.column,
+ \ 'type': 'E',
+ \ 'text': l:problem.title,
+ \ 'detail': join(l:details, '')
+ \})
+ else
+ " Imported module has problems
+ let l:location = l:error.path .':'. l:problem.region.start.line
+ call add(l:output, {
+ \ 'lnum': 1,
+ \ 'type': 'E',
+ \ 'text': l:location .' - '. l:problem.title,
+ \ 'detail': l:location ." -------\n\n" . join(l:details, '')
+ \})
+ endif
+ endfor
+ endfor
+ endif
+ else
call add(l:unparsed_lines, l:line)
endif
endfor
@@ -57,23 +77,44 @@ function! ale_linters#elm#make#Handle(buffer, lines) abort
return l:output
endfunction
+function! ale_linters#elm#make#FileIsBuffer(path) abort
+ let l:is_windows = has('win32')
+ let l:temp_dir = l:is_windows ? $TMP : $TMPDIR
+
+ if has('win32')
+ return a:path[0:len(l:temp_dir) - 1] is? l:temp_dir
+ else
+ return a:path[0:len(l:temp_dir) - 1] is# l:temp_dir
+ endif
+endfunction
+
+function! ale_linters#elm#make#ParseMessageItem(item) abort
+ if type(a:item) == type('')
+ return a:item
+ else
+ return a:item.string
+ endif
+endfunction
+
" Return the command to execute the linter in the projects directory.
" If it doesn't, then this will fail when imports are needed.
function! ale_linters#elm#make#GetCommand(buffer) abort
- let l:elm_package = ale#path#FindNearestFile(a:buffer, 'elm-package.json')
+ let l:elm_json = ale#path#FindNearestFile(a:buffer, 'elm.json')
let l:elm_exe = ale_linters#elm#make#GetExecutable(a:buffer)
- if empty(l:elm_package)
+
+ if empty(l:elm_json)
let l:dir_set_cmd = ''
else
- let l:root_dir = fnamemodify(l:elm_package, ':p:h')
+ let l:root_dir = fnamemodify(l:elm_json, ':p:h')
let l:dir_set_cmd = 'cd ' . ale#Escape(l:root_dir) . ' && '
endif
- " The elm-make compiler, at the time of this writing, uses '/dev/null' as
+ " The elm compiler, at the time of this writing, uses '/dev/null' as
" a sort of flag to tell the compiler not to generate an output file,
- " which is why this is hard coded here. It does not use NUL on Windows.
- " Source: https://github.com/elm-lang/elm-make/blob/master/src/Flags.hs
+ " which is why this is hard coded here.
+ " Source: https://github.com/elm-lang/elm-compiler/blob/19d5a769b30ec0b2fc4475985abb4cd94cd1d6c3/builder/src/Generate/Output.hs#L253
let l:elm_cmd = ale#Escape(l:elm_exe)
+ \ . ' make'
\ . ' --report=json'
\ . ' --output=/dev/null'