feat(template-lint): Read from stdin (#2622)
* ember-template-lint: Lint from stdin * This feature has recently been implemented in ember-template-lint. * Refactor ember-template-lint executable * Fallback on a temporary file for old template-lint Co-authored-by: w0rp <w0rp@users.noreply.github.com>
This commit is contained in:
parent
ac2100d410
commit
d4a14746cd
4 changed files with 46 additions and 4 deletions
|
@ -4,6 +4,28 @@
|
||||||
call ale#Set('handlebars_embertemplatelint_executable', 'ember-template-lint')
|
call ale#Set('handlebars_embertemplatelint_executable', 'ember-template-lint')
|
||||||
call ale#Set('handlebars_embertemplatelint_use_global', get(g:, 'ale_use_global_executables', 0))
|
call ale#Set('handlebars_embertemplatelint_use_global', get(g:, 'ale_use_global_executables', 0))
|
||||||
|
|
||||||
|
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(
|
||||||
|
\ a:buffer,
|
||||||
|
\ ale_linters#handlebars#embertemplatelint#GetExecutable(a:buffer),
|
||||||
|
\ '%e --version',
|
||||||
|
\ function('ale_linters#handlebars#embertemplatelint#GetCommand'),
|
||||||
|
\ )
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! ale_linters#handlebars#embertemplatelint#Handle(buffer, lines) abort
|
function! ale_linters#handlebars#embertemplatelint#Handle(buffer, lines) abort
|
||||||
let l:output = []
|
let l:output = []
|
||||||
let l:json = ale#util#FuzzyJSONDecode(a:lines, {})
|
let l:json = ale#util#FuzzyJSONDecode(a:lines, {})
|
||||||
|
@ -31,9 +53,7 @@ endfunction
|
||||||
|
|
||||||
call ale#linter#Define('handlebars', {
|
call ale#linter#Define('handlebars', {
|
||||||
\ 'name': 'ember-template-lint',
|
\ 'name': 'ember-template-lint',
|
||||||
\ 'executable': {b -> ale#node#FindExecutable(b, 'handlebars_embertemplatelint', [
|
\ 'executable': function('ale_linters#handlebars#embertemplatelint#GetExecutable'),
|
||||||
\ 'node_modules/.bin/ember-template-lint',
|
\ 'command': function('ale_linters#handlebars#embertemplatelint#GetCommandWithVersionCheck'),
|
||||||
\ ])},
|
|
||||||
\ 'command': '%e --json %t',
|
|
||||||
\ 'callback': 'ale_linters#handlebars#embertemplatelint#Handle',
|
\ 'callback': 'ale_linters#handlebars#embertemplatelint#Handle',
|
||||||
\})
|
\})
|
||||||
|
|
0
test/ember-template-lint-test-files/app/template.hbs
Normal file
0
test/ember-template-lint-test-files/app/template.hbs
Normal file
0
test/ember-template-lint-test-files/package.json
Normal file
0
test/ember-template-lint-test-files/package.json
Normal file
22
test/test_embertemplatelint_executable_detection.vader
Normal file
22
test/test_embertemplatelint_executable_detection.vader
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
Before:
|
||||||
|
call ale#test#SetDirectory('/testplugin/test')
|
||||||
|
|
||||||
|
runtime ale_linters/handlebars/embertemplatelint.vim
|
||||||
|
|
||||||
|
After:
|
||||||
|
call ale#test#RestoreDirectory()
|
||||||
|
call ale#linter#Reset()
|
||||||
|
|
||||||
|
Execute(ember-template-lint executables runs the right command):
|
||||||
|
call ale#test#SetFilename('ember-template-lint-test-files/app/template.hbs')
|
||||||
|
|
||||||
|
AssertEqual
|
||||||
|
\ ale_linters#handlebars#embertemplatelint#GetCommand(bufnr(''), [2, 0, 0]),
|
||||||
|
\ '%e --json --filename %s'
|
||||||
|
|
||||||
|
Execute(old ember-template-lint executables runs the right command):
|
||||||
|
call ale#test#SetFilename('ember-template-lint-test-files/app/template.hbs')
|
||||||
|
|
||||||
|
AssertEqual
|
||||||
|
\ ale_linters#handlebars#embertemplatelint#GetCommand(bufnr(''), [1, 5, 0]),
|
||||||
|
\ '%e --json %t'
|
Reference in a new issue