summaryrefslogtreecommitdiff
path: root/ale_linters/elm
diff options
context:
space:
mode:
authorEric Lehner <ericj@buffalo.edu>2016-12-16 05:41:21 -0500
committerw0rp <w0rp@users.noreply.github.com>2016-12-16 10:41:21 +0000
commitbda6df61a08e9582f43dd419b3fc18a15a714c5b (patch)
tree0b8c35aa81293407434ed1f13eff1f2f125c03be /ale_linters/elm
parent8cb9b2ba4eda0144dcdb2045c5d3036231e8faa3 (diff)
downloadale-bda6df61a08e9582f43dd419b3fc18a15a714c5b.zip
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 '-'
Diffstat (limited to 'ale_linters/elm')
-rw-r--r--ale_linters/elm/make.vim38
1 files changed, 27 insertions, 11 deletions
diff --git a/ale_linters/elm/make.vim b/ale_linters/elm/make.vim
index 77277b60..abf4beba 100644
--- a/ale_linters/elm/make.vim
+++ b/ale_linters/elm/make.vim
@@ -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