summaryrefslogtreecommitdiff
path: root/ale_linters
diff options
context:
space:
mode:
authorw0rp <w0rp@users.noreply.github.com>2018-11-04 11:33:15 +0000
committerGitHub <noreply@github.com>2018-11-04 11:33:15 +0000
commitacdc99b94daf0f14a8a71d1de5656e9f612a0139 (patch)
tree2701e6e7bdbcb0b03d85f907c4b3c474f26ea0f8 /ale_linters
parent88d328739f73c98794f05fb624edf1cd4b147abe (diff)
parentfa036ca72c94769850c33505e3ab0f5e3343da7f (diff)
downloadale-acdc99b94daf0f14a8a71d1de5656e9f612a0139.zip
Merge pull request #2051 from aclemons/ruumba
Add initial support for ruumba in eruby files.
Diffstat (limited to 'ale_linters')
-rw-r--r--ale_linters/eruby/ruumba.vim62
1 files changed, 62 insertions, 0 deletions
diff --git a/ale_linters/eruby/ruumba.vim b/ale_linters/eruby/ruumba.vim
new file mode 100644
index 00000000..24f112e4
--- /dev/null
+++ b/ale_linters/eruby/ruumba.vim
@@ -0,0 +1,62 @@
+" Author: aclemons - https://github.com/aclemons
+" based on the ale rubocop linter
+" Description: Ruumba, RuboCop linting for ERB templates.
+
+call ale#Set('eruby_ruumba_executable', 'ruumba')
+call ale#Set('eruby_ruumba_options', '')
+
+function! ale_linters#eruby#ruumba#GetCommand(buffer) abort
+ let l:executable = ale#Var(a:buffer, 'eruby_ruumba_executable')
+
+ return ale#handlers#ruby#EscapeExecutable(l:executable, 'ruumba')
+ \ . ' --format json --force-exclusion '
+ \ . ale#Var(a:buffer, 'eruby_ruumba_options')
+ \ . ' --stdin ' . ale#Escape(expand('#' . a:buffer . ':p'))
+endfunction
+
+function! ale_linters#eruby#ruumba#Handle(buffer, lines) abort
+ try
+ let l:errors = json_decode(a:lines[0])
+ catch
+ return []
+ endtry
+
+ if !has_key(l:errors, 'summary')
+ \|| l:errors['summary']['offense_count'] == 0
+ \|| empty(l:errors['files'])
+ return []
+ endif
+
+ let l:output = []
+
+ for l:error in l:errors['files'][0]['offenses']
+ let l:start_col = l:error['location']['column'] + 0
+ call add(l:output, {
+ \ 'lnum': l:error['location']['line'] + 0,
+ \ 'col': l:start_col,
+ \ 'end_col': l:start_col + l:error['location']['length'] - 1,
+ \ 'code': l:error['cop_name'],
+ \ 'text': l:error['message'],
+ \ 'type': ale_linters#eruby#ruumba#GetType(l:error['severity']),
+ \})
+ endfor
+
+ return l:output
+endfunction
+
+function! ale_linters#eruby#ruumba#GetType(severity) abort
+ if a:severity is? 'convention'
+ \|| a:severity is? 'warning'
+ \|| a:severity is? 'refactor'
+ return 'W'
+ endif
+
+ return 'E'
+endfunction
+
+call ale#linter#Define('eruby', {
+\ 'name': 'ruumba',
+\ 'executable_callback': ale#VarFunc('eruby_ruumba_executable'),
+\ 'command_callback': 'ale_linters#eruby#ruumba#GetCommand',
+\ 'callback': 'ale_linters#eruby#ruumba#Handle',
+\})