Elm file filter & Windows bug fixes (#223)

* Filters out unrelated errors in Elm linter

The function now filters out errors that are unrelated to the file,
those that were found in imported modules.

It does this by comparing the temp directory environment variable to the
file name in the elm output. If the file begins with the temp directory,
then it sould be included (it's from the buffer).

* Changing output to '/dev/null'

Turns out the compiler only accepts /dev/null as an ignorable name. It's
hard-coded here
https://github.com/elm-lang/elm-make/blob/master/src/Flags.hs

Changing this allows Windows linting to work. Otherwise the compiler
errors when using "nul"

* Fixes for Windows

Should now be able to successfully handle Windows.

Windows seemed to not handle the ";" properly, so I switched it to "&&",
which probably should've been done anyway to prevent false positives.

Oddly, matchend(l:error.file, l:temp_dir), and various other regex
solutions, couldn't properly match the two. Subsetting did though, hence
the new solution.

* Applying corrections

Made the file check case-insensitive for Windows, case-sensitive for
Unix/non-windows.

Added comment explaining hard coding of 'dev/null'

* Spelling correction

* Minor corrections

Actually uses the is_file_buffer variable now, added space between the
if statements, and added space between '-'
This commit is contained in:
Eric Lehner 2016-12-16 05:41:21 -05:00 committed by w0rp
parent 8cb9b2ba4e
commit bda6df61a0
1 changed files with 27 additions and 11 deletions

View File

@ -3,20 +3,32 @@
function! ale_linters#elm#make#Handle(buffer, lines)
let l:output = []
let l:is_windows = has('win32')
let l:temp_dir = l:is_windows ? $TMP : $TMPDIR
for l:line in a:lines
if l:line[0] ==# '['
let l:errors = json_decode(l:line)
for l:error in l:errors
call add(l:output, {
\ 'bufnr': a:buffer,
\ 'lnum': l:error.region.start.line,
\ 'vcol': 0,
\ 'col': l:error.region.start.column,
\ 'type': (l:error.type ==? 'error') ? 'E' : 'W',
\ 'text': l:error.overview,
\ 'nr': -1,
\})
" 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] ==? l:temp_dir
else
let l:file_is_buffer = l:error.file[0:len(l:temp_dir) - 1] ==# l:temp_dir
endif
if l:file_is_buffer
call add(l:output, {
\ 'bufnr': a:buffer,
\ 'lnum': l:error.region.start.line,
\ 'vcol': 0,
\ 'col': l:error.region.start.column,
\ 'type': (l:error.type ==? 'error') ? 'E' : 'W',
\ 'text': l:error.overview,
\ 'nr': -1,
\})
endif
endfor
endif
endfor
@ -32,10 +44,14 @@ function! ale_linters#elm#make#GetCommand(buffer) abort
let l:dir_set_cmd = ''
else
let l:root_dir = fnamemodify(l:elm_package, ':p:h')
let l:dir_set_cmd = 'cd ' . fnameescape(l:root_dir) . '; '
let l:dir_set_cmd = 'cd ' . fnameescape(l:root_dir) . ' && '
endif
let l:elm_cmd = 'elm-make --report=json --output='.shellescape(g:ale#util#nul_file)
" The elm-make 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.
" Source: https://github.com/elm-lang/elm-make/blob/master/src/Flags.hs
let l:elm_cmd = 'elm-make --report=json --output='.shellescape('/dev/null')
let l:stdin_wrapper = g:ale#util#stdin_wrapper . ' .elm'
return l:dir_set_cmd . ' ' . l:stdin_wrapper . ' ' . l:elm_cmd