summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ale_linters/twig/cs.vim42
1 files changed, 42 insertions, 0 deletions
diff --git a/ale_linters/twig/cs.vim b/ale_linters/twig/cs.vim
new file mode 100644
index 00000000..da4ec1ae
--- /dev/null
+++ b/ale_linters/twig/cs.vim
@@ -0,0 +1,42 @@
+" Author: cos http://www.netizen.se/
+" Description: Support for Twig CS Check
+
+" See also autoload/ale/fixers/php_cs_fixer.vim for inspiration.
+
+call ale#Set('twig_cs_executable', 'twig_cs_fixer')
+
+function! ale_linters#twig#cs#GetCommand(buffer) abort
+ let l:tmp_dir = fnamemodify(ale#command#CreateDirectory(a:buffer), ':p')
+ let l:out_file = l:tmp_dir . fnamemodify(bufname(a:buffer), ':t:r') . '.o'
+
+" ~/.vim/tools/twig-cs-fixer/vendor/bin/twig-cs-fixer --report=junit check
+"
+ " -gnatc: Check syntax and semantics only (no code generation attempted)
+ return '%e --report=checkstyle check %t'
+endfunction
+
+function! ale_linters#twig#cs#Handle(buffer, lines) abort
+ " <error line="15" column="60" severity="error" message="Expecting 0 whitespace before &quot;|&quot;; found 1." source="TwigCsFixer\Rules\Punctuation\PunctuationSpacingRule"/>
+ let l:re = '\v.*line=."([0-9]*)" column=."([0-9]*)" severity=."([^"]*)" message=."([^"]*)"'
+ let l:output = []
+
+ for l:match in ale#util#GetMatches(a:lines, l:re)
+ echom 'Linenum: ' . l:match[1]
+ call add(l:output, {
+ \ 'bufnr': a:buffer,
+ \ 'lnum': l:match[1],
+ \ 'col': l:match[2],
+ \ 'type': l:match[3] is# 'warning:' ? 'W' : 'E',
+ \ 'text': l:match[4],
+ \})
+ endfor
+
+ return l:output
+endfunction
+
+call ale#linter#Define('twig', {
+\ 'name': 'cs',
+\ 'callback': 'ale_linters#twig#cs#Handle',
+\ 'executable': {b -> ale#Var(b, 'twig_cs_executable')},
+\ 'command': function('ale_linters#twig#cs#GetCommand'),
+\})