-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
10 changed files
with
183 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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', | ||
\}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
call ale#Set('hurl_hurlfmt_executable', 'hurlfmt') | ||
|
||
function! ale#fixers#hurlfmt#GetCommand(buffer) abort | ||
let l:executable = ale#Var(a:buffer, 'hurl_hurlfmt_executable') | ||
|
||
return ale#Escape(l:executable) | ||
\ . ' --out hurl' | ||
endfunction | ||
|
||
function! ale#fixers#hurlfmt#Fix(buffer) abort | ||
return { | ||
\ 'command': ale#fixers#hurlfmt#GetCommand(a:buffer) | ||
\} | ||
endfunction | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
=============================================================================== | ||
ALE Hurl Integration *ale-hurl-options* | ||
|
||
|
||
=============================================================================== | ||
hurlfmt *ale-hurl-hurlfmt* | ||
|
||
g:ale_hurl_hurlfmt_executable *g:ale_hurl_hurlfmt_executable* | ||
*b:ale_hurl_hurlfmt_executable* | ||
Type: |String| | ||
Default: `'hurlfmt'` | ||
|
||
Override the invoked hurlfmt binary. | ||
|
||
|
||
=============================================================================== | ||
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -274,6 +274,8 @@ Notes: | |
* `rustywind` | ||
* `tidy` | ||
* `write-good` | ||
* Hurl | ||
* `hurlfmt` | ||
* Idris | ||
* `idris` | ||
* Ink | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
Before: | ||
Save g:ale_hurl_hurlfmt_executable | ||
|
||
" Use an invalid global executable, so we don't match it. | ||
let g:ale_hurl_hurlfmt_executable = 'xxxinvalid' | ||
|
||
call ale#test#SetDirectory('/testplugin/test/fixers') | ||
|
||
After: | ||
Restore | ||
|
||
call ale#test#RestoreDirectory() | ||
|
||
Execute(The hurlfmt callback should return the correct default values): | ||
call ale#test#SetFilename('../test-files/hurl/dummy.hurl') | ||
|
||
AssertEqual | ||
\ { | ||
\ 'command': ale#Escape(g:ale_hurl_hurlfmt_executable) | ||
\ . ' --out hurl', | ||
\ }, | ||
\ ale#fixers#hurlfmt#Fix(bufnr('')) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
Before: | ||
runtime ale_linters/hurl/hurlfmt.vim | ||
|
||
After: | ||
call ale#linter#Reset() | ||
|
||
Execute(The hurlfmt handler should parse lines correctly): | ||
AssertEqual | ||
\ [ | ||
\ { | ||
\ 'lnum': 11, | ||
\ 'bufnr': 345, | ||
\ 'col': 48, | ||
\ 'end_col': 48, | ||
\ 'text': 'Parsing space : expecting a space ', | ||
\ 'type': 'E', | ||
\ }, | ||
\ ], | ||
\ ale_linters#hurl#hurlfmt#HandleOutput(345, [ | ||
\ 'error: Parsing space', | ||
\ '--> test.hurl:11:48', | ||
\ ' |', | ||
\ '8 " | header "Content-Type"= "application/json; charset=utf-8"', | ||
\ ' | ^ expecting a space', | ||
\ ' |', | ||
\ ]) | ||
|
||
Execute(The rubocop handler should handle empty output): | ||
AssertEqual [], ale_linters#hurl#hurlfmt#HandleOutput(347, []) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Before: | ||
call ale#assert#SetUpLinterTest('hurl', 'hurlfmt') | ||
call ale#test#SetFilename('dummy.hurl') | ||
|
||
let g:ale_ruby_hurlfmt_executable = 'hurlfmt' | ||
let g:ale_ruby_hurlfmt_options = '' | ||
|
||
After: | ||
call ale#assert#TearDownLinterTest() | ||
|
||
Execute(Executable should default to hurlfmt): | ||
AssertLinter 'hurlfmt', ale#Escape('hurlfmt') | ||
\ . ' --check --no-color ' | ||
|
||
Execute(Should be able to set a custom executable): | ||
let g:ale_hurl_hurlfmt_executable = 'bin/hurlfmt' | ||
|
||
AssertLinter 'bin/hurlfmt' , ale#Escape('bin/hurlfmt') | ||
\ . ' --check --no-color ' |