2016-12-13 09:06:04 +00:00
|
|
|
" Author: buffalocoder - https://github.com/buffalocoder
|
|
|
|
" Description: Elm linting in Ale. Closely follows the Syntastic checker in https://github.com/ElmCast/elm-vim.
|
|
|
|
|
2017-01-22 14:54:57 +00:00
|
|
|
function! ale_linters#elm#make#Handle(buffer, lines) abort
|
2016-12-13 09:06:04 +00:00
|
|
|
let l:output = []
|
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 '-'
2016-12-16 10:41:21 +00:00
|
|
|
let l:is_windows = has('win32')
|
|
|
|
let l:temp_dir = l:is_windows ? $TMP : $TMPDIR
|
2016-12-13 09:06:04 +00:00
|
|
|
for l:line in a:lines
|
|
|
|
if l:line[0] ==# '['
|
|
|
|
let l:errors = json_decode(l:line)
|
|
|
|
|
|
|
|
for l:error in l:errors
|
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 '-'
2016-12-16 10:41:21 +00:00
|
|
|
" 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,
|
|
|
|
\ 'col': l:error.region.start.column,
|
|
|
|
\ 'type': (l:error.type ==? 'error') ? 'E' : 'W',
|
|
|
|
\ 'text': l:error.overview,
|
2017-03-02 07:14:30 +00:00
|
|
|
\ 'detail': l:error.overview . "\n\n" . l:error.details
|
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 '-'
2016-12-16 10:41:21 +00:00
|
|
|
\})
|
|
|
|
endif
|
2016-12-13 09:06:04 +00:00
|
|
|
endfor
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
|
|
|
|
return l:output
|
|
|
|
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#util#FindNearestFile(a:buffer, 'elm-package.json')
|
|
|
|
if empty(l:elm_package)
|
|
|
|
let l:dir_set_cmd = ''
|
|
|
|
else
|
|
|
|
let l:root_dir = fnamemodify(l:elm_package, ':p:h')
|
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 '-'
2016-12-16 10:41:21 +00:00
|
|
|
let l:dir_set_cmd = 'cd ' . fnameescape(l:root_dir) . ' && '
|
2016-12-13 09:06:04 +00:00
|
|
|
endif
|
|
|
|
|
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 '-'
2016-12-16 10:41:21 +00:00
|
|
|
" 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')
|
2016-12-13 09:06:04 +00:00
|
|
|
|
2017-02-11 19:40:57 +00:00
|
|
|
return l:dir_set_cmd . ' ' . l:elm_cmd . ' %t'
|
2016-12-13 09:06:04 +00:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
call ale#linter#Define('elm', {
|
|
|
|
\ 'name': 'make',
|
|
|
|
\ 'executable': 'elm-make',
|
|
|
|
\ 'output_stream': 'both',
|
|
|
|
\ 'command_callback': 'ale_linters#elm#make#GetCommand',
|
|
|
|
\ 'callback': 'ale_linters#elm#make#Handle'
|
|
|
|
\})
|