Fix 3998 - add language option to uncrustify fixer (#4007)

This commit is contained in:
Horacio Sanson 2021-12-25 00:25:47 +09:00 committed by GitHub
parent 5b792c7641
commit dcec4b3c37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 96 additions and 4 deletions

View File

@ -4,6 +4,22 @@
call ale#Set('c_uncrustify_executable', 'uncrustify')
call ale#Set('c_uncrustify_options', '')
let s:languages = {
\ 'c': 'C',
\ 'cpp': 'CPP',
\ 'cs': 'CS',
\ 'objc': 'OC',
\ 'objcpp': 'OC+',
\ 'd': 'D',
\ 'java': 'JAVA',
\ 'vala': 'VALA',
\ 'p': 'PAWN',
\}
function! ale#fixers#uncrustify#Language(buffer) abort
return get(s:languages, &filetype, 'C')
endfunction
function! ale#fixers#uncrustify#Fix(buffer) abort
let l:executable = ale#Var(a:buffer, 'c_uncrustify_executable')
let l:options = ale#Var(a:buffer, 'c_uncrustify_options')
@ -11,6 +27,7 @@ function! ale#fixers#uncrustify#Fix(buffer) abort
return {
\ 'command': ale#Escape(l:executable)
\ . ' --no-backup '
\ . (empty(l:options) ? '' : ' ' . l:options)
\ . '-l' . ale#Pad(ale#fixers#uncrustify#Language(a:buffer))
\ . ale#Pad(l:options)
\}
endfunction

View File

@ -17,7 +17,7 @@ Execute(The clang-format callback should return the correct default values):
AssertEqual
\ {
\ 'command': ale#Escape(g:ale_c_uncrustify_executable)
\ . ' --no-backup'
\ . ' --no-backup -l C'
\ },
\ ale#fixers#uncrustify#Fix(bufnr(''))
@ -28,6 +28,81 @@ Execute(The uncrustify callback should include any additional options):
AssertEqual
\ {
\ 'command': ale#Escape(g:ale_c_uncrustify_executable)
\ . ' --no-backup --some-option',
\ . ' --no-backup -l C --some-option',
\ },
\ ale#fixers#uncrustify#Fix(bufnr(''))
Execute(The uncrustify callback should set proper language):
unlet b:ale_c_uncrustify_options
set filetype=c
AssertEqual
\ {
\ 'command': ale#Escape(g:ale_c_uncrustify_executable)
\ . ' --no-backup -l C',
\ },
\ ale#fixers#uncrustify#Fix(bufnr(''))
set filetype=cpp
AssertEqual
\ {
\ 'command': ale#Escape(g:ale_c_uncrustify_executable)
\ . ' --no-backup -l CPP',
\ },
\ ale#fixers#uncrustify#Fix(bufnr(''))
set filetype=cs
AssertEqual
\ {
\ 'command': ale#Escape(g:ale_c_uncrustify_executable)
\ . ' --no-backup -l CS',
\ },
\ ale#fixers#uncrustify#Fix(bufnr(''))
set filetype=objc
AssertEqual
\ {
\ 'command': ale#Escape(g:ale_c_uncrustify_executable)
\ . ' --no-backup -l OC',
\ },
\ ale#fixers#uncrustify#Fix(bufnr(''))
set filetype=objcpp
AssertEqual
\ {
\ 'command': ale#Escape(g:ale_c_uncrustify_executable)
\ . ' --no-backup -l OC+',
\ },
\ ale#fixers#uncrustify#Fix(bufnr(''))
set filetype=d
AssertEqual
\ {
\ 'command': ale#Escape(g:ale_c_uncrustify_executable)
\ . ' --no-backup -l D',
\ },
\ ale#fixers#uncrustify#Fix(bufnr(''))
set filetype=java
AssertEqual
\ {
\ 'command': ale#Escape(g:ale_c_uncrustify_executable)
\ . ' --no-backup -l JAVA',
\ },
\ ale#fixers#uncrustify#Fix(bufnr(''))
set filetype=vala
AssertEqual
\ {
\ 'command': ale#Escape(g:ale_c_uncrustify_executable)
\ . ' --no-backup -l VALA',
\ },
\ ale#fixers#uncrustify#Fix(bufnr(''))
set filetype=p
AssertEqual
\ {
\ 'command': ale#Escape(g:ale_c_uncrustify_executable)
\ . ' --no-backup -l PAWN',
\ },
\ ale#fixers#uncrustify#Fix(bufnr(''))