mirror of
https://github.com/dense-analysis/ale
synced 2024-12-22 06:10:07 +00:00
Allow custom filters for the jq fixer (#1980)
* Allow the jq filters to receive custom filters. * Update documentation.
This commit is contained in:
parent
e5b5ce9f51
commit
b7ec11c93d
@ -1,5 +1,6 @@
|
||||
call ale#Set('json_jq_executable', 'jq')
|
||||
call ale#Set('json_jq_options', '')
|
||||
call ale#Set('json_jq_filters', '.')
|
||||
|
||||
function! ale#fixers#jq#GetExecutable(buffer) abort
|
||||
return ale#Var(a:buffer, 'json_jq_executable')
|
||||
@ -7,9 +8,15 @@ endfunction
|
||||
|
||||
function! ale#fixers#jq#Fix(buffer) abort
|
||||
let l:options = ale#Var(a:buffer, 'json_jq_options')
|
||||
let l:filters = ale#Var(a:buffer, 'json_jq_filters')
|
||||
|
||||
if empty(l:filters)
|
||||
return 0
|
||||
endif
|
||||
|
||||
return {
|
||||
\ 'command': ale#Escape(ale#fixers#jq#GetExecutable(a:buffer))
|
||||
\ . ' . ' . l:options,
|
||||
\ . ' ' . l:filters . ' '
|
||||
\ . l:options,
|
||||
\}
|
||||
endfunction
|
||||
|
@ -73,6 +73,13 @@ g:ale_json_jq_options *g:ale_json_jq_options*
|
||||
|
||||
This option can be changed to pass extra options to `jq`.
|
||||
|
||||
g:ale_json_jq_filters *g:ale_json_jq_filters*
|
||||
*b:ale_json_jq_filters*
|
||||
Type: |String|
|
||||
Default: `'.'`
|
||||
|
||||
This option can be changed to pass custom filters to `jq`.
|
||||
|
||||
|
||||
===============================================================================
|
||||
prettier *ale-json-prettier*
|
||||
|
@ -1,6 +1,7 @@
|
||||
Before:
|
||||
Save g:ale_json_jq_executable
|
||||
Save g:ale_json_jq_options
|
||||
Save g:ale_json_jq_filters
|
||||
|
||||
After:
|
||||
Restore
|
||||
@ -8,7 +9,18 @@ After:
|
||||
Execute(The jq fixer should use the options you set):
|
||||
let g:ale_json_jq_executable = 'foo'
|
||||
let g:ale_json_jq_options = '--bar'
|
||||
let g:ale_json_jq_filters = '.baz'
|
||||
|
||||
AssertEqual
|
||||
\ {'command': ale#Escape('foo') . ' . --bar'},
|
||||
\ {'command': ale#Escape('foo') . ' .baz --bar'},
|
||||
\ ale#fixers#jq#Fix(bufnr(''))
|
||||
|
||||
Execute(The jq fixer should return 0 when there are no filters):
|
||||
let g:ale_json_jq_executable = 'jq'
|
||||
let g:ale_json_jq_options = ''
|
||||
|
||||
let g:ale_json_jq_filters = ''
|
||||
|
||||
AssertEqual
|
||||
\ 0,
|
||||
\ ale#fixers#jq#Fix(bufnr(''))
|
||||
|
Loading…
Reference in New Issue
Block a user