#1872 Remove extra carriage returns when fixing files on Windows
This commit is contained in:
parent
9d50a06d48
commit
a6c6e24d61
@ -30,7 +30,14 @@ function! ale#fix#ApplyQueuedFixes() abort
|
|||||||
call winrestview(l:save)
|
call winrestview(l:save)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
call setline(1, l:data.output)
|
" If the file is in DOS mode, we have to remove carriage returns from
|
||||||
|
" the ends of lines before calling setline(), or we will see them
|
||||||
|
" twice.
|
||||||
|
let l:lines_to_set = getbufvar(l:buffer, '&fileformat') is# 'dos'
|
||||||
|
\ ? map(copy(l:data.output), 'substitute(v:val, ''\r\+$'', '''', '''')')
|
||||||
|
\ : l:data.output
|
||||||
|
|
||||||
|
call setline(1, l:lines_to_set)
|
||||||
|
|
||||||
if l:data.should_save
|
if l:data.should_save
|
||||||
if empty(&buftype)
|
if empty(&buftype)
|
||||||
|
@ -405,7 +405,7 @@ endfunction
|
|||||||
" the buffer.
|
" the buffer.
|
||||||
function! ale#util#Writefile(buffer, lines, filename) abort
|
function! ale#util#Writefile(buffer, lines, filename) abort
|
||||||
let l:corrected_lines = getbufvar(a:buffer, '&fileformat') is# 'dos'
|
let l:corrected_lines = getbufvar(a:buffer, '&fileformat') is# 'dos'
|
||||||
\ ? map(copy(a:lines), 'v:val . "\r"')
|
\ ? map(copy(a:lines), 'substitute(v:val, ''\r*$'', ''\r'', '''')')
|
||||||
\ : a:lines
|
\ : a:lines
|
||||||
|
|
||||||
call writefile(l:corrected_lines, a:filename) " no-custom-checks
|
call writefile(l:corrected_lines, a:filename) " no-custom-checks
|
||||||
|
@ -28,7 +28,26 @@ Execute(Carriage returns should be included for ale#util#Writefile):
|
|||||||
AssertEqual
|
AssertEqual
|
||||||
\ ["first\r", "second\r", "third\r", ''],
|
\ ["first\r", "second\r", "third\r", ''],
|
||||||
\ readfile('.newline-test', 'b')
|
\ readfile('.newline-test', 'b')
|
||||||
\
|
|
||||||
|
Given(A file with extra carriage returns):
|
||||||
|
first
|
||||||
|
second
|
||||||
|
third
|
||||||
|
fourth
|
||||||
|
|
||||||
|
Execute(Carriage returns should be de-depulicated):
|
||||||
|
call ale#test#SetFilename('.newline-test')
|
||||||
|
|
||||||
|
setlocal buftype=
|
||||||
|
noautocmd :w
|
||||||
|
noautocmd :e! ++ff=dos
|
||||||
|
|
||||||
|
call ale#util#Writefile(bufnr(''), getline(1, '$'), '.newline-test')
|
||||||
|
|
||||||
|
AssertEqual
|
||||||
|
\ ["first\r", "second\r", "third\r", "fourth\r", ''],
|
||||||
|
\ readfile('.newline-test', 'b')
|
||||||
|
|
||||||
Given(A file with Unix line ending characters):
|
Given(A file with Unix line ending characters):
|
||||||
first
|
first
|
||||||
second
|
second
|
||||||
|
Loading…
Reference in New Issue
Block a user