2017-04-07 14:38:50 +00:00
|
|
|
" Author: Adrian Zalewski <aazalewski@hotmail.com>
|
|
|
|
" Description: Ember-template-lint for checking Handlebars files
|
|
|
|
|
2017-05-27 16:11:03 +00:00
|
|
|
call ale#Set('handlebars_embertemplatelint_executable', 'ember-template-lint')
|
|
|
|
call ale#Set('handlebars_embertemplatelint_use_global', 0)
|
2017-04-07 14:38:50 +00:00
|
|
|
|
|
|
|
function! ale_linters#handlebars#embertemplatelint#GetExecutable(buffer) abort
|
2017-05-27 16:11:03 +00:00
|
|
|
return ale#node#FindExecutable(a:buffer, 'handlebars_embertemplatelint', [
|
2017-04-07 14:38:50 +00:00
|
|
|
\ 'node_modules/.bin/ember-template-lint',
|
2017-05-27 16:11:03 +00:00
|
|
|
\])
|
2017-04-07 14:38:50 +00: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
|
|
|
|
if len(a:lines) == 0
|
|
|
|
return []
|
2017-04-15 11:52:08 +00:00
|
|
|
endif
|
2017-04-07 14:38:50 +00:00
|
|
|
|
|
|
|
let l:output = []
|
|
|
|
|
|
|
|
let l:input_json = json_decode(join(a:lines, ''))
|
|
|
|
let l:file_errors = values(l:input_json)[0]
|
|
|
|
|
|
|
|
for l:error in l:file_errors
|
|
|
|
call add(l:output, {
|
|
|
|
\ 'bufnr': a:buffer,
|
|
|
|
\ 'lnum': l:error.line,
|
|
|
|
\ 'col': l:error.column,
|
|
|
|
\ 'text': l:error.rule . ': ' . l:error.message,
|
|
|
|
\ 'type': l:error.severity == 1 ? 'W' : 'E',
|
|
|
|
\})
|
|
|
|
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',
|
|
|
|
\})
|