]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/ale/autoload/ale/handlers/embertemplatelint.vim

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Merge commit '76265755a1add77121c8f9dabb3e9bb70fe9a972' as '.vim/bundle/ale'
[etc/vim.git] / .vim / bundle / ale / autoload / ale / handlers / embertemplatelint.vim
1 " Author: Adrian Zalewski <aazalewski@hotmail.com>
2 " Description: Ember-template-lint for checking Handlebars files
3
4 function! ale#handlers#embertemplatelint#GetExecutable(buffer) abort
5     return ale#path#FindExecutable(a:buffer, 'handlebars_embertemplatelint', [
6     \   'node_modules/.bin/ember-template-lint',
7     \])
8 endfunction
9
10 function! ale#handlers#embertemplatelint#GetCommand(buffer, version) abort
11     if ale#semver#GTE(a:version, [4, 0, 0])
12         " --json was removed in favor of --format=json in ember-template-lint@4.0.0
13         return '%e --format=json --filename %s'
14     endif
15
16     return '%e --json --filename %s'
17 endfunction
18
19 function! ale#handlers#embertemplatelint#GetCommandWithVersionCheck(buffer) abort
20     return ale#semver#RunWithVersionCheck(
21     \   a:buffer,
22     \   ale#handlers#embertemplatelint#GetExecutable(a:buffer),
23     \   '%e --version',
24     \   function('ale#handlers#embertemplatelint#GetCommand'),
25     \)
26 endfunction
27
28 function! ale#handlers#embertemplatelint#Handle(buffer, lines) abort
29     let l:output = []
30     let l:json = ale#util#FuzzyJSONDecode(a:lines, {})
31
32     for l:error in get(values(l:json), 0, [])
33         if has_key(l:error, 'fatal')
34             call add(l:output, {
35             \   'lnum': get(l:error, 'line', 1),
36             \   'col': get(l:error, 'column', 1),
37             \   'text': l:error.message,
38             \   'type': l:error.severity == 1 ? 'W' : 'E',
39             \})
40         else
41             call add(l:output, {
42             \   'lnum': l:error.line,
43             \   'col': l:error.column,
44             \   'text': l:error.rule . ': ' . l:error.message,
45             \   'type': l:error.severity == 1 ? 'W' : 'E',
46             \})
47         endif
48     endfor
49
50     return l:output
51 endfunction
52
53 function! ale#handlers#embertemplatelint#DefineLinter(filetype) abort
54     call ale#Set('handlebars_embertemplatelint_executable', 'ember-template-lint')
55     call ale#Set('handlebars_embertemplatelint_use_global', get(g:, 'ale_use_global_executables', 0))
56
57     call ale#linter#Define(a:filetype, {
58     \   'name': 'embertemplatelint',
59     \   'aliases': ['ember-template-lint'],
60     \   'executable': function('ale#handlers#embertemplatelint#GetExecutable'),
61     \   'command': function('ale#handlers#embertemplatelint#GetCommandWithVersionCheck'),
62     \   'callback': 'ale#handlers#embertemplatelint#Handle',
63     \})
64 endfunction
65
66