mirror of
https://github.com/dense-analysis/ale.git
synced 2025-12-07 05:04:28 +08:00
xmllint fixer must read from stdin - not buffer filename (#4884)
The current xmllint fixer reads and formats the file that a buffer is associated with from disk instead of accepting input from stdin. This has the side effect that if the filename is changed in the buffer, but not saved yet, the fixer discards all the pending changes and replaces the buffer contents with the formatted text from the file contents on disk.
This commit is contained in:
@@ -7,15 +7,8 @@ call ale#Set('xml_xmllint_indentsize', 2)
|
|||||||
|
|
||||||
function! ale#fixers#xmllint#Fix(buffer) abort
|
function! ale#fixers#xmllint#Fix(buffer) abort
|
||||||
let l:executable = ale#Escape(ale#Var(a:buffer, 'xml_xmllint_executable'))
|
let l:executable = ale#Escape(ale#Var(a:buffer, 'xml_xmllint_executable'))
|
||||||
let l:filename = bufname(a:buffer)
|
|
||||||
|
|
||||||
if empty(l:filename)
|
let l:command = l:executable . ' --format'
|
||||||
let l:filename = '%t'
|
|
||||||
else
|
|
||||||
let l:filename = ale#Escape(l:filename)
|
|
||||||
endif
|
|
||||||
|
|
||||||
let l:command = l:executable . ' --format ' . l:filename
|
|
||||||
|
|
||||||
let l:indent = ale#Var(a:buffer, 'xml_xmllint_indentsize')
|
let l:indent = ale#Var(a:buffer, 'xml_xmllint_indentsize')
|
||||||
|
|
||||||
@@ -31,6 +24,6 @@ function! ale#fixers#xmllint#Fix(buffer) abort
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
return {
|
return {
|
||||||
\ 'command': l:command
|
\ 'command': l:command . ' -'
|
||||||
\}
|
\}
|
||||||
endfunction
|
endfunction
|
||||||
|
|||||||
@@ -18,39 +18,39 @@ Execute(The xmllint callback should return the correct default command with unpe
|
|||||||
AssertEqual
|
AssertEqual
|
||||||
\ {
|
\ {
|
||||||
\ 'command': ale#Escape('/path/to/xmllint')
|
\ 'command': ale#Escape('/path/to/xmllint')
|
||||||
\ . ' --format %t'
|
\ . ' --format -'
|
||||||
\ },
|
\ },
|
||||||
\ ale#fixers#xmllint#Fix(bufnr(''))
|
\ ale#fixers#xmllint#Fix(bufnr(''))
|
||||||
|
|
||||||
Execute(The xmllint callback should return the correct default command):
|
Execute(The xmllint callback should return the correct default command):
|
||||||
|
call ale#test#SetFilename('../test-files/xml/dummy.xml')
|
||||||
|
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ {
|
\ {
|
||||||
\ 'command': ale#Escape('/path/to/xmllint')
|
\ 'command': ale#Escape('/path/to/xmllint')
|
||||||
\ . ' --format '
|
\ . ' --format -'
|
||||||
\ . ale#Escape(bufname(bufnr('')))
|
|
||||||
\ },
|
\ },
|
||||||
\ ale#fixers#xmllint#Fix(bufnr(''))
|
\ ale#fixers#xmllint#Fix(bufnr(''))
|
||||||
|
|
||||||
Execute(The xmllint callback should include the XMLLINT_INDENT variable):
|
Execute(The xmllint callback should include the XMLLINT_INDENT variable):
|
||||||
|
call ale#test#SetFilename('../test-files/xml/dummy.xml')
|
||||||
let g:ale_xml_xmllint_indentsize = 2
|
let g:ale_xml_xmllint_indentsize = 2
|
||||||
|
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ {
|
\ {
|
||||||
\ 'command': ale#Env('XMLLINT_INDENT', ' ')
|
\ 'command': ale#Env('XMLLINT_INDENT', ' ')
|
||||||
\ . ale#Escape('/path/to/xmllint')
|
\ . ale#Escape('/path/to/xmllint')
|
||||||
\ . ' --format '
|
\ . ' --format -'
|
||||||
\ . ale#Escape(bufname(bufnr('')))
|
|
||||||
\ },
|
\ },
|
||||||
\ ale#fixers#xmllint#Fix(bufnr(''))
|
\ ale#fixers#xmllint#Fix(bufnr(''))
|
||||||
|
|
||||||
Execute(The xmllint callback should include additional options):
|
Execute(The xmllint callback should include additional options):
|
||||||
let g:ale_xml_xmllint_options = '--nonet'
|
call ale#test#SetFilename('../test-files/xml/dummy.xml')
|
||||||
|
let g:ale_xml_xmllint_options = '--nonet --custom-opt 2'
|
||||||
|
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ {
|
\ {
|
||||||
\ 'command': ale#Escape('/path/to/xmllint')
|
\ 'command': ale#Escape('/path/to/xmllint')
|
||||||
\ . ' --format '
|
\ . ' --format --nonet --custom-opt 2 -'
|
||||||
\ . ale#Escape(bufname(bufnr('')))
|
|
||||||
\ . ' --nonet'
|
|
||||||
\ },
|
\ },
|
||||||
\ ale#fixers#xmllint#Fix(bufnr(''))
|
\ ale#fixers#xmllint#Fix(bufnr(''))
|
||||||
|
|||||||
4
test/test-files/xml/dummy.xml
Normal file
4
test/test-files/xml/dummy.xml
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<xml>
|
||||||
|
<test id="12"/>
|
||||||
|
</xml>
|
||||||
Reference in New Issue
Block a user