2016-12-13 04:06:04 -05: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 09:54:57 -05:00
|
|
|
function! ale_linters#elm#make#Handle(buffer, lines) abort
|
2016-12-13 04:06:04 -05: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 05:41:21 -05:00
|
|
|
let l:is_windows = has('win32')
|
|
|
|
let l:temp_dir = l:is_windows ? $TMP : $TMPDIR
|
2017-06-25 12:12:40 -04:00
|
|
|
let l:unparsed_lines = []
|
2016-12-13 04:06:04 -05: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 05:41:21 -05: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, {
|
|
|
|
\ 'lnum': l:error.region.start.line,
|
|
|
|
\ 'col': l:error.region.start.column,
|
2017-06-26 09:37:04 -04:00
|
|
|
\ 'end_lnum': l:error.region.end.line,
|
|
|
|
\ 'end_col': l:error.region.end.column,
|
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 05:41:21 -05:00
|
|
|
\ 'type': (l:error.type ==? 'error') ? 'E' : 'W',
|
|
|
|
\ 'text': l:error.overview,
|
2017-03-02 02:14:30 -05: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 05:41:21 -05:00
|
|
|
\})
|
|
|
|
endif
|
2016-12-13 04:06:04 -05:00
|
|
|
endfor
|
2017-06-25 12:12:40 -04:00
|
|
|
elseif l:line !=# 'Successfully generated /dev/null'
|
|
|
|
call add(l:unparsed_lines, l:line)
|
2016-12-13 04:06:04 -05:00
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
|
2017-06-25 12:12:40 -04:00
|
|
|
if len(l:unparsed_lines) > 0
|
|
|
|
call add(l:output, {
|
|
|
|
\ 'lnum': 1,
|
|
|
|
\ 'type': 'E',
|
|
|
|
\ 'text': l:unparsed_lines[0],
|
|
|
|
\ 'detail': join(l:unparsed_lines, "\n")
|
|
|
|
\})
|
|
|
|
endif
|
|
|
|
|
2016-12-13 04:06:04 -05:00
|
|
|
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
|
2017-04-17 18:29:02 -04:00
|
|
|
let l:elm_package = ale#path#FindNearestFile(a:buffer, 'elm-package.json')
|
2016-12-13 04:06:04 -05:00
|
|
|
if empty(l:elm_package)
|
|
|
|
let l:dir_set_cmd = ''
|
|
|
|
else
|
|
|
|
let l:root_dir = fnamemodify(l:elm_package, ':p:h')
|
2017-05-12 04:20:16 -04:00
|
|
|
let l:dir_set_cmd = 'cd ' . ale#Escape(l:root_dir) . ' && '
|
2016-12-13 04:06:04 -05: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 05:41:21 -05: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
|
2017-05-12 04:20:16 -04:00
|
|
|
let l:elm_cmd = 'elm-make --report=json --output='.ale#Escape('/dev/null')
|
2016-12-13 04:06:04 -05:00
|
|
|
|
2017-02-11 14:40:57 -05:00
|
|
|
return l:dir_set_cmd . ' ' . l:elm_cmd . ' %t'
|
2016-12-13 04:06:04 -05: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'
|
|
|
|
\})
|