Add support for xmllint as a fixer.
This commit is contained in:
parent
3c85c7ef65
commit
cc5ad6491f
4 changed files with 86 additions and 0 deletions
|
@ -225,6 +225,11 @@ let s:default_registry = {
|
||||||
\ 'suggested_filetypes': ['dart'],
|
\ 'suggested_filetypes': ['dart'],
|
||||||
\ 'description': 'Fix Dart files with dartfmt.',
|
\ 'description': 'Fix Dart files with dartfmt.',
|
||||||
\ },
|
\ },
|
||||||
|
\ 'xmllint': {
|
||||||
|
\ 'function': 'ale#fixers#xmllint#Fix',
|
||||||
|
\ 'suggested_filetypes': ['xml'],
|
||||||
|
\ 'description': 'Fix XML files with xmllint.',
|
||||||
|
\ },
|
||||||
\}
|
\}
|
||||||
|
|
||||||
" Reset the function registry to the default entries.
|
" Reset the function registry to the default entries.
|
||||||
|
|
27
autoload/ale/fixers/xmllint.vim
Normal file
27
autoload/ale/fixers/xmllint.vim
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
" Author: Cyril Roelandt <tipecaml@gmail.com>
|
||||||
|
" Description: Integration of xmllint with ALE.
|
||||||
|
|
||||||
|
call ale#Set('xml_xmllint_executable', 'xmllint')
|
||||||
|
call ale#Set('xml_xmllint_options', '')
|
||||||
|
call ale#Set('xml_xmllint_indentsize', 2)
|
||||||
|
|
||||||
|
function! ale#fixers#xmllint#Fix(buffer) abort
|
||||||
|
let l:executable = ale#Escape(ale#Var(a:buffer, 'xml_xmllint_executable'))
|
||||||
|
let l:filename = ale#Escape(bufname(a:buffer))
|
||||||
|
let l:command = l:executable . ' --format ' . l:filename
|
||||||
|
|
||||||
|
let l:indent = ale#Var(a:buffer, 'xml_xmllint_indentsize')
|
||||||
|
if l:indent isnot# ''
|
||||||
|
let l:env = ale#Env('XMLLINT_INDENT', repeat(' ', l:indent))
|
||||||
|
let l:command = l:env . l:command
|
||||||
|
endif
|
||||||
|
|
||||||
|
let l:options = ale#Var(a:buffer, 'xml_xmllint_options')
|
||||||
|
if l:options isnot# ''
|
||||||
|
let l:command .= ' ' . l:options
|
||||||
|
endif
|
||||||
|
|
||||||
|
return {
|
||||||
|
\ 'command': l:command
|
||||||
|
\}
|
||||||
|
endfunction
|
|
@ -21,6 +21,14 @@ g:ale_xml_xmllint_options *g:ale_xml_xmllint_options*
|
||||||
This variable can be set to pass additional options to xmllint.
|
This variable can be set to pass additional options to xmllint.
|
||||||
|
|
||||||
|
|
||||||
|
g:ale_xml_xmllint_indentsize *g:ale_xml_xmllint_indentsize*
|
||||||
|
*b:ale_xml_xmllint_indentsize*
|
||||||
|
Type: |Number|
|
||||||
|
Default: 2
|
||||||
|
|
||||||
|
This variable can be sent to specify the amount of spaces used for
|
||||||
|
indentation.
|
||||||
|
|
||||||
===============================================================================
|
===============================================================================
|
||||||
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:
|
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:
|
||||||
|
|
||||||
|
|
46
test/fixers/test_xmllint_fixer_callback.vader
Normal file
46
test/fixers/test_xmllint_fixer_callback.vader
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
Before:
|
||||||
|
Save g:ale_xml_xmllint_executable
|
||||||
|
Save g:ale_xml_xmllint_indentsize
|
||||||
|
Save g:ale_xml_xmllint_options
|
||||||
|
|
||||||
|
let g:ale_xml_xmllint_executable = '/path/to/xmllint'
|
||||||
|
let g:ale_xml_xmllint_indentsize = ''
|
||||||
|
let g:ale_xml_xmllint_options = ''
|
||||||
|
|
||||||
|
call ale#test#SetDirectory('/testplugin/test/fixers')
|
||||||
|
|
||||||
|
After:
|
||||||
|
Restore
|
||||||
|
|
||||||
|
Execute(The xmllint callback should return the correct default command):
|
||||||
|
AssertEqual
|
||||||
|
\ {
|
||||||
|
\ 'command': ale#Escape('/path/to/xmllint')
|
||||||
|
\ . ' --format '
|
||||||
|
\ . ale#Escape(bufname(bufnr('')))
|
||||||
|
\ },
|
||||||
|
\ ale#fixers#xmllint#Fix(bufnr(''))
|
||||||
|
|
||||||
|
Execute(The xmllint callback should include the XMLLINT_INDENT variable):
|
||||||
|
let g:ale_xml_xmllint_indentsize = 2
|
||||||
|
|
||||||
|
AssertEqual
|
||||||
|
\ {
|
||||||
|
\ 'command': ale#Env('XMLLINT_INDENT', ' ')
|
||||||
|
\ . ale#Escape('/path/to/xmllint')
|
||||||
|
\ . ' --format '
|
||||||
|
\ . ale#Escape(bufname(bufnr('')))
|
||||||
|
\ },
|
||||||
|
\ ale#fixers#xmllint#Fix(bufnr(''))
|
||||||
|
|
||||||
|
Execute(The xmllint callback should include additional options):
|
||||||
|
let g:ale_xml_xmllint_options = '--nonet'
|
||||||
|
|
||||||
|
AssertEqual
|
||||||
|
\ {
|
||||||
|
\ 'command': ale#Escape('/path/to/xmllint')
|
||||||
|
\ . ' --format '
|
||||||
|
\ . ale#Escape(bufname(bufnr('')))
|
||||||
|
\ . ' --nonet'
|
||||||
|
\ },
|
||||||
|
\ ale#fixers#xmllint#Fix(bufnr(''))
|
Reference in a new issue