summaryrefslogtreecommitdiff
path: root/ale_linters/handlebars
diff options
context:
space:
mode:
authorAdrian <bardzusny@users.noreply.github.com>2017-04-07 16:38:50 +0200
committerw0rp <w0rp@users.noreply.github.com>2017-04-07 15:38:50 +0100
commitd28d7f732ae5c5017c7e4c2497a744a781e48dab (patch)
tree14039f15233099ed5b178fd75975e2fe20b7d06c /ale_linters/handlebars
parent4caf273d53e7d90e845cb79d0293b1b410f22138 (diff)
downloadale-d28d7f732ae5c5017c7e4c2497a744a781e48dab.zip
Add support for linting Handlebars templates with ember-template-lint (#452)
* Ember-template-lint Handlebars template linter: initial handler, test. * Handlebars support with ember-template-lint: basic documentation entries.
Diffstat (limited to 'ale_linters/handlebars')
-rw-r--r--ale_linters/handlebars/embertemplatelint.vim55
1 files changed, 55 insertions, 0 deletions
diff --git a/ale_linters/handlebars/embertemplatelint.vim b/ale_linters/handlebars/embertemplatelint.vim
new file mode 100644
index 00000000..7a630e19
--- /dev/null
+++ b/ale_linters/handlebars/embertemplatelint.vim
@@ -0,0 +1,55 @@
+" Author: Adrian Zalewski <aazalewski@hotmail.com>
+" Description: Ember-template-lint for checking Handlebars files
+
+let g:ale_handlebars_embertemplatelint_executable =
+\ get(g:, 'ale_handlebars_embertemplatelint_executable', 'ember-template-lint')
+
+let g:ale_handlebars_embertemplatelint_use_global =
+\ get(g:, 'ale_handlebars_embertemplatelint_use_global', 0)
+
+function! ale_linters#handlebars#embertemplatelint#GetExecutable(buffer) abort
+ if g:ale_handlebars_embertemplatelint_use_global
+ return g:ale_handlebars_embertemplatelint_executable
+ endif
+
+ return ale#util#ResolveLocalPath(
+ \ a:buffer,
+ \ 'node_modules/.bin/ember-template-lint',
+ \ g:ale_handlebars_embertemplatelint_executable
+ \)
+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 []
+ end
+
+ 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',
+\})