-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add clang-format fixer for C/C++ (#873)
* Add clang-format fixer for C/C++ * Document clang-format options * Refer ale-cpp-clangformat to ale-c-clangformat
- Loading branch information
Showing
8 changed files
with
94 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
" Author: Peter Renström <[email protected]> | ||
" Description: Fixing C/C++ files with clang-format. | ||
|
||
call ale#Set('c_clangformat_executable', 'clang-format') | ||
call ale#Set('c_clangformat_use_global', 0) | ||
call ale#Set('c_clangformat_options', '') | ||
|
||
function! ale#fixers#clangformat#GetExecutable(buffer) abort | ||
return ale#node#FindExecutable(a:buffer, 'c_clangformat', [ | ||
\ 'clang-format', | ||
\]) | ||
endfunction | ||
|
||
function! ale#fixers#clangformat#Fix(buffer) abort | ||
let l:options = ale#Var(a:buffer, 'c_clangformat_options') | ||
|
||
return { | ||
\ 'command': ale#Escape(ale#fixers#clangformat#GetExecutable(a:buffer)) | ||
\ . ' ' . l:options, | ||
\} | ||
endfunction |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
Before: | ||
Save g:ale_c_clangformat_executable | ||
|
||
" Use an invalid global executable, so we don't match it. | ||
let g:ale_c_clangformat_executable = 'xxxinvalid' | ||
|
||
call ale#test#SetDirectory('/testplugin/test/fixers') | ||
silent cd .. | ||
silent cd command_callback | ||
let g:dir = getcwd() | ||
|
||
After: | ||
Restore | ||
|
||
call ale#test#RestoreDirectory() | ||
|
||
Execute(The clang-format callback should return the correct default values): | ||
call ale#test#SetFilename('c_paths/dummy.c') | ||
|
||
AssertEqual | ||
\ { | ||
\ 'command': ale#Escape(g:ale_c_clangformat_executable) | ||
\ . ' ' | ||
\ }, | ||
\ ale#fixers#clangformat#Fix(bufnr('')) | ||
|
||
Execute(The clangformat callback should include any additional options): | ||
call ale#test#SetFilename('c_paths/dummy.c') | ||
let g:ale_c_clangformat_options = '--some-option' | ||
|
||
AssertEqual | ||
\ { | ||
\ 'command': ale#Escape(g:ale_c_clangformat_executable) | ||
\ . ' --some-option', | ||
\ }, | ||
\ ale#fixers#clangformat#Fix(bufnr('')) |