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')
|
2018-04-09 18:11:20 +00:00
|
|
|
call ale#Set('handlebars_embertemplatelint_use_global', get(g:, 'ale_use_global_executables', 0))
|
2017-04-07 14:38:50 +00:00
|
|
|
|
2020-08-31 08:26:33 +00:00
|
|
|
function! ale_linters#handlebars#embertemplatelint#GetExecutable(buffer) abort
|
|
|
|
return ale#node#FindExecutable(a:buffer, 'handlebars_embertemplatelint', [
|
|
|
|
\ 'node_modules/.bin/ember-template-lint',
|
|
|
|
\])
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! ale_linters#handlebars#embertemplatelint#GetCommand(buffer, version) abort
|
|
|
|
" Reading from stdin was introduced in ember-template-lint@1.6.0
|
|
|
|
return ale#semver#GTE(a:version, [1, 6, 0])
|
|
|
|
\ ? '%e --json --filename %s'
|
|
|
|
\ : '%e --json %t'
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! ale_linters#handlebars#embertemplatelint#GetCommandWithVersionCheck(buffer) abort
|
|
|
|
return ale#semver#RunWithVersionCheck(
|
2020-09-05 18:06:07 +00:00
|
|
|
\ a:buffer,
|
|
|
|
\ ale_linters#handlebars#embertemplatelint#GetExecutable(a:buffer),
|
|
|
|
\ '%e --version',
|
|
|
|
\ function('ale_linters#handlebars#embertemplatelint#GetCommand'),
|
|
|
|
\)
|
2020-08-31 08:26:33 +00:00
|
|
|
endfunction
|
|
|
|
|
2017-04-07 14:38:50 +00:00
|
|
|
function! ale_linters#handlebars#embertemplatelint#Handle(buffer, lines) abort
|
|
|
|
let l:output = []
|
2017-07-26 23:45:25 +00:00
|
|
|
let l:json = ale#util#FuzzyJSONDecode(a:lines, {})
|
2017-04-07 14:38:50 +00:00
|
|
|
|
2017-07-26 23:45:25 +00:00
|
|
|
for l:error in get(values(l:json), 0, [])
|
2017-05-28 19:19:47 +00:00
|
|
|
if has_key(l:error, 'fatal')
|
|
|
|
call add(l:output, {
|
2017-12-19 17:42:51 +00:00
|
|
|
\ 'lnum': get(l:error, 'line', 1),
|
|
|
|
\ 'col': get(l:error, 'column', 1),
|
2017-05-28 19:19:47 +00: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 14:38:50 +00:00
|
|
|
endfor
|
|
|
|
|
|
|
|
return l:output
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
call ale#linter#Define('handlebars', {
|
2020-09-05 18:06:07 +00:00
|
|
|
\ 'name': 'embertemplatelint',
|
|
|
|
\ 'aliases': ['ember-template-lint'],
|
2020-08-31 08:26:33 +00:00
|
|
|
\ 'executable': function('ale_linters#handlebars#embertemplatelint#GetExecutable'),
|
|
|
|
\ 'command': function('ale_linters#handlebars#embertemplatelint#GetCommandWithVersionCheck'),
|
2017-04-07 14:38:50 +00:00
|
|
|
\ 'callback': 'ale_linters#handlebars#embertemplatelint#Handle',
|
|
|
|
\})
|