2017-04-07 10:38:50 -04:00
|
|
|
" Author: Adrian Zalewski <aazalewski@hotmail.com>
|
|
|
|
" Description: Ember-template-lint for checking Handlebars files
|
|
|
|
|
2017-05-27 12:11:03 -04:00
|
|
|
call ale#Set('handlebars_embertemplatelint_executable', 'ember-template-lint')
|
2018-04-09 14:11:20 -04:00
|
|
|
call ale#Set('handlebars_embertemplatelint_use_global', get(g:, 'ale_use_global_executables', 0))
|
2017-04-07 10:38:50 -04:00
|
|
|
|
|
|
|
function! ale_linters#handlebars#embertemplatelint#GetExecutable(buffer) abort
|
2017-05-27 12:11:03 -04:00
|
|
|
return ale#node#FindExecutable(a:buffer, 'handlebars_embertemplatelint', [
|
2017-04-07 10:38:50 -04:00
|
|
|
\ 'node_modules/.bin/ember-template-lint',
|
2017-05-27 12:11:03 -04:00
|
|
|
\])
|
2017-04-07 10:38:50 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! ale_linters#handlebars#embertemplatelint#GetCommand(buffer) abort
|
|
|
|
return ale_linters#handlebars#embertemplatelint#GetExecutable(a:buffer)
|
|
|
|
\ . ' --json %t'
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! ale_linters#handlebars#embertemplatelint#Handle(buffer, lines) abort
|
|
|
|
let l:output = []
|
2017-07-26 19:45:25 -04:00
|
|
|
let l:json = ale#util#FuzzyJSONDecode(a:lines, {})
|
2017-04-07 10:38:50 -04:00
|
|
|
|
2017-07-26 19:45:25 -04:00
|
|
|
for l:error in get(values(l:json), 0, [])
|
2017-05-28 15:19:47 -04:00
|
|
|
if has_key(l:error, 'fatal')
|
|
|
|
call add(l:output, {
|
2017-12-19 12:42:51 -05:00
|
|
|
\ 'lnum': get(l:error, 'line', 1),
|
|
|
|
\ 'col': get(l:error, 'column', 1),
|
2017-05-28 15:19:47 -04:00
|
|
|
\ 'text': l:error.message,
|
|
|
|
\ 'type': l:error.severity == 1 ? 'W' : 'E',
|
|
|
|
\})
|
|
|
|
else
|
|
|
|
call add(l:output, {
|
|
|
|
\ 'lnum': l:error.line,
|
|
|
|
\ 'col': l:error.column,
|
|
|
|
\ 'text': l:error.rule . ': ' . l:error.message,
|
|
|
|
\ 'type': l:error.severity == 1 ? 'W' : 'E',
|
|
|
|
\})
|
|
|
|
endif
|
2017-04-07 10:38:50 -04:00
|
|
|
endfor
|
|
|
|
|
|
|
|
return l:output
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
call ale#linter#Define('handlebars', {
|
|
|
|
\ 'name': 'ember-template-lint',
|
|
|
|
\ 'executable_callback': 'ale_linters#handlebars#embertemplatelint#GetExecutable',
|
|
|
|
\ 'command_callback': 'ale_linters#handlebars#embertemplatelint#GetCommand',
|
|
|
|
\ 'callback': 'ale_linters#handlebars#embertemplatelint#Handle',
|
|
|
|
\})
|