2017-09-10 07:58:42 -04:00
|
|
|
" Author: buffalocoder - https://github.com/buffalocoder, soywod - https://github.com/soywod
|
2016-12-13 04:06:04 -05:00
|
|
|
" Description: Elm linting in Ale. Closely follows the Syntastic checker in https://github.com/ElmCast/elm-vim.
|
|
|
|
|
2017-09-10 07:58:42 -04:00
|
|
|
call ale#Set('elm_make_executable', 'elm-make')
|
2018-04-09 14:11:20 -04:00
|
|
|
call ale#Set('elm_make_use_global', get(g:, 'ale_use_global_executables', 0))
|
2017-09-10 07:58:42 -04:00
|
|
|
|
|
|
|
function! ale_linters#elm#make#GetExecutable(buffer) abort
|
|
|
|
return ale#node#FindExecutable(a:buffer, 'elm_make', [
|
|
|
|
\ 'node_modules/.bin/elm-make',
|
|
|
|
\])
|
|
|
|
endfunction
|
|
|
|
|
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
|
2017-08-08 03:39:13 -04:00
|
|
|
if l:line[0] is# '['
|
2016-12-13 04:06:04 -05:00
|
|
|
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
|
2017-08-08 03:39:13 -04:00
|
|
|
let l:file_is_buffer = l:error.file[0:len(l:temp_dir) - 1] is? l:temp_dir
|
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
|
|
|
else
|
2017-08-08 03:39:13 -04:00
|
|
|
let l:file_is_buffer = l:error.file[0:len(l:temp_dir) - 1] is# l:temp_dir
|
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
|
|
|
|
|
|
|
|
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,
|
2017-08-08 03:39:13 -04:00
|
|
|
\ 'type': (l:error.type is? 'error') ? 'E' : 'W',
|
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
|
|
|
\ '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-08-10 19:31:42 -04:00
|
|
|
elseif l:line isnot# 'Successfully generated /dev/null'
|
2017-06-25 12:12:40 -04:00
|
|
|
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')
|
2017-09-10 07:58:42 -04:00
|
|
|
let l:elm_exe = ale_linters#elm#make#GetExecutable(a:buffer)
|
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,
|
2017-10-06 17:26:50 -04:00
|
|
|
" which is why this is hard coded here. It does not use NUL on Windows.
|
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
|
|
|
" Source: https://github.com/elm-lang/elm-make/blob/master/src/Flags.hs
|
2017-09-10 07:58:42 -04:00
|
|
|
let l:elm_cmd = ale#Escape(l:elm_exe)
|
|
|
|
\ . ' --report=json'
|
2017-10-06 17:26:50 -04:00
|
|
|
\ . ' --output=/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',
|
2017-09-10 07:58:42 -04:00
|
|
|
\ 'executable_callback': 'ale_linters#elm#make#GetExecutable',
|
2016-12-13 04:06:04 -05:00
|
|
|
\ 'output_stream': 'both',
|
|
|
|
\ 'command_callback': 'ale_linters#elm#make#GetCommand',
|
|
|
|
\ 'callback': 'ale_linters#elm#make#Handle'
|
|
|
|
\})
|