mirror of https://github.com/dense-analysis/ale
Fix #823 - Write Windows files with CRLF
This commit is contained in:
parent
747d4fe80b
commit
593cafa18b
|
@ -11,7 +11,8 @@ function! ale_linters#verilog#verilator#GetCommand(buffer) abort
|
|||
|
||||
" Create a special filename, so we can detect it in the handler.
|
||||
call ale#engine#ManageFile(a:buffer, l:filename)
|
||||
call writefile(getbufline(a:buffer, 1, '$'), l:filename)
|
||||
let l:lines = getbufline(a:buffer, 1, '$')
|
||||
call ale#util#Writefile(a:buffer, l:lines, l:filename)
|
||||
|
||||
return 'verilator --lint-only -Wall -Wno-DECLFILENAME '
|
||||
\ . ale#Var(a:buffer, 'verilog_verilator_options') .' '
|
||||
|
|
|
@ -417,7 +417,8 @@ function! s:CreateTemporaryFileForJob(buffer, temporary_file) abort
|
|||
" Automatically delete the directory later.
|
||||
call ale#engine#ManageDirectory(a:buffer, l:temporary_directory)
|
||||
" Write the buffer out to a file.
|
||||
call writefile(getbufline(a:buffer, 1, '$'), a:temporary_file)
|
||||
let l:lines = getbufline(a:buffer, 1, '$')
|
||||
call ale#util#Writefile(a:buffer, l:lines, a:temporary_file)
|
||||
|
||||
return 1
|
||||
endfunction
|
||||
|
|
|
@ -154,7 +154,7 @@ function! s:CreateTemporaryFileForJob(buffer, temporary_file, input) abort
|
|||
" Automatically delete the directory later.
|
||||
call ale#fix#ManageDirectory(a:buffer, l:temporary_directory)
|
||||
" Write the buffer out to a file.
|
||||
call writefile(a:input, a:temporary_file)
|
||||
call ale#util#Writefile(a:buffer, a:input, a:temporary_file)
|
||||
|
||||
return 1
|
||||
endfunction
|
||||
|
|
|
@ -187,3 +187,15 @@ function! ale#util#FuzzyJSONDecode(data, default) abort
|
|||
return a:default
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
" Write a file, including carriage return characters for DOS files.
|
||||
"
|
||||
" The buffer number is required for determining the fileformat setting for
|
||||
" the buffer.
|
||||
function! ale#util#Writefile(buffer, lines, filename) abort
|
||||
let l:corrected_lines = getbufvar(a:buffer, '&fileformat') ==# 'dos'
|
||||
\ ? map(copy(a:lines), 'v:val . "\r"')
|
||||
\ : a:lines
|
||||
|
||||
call writefile(l:corrected_lines, a:filename) " no-custom-checks
|
||||
endfunction
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
Before:
|
||||
call ale#test#SetDirectory('/testplugin/test')
|
||||
|
||||
After:
|
||||
noautocmd :e! ++ff=unix
|
||||
setlocal buftype=nofile
|
||||
|
||||
if filereadable('.newline-test')
|
||||
call delete('.newline-test')
|
||||
endif
|
||||
|
||||
call ale#test#RestoreDirectory()
|
||||
|
||||
Given(A file with Windows line ending characters):
|
||||
first
|
||||
second
|
||||
third
|
||||
|
||||
Execute(Carriage returns should be included for ale#util#Writefile):
|
||||
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", ''],
|
||||
\ readfile('.newline-test', 'b')
|
||||
\
|
||||
Given(A file with Unix line ending characters):
|
||||
first
|
||||
second
|
||||
third
|
||||
|
||||
Execute(Unix file lines should be written as normal):
|
||||
call ale#test#SetFilename('.newline-test')
|
||||
|
||||
setlocal buftype=
|
||||
noautocmd :w
|
||||
noautocmd :e! ++ff=unix
|
||||
|
||||
call ale#util#Writefile(bufnr(''), getline(1, '$'), '.newline-test')
|
||||
|
||||
AssertEqual
|
||||
\ ['first', 'second', 'third', ''],
|
||||
\ readfile('.newline-test', 'b')
|
Loading…
Reference in New Issue