diff options
author | Horacio Sanson <900716+hsanson@users.noreply.github.com> | 2024-03-12 09:51:49 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-12 09:51:49 +0900 |
commit | 8f9197b79b54e01b1f1cb2486ee30124c8e7b4d9 (patch) | |
tree | 8ad408404cad228e3c10a4a17a80ccc2f07ede64 /ale_linters/hurl | |
parent | 5a8287e676e32792fffbde755fdb6551a7ef7153 (diff) | |
download | ale-8f9197b79b54e01b1f1cb2486ee30124c8e7b4d9.zip |
Fix 4740 - add hurlfmt linter (#4741)
* Fix 4740 - add hurlfmt linter
* Fix 4740 - add hurlfmt fixer
* Fix wrong comments
* Add end_col to qflist
* Fix test
Diffstat (limited to 'ale_linters/hurl')
-rw-r--r-- | ale_linters/hurl/hurlfmt.vim | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/ale_linters/hurl/hurlfmt.vim b/ale_linters/hurl/hurlfmt.vim new file mode 100644 index 00000000..fa4252da --- /dev/null +++ b/ale_linters/hurl/hurlfmt.vim @@ -0,0 +1,69 @@ +" Description: Hurl linter using hurlfmt --check. +" https://hurl.dev/ + +call ale#Set('hurl_hurlfmt_executable', 'hurlfmt') + +function! ale_linters#hurl#hurlfmt#GetCommand(buffer) abort + return '%e' + \ . ' --check --no-color ' +endfunction + +function! ale_linters#hurl#hurlfmt#HandleOutput(buffer, lines) abort + " Matches patterns: + " + " error: Parsing space + " --> test.hurl:11:48 + " | + " 8 | header "Content-Type"= "application/json; charset=utf-8" + " | ^ expecting a space + " | + " + " error: Parsing URL + " --> test.hurl:11:48 + " | + " 11 | PUT https://jsonplaceholder.typicode.com/posts/{post_id}} + " | ^ illegal character <{> + " | + " + " Note: hurlfmt seems to report always the first error only so we assume + " there is only one error to make parsing easier. + let l:output = [] + + if empty(a:lines) + return l:output + endif + + let l:pattern = '\v(error|warning): (.+) --\> (.+):(\d+):(\d+) .+ \^ (.+) |' + let l:lines = join(a:lines, ' ') + + for l:match in ale#util#GetMatches(l:lines, l:pattern) + call add(l:output, { + \ 'bufnr': a:buffer, + \ 'lnum': match[4] + 0, + \ 'col': match[5] + 0, + \ 'end_col': match[5] + 0, + \ 'text': match[2] . ' : ' . match[6], + \ 'type': (match[1] is# 'error') ? 'E' : 'W' + \}) + endfor + + return l:output +endfunction + +function! ale_linters#hurl#hurlfmt#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('hurl', { +\ 'name': 'hurlfmt', +\ 'output_stream': 'stderr', +\ 'executable': {b -> ale#Var(b, 'hurl_hurlfmt_executable')}, +\ 'command': function('ale_linters#hurl#hurlfmt#GetCommand'), +\ 'callback': 'ale_linters#hurl#hurlfmt#HandleOutput', +\}) |