diff options
author | Harrison Bachrach <harrison.bachrach@gmail.com> | 2019-01-27 08:01:42 -0800 |
---|---|---|
committer | w0rp <w0rp@users.noreply.github.com> | 2019-01-27 16:01:42 +0000 |
commit | 17a2f554e3b56411aec3f2ae4d3b0f44656870ef (patch) | |
tree | 04ed65c2015f8d6f74529e1d7bb6c8e5ee0657cb /ale_linters/crystal | |
parent | 08d3523962927d1360b87ac147a29a242c31e7b0 (diff) | |
download | ale-17a2f554e3b56411aec3f2ae4d3b0f44656870ef.zip |
Add initial ameba (crystal linter) support (#2174)
* Add initial ameba (crystal linter) support
Note that this depends on saved file as `ameba` does not have STDIN
support
* Fix formatting of crystal linter documentation
* Add tests for ameba executable customization
Diffstat (limited to 'ale_linters/crystal')
-rw-r--r-- | ale_linters/crystal/ameba.vim | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/ale_linters/crystal/ameba.vim b/ale_linters/crystal/ameba.vim new file mode 100644 index 00000000..d50d9fd3 --- /dev/null +++ b/ale_linters/crystal/ameba.vim @@ -0,0 +1,56 @@ +" Author: Harrison Bachrach - https://github.com/HarrisonB +" Description: Ameba, a linter for crystal files + +call ale#Set('crystal_ameba_executable', 'bin/ameba') + +function! ale_linters#crystal#ameba#GetCommand(buffer) abort + let l:executable = ale#Var(a:buffer, 'crystal_ameba_executable') + + return ale#Escape(l:executable) + \ . ' --format json ' + \ . ale#Escape(expand('#' . a:buffer . ':p')) +endfunction + +call ale#linter#Define('crystal', { +\ 'name': 'ameba', +\ 'executable_callback': ale#VarFunc('crystal_ameba_executable'), +\ 'command_callback': 'ale_linters#crystal#ameba#GetCommand', +\ 'callback': 'ale_linters#crystal#ameba#HandleAmebaOutput', +\}) + +" Handle output from ameba +function! ale_linters#crystal#ameba#HandleAmebaOutput(buffer, lines) abort + if len(a:lines) == 0 + return [] + endif + + let l:errors = ale#util#FuzzyJSONDecode(a:lines[0], {}) + + if !has_key(l:errors, 'summary') + \|| l:errors['summary']['issues_count'] == 0 + \|| empty(l:errors['sources']) + return [] + endif + + let l:output = [] + + for l:error in l:errors['sources'][0]['issues'] + let l:start_col = str2nr(l:error['location']['column']) + let l:end_col = str2nr(l:error['end_location']['column']) + + if !l:end_col + let l:end_col = l:start_col + 1 + endif + + call add(l:output, { + \ 'lnum': str2nr(l:error['location']['line']), + \ 'col': l:start_col, + \ 'end_col': l:end_col, + \ 'code': l:error['rule_name'], + \ 'text': l:error['message'], + \ 'type': 'W', + \}) + endfor + + return l:output +endfunction |