add cmake-format fixer support (#2244)

This commit is contained in:
Attila Maczak 2019-01-27 06:45:57 -05:00 committed by w0rp
parent e46c17e8ef
commit d7ced31fe2
6 changed files with 84 additions and 2 deletions

View file

@ -113,7 +113,7 @@ formatting.
| Chef | [foodcritic](http://www.foodcritic.io/) |
| Clojure | [joker](https://github.com/candid82/joker) |
| CloudFormation | [cfn-python-lint](https://github.com/awslabs/cfn-python-lint) |
| CMake | [cmakelint](https://github.com/richq/cmake-lint) |
| CMake | [cmakelint](https://github.com/richq/cmake-lint), [cmake-format](https://github.com/cheshirekow/cmake_format) |
| CoffeeScript | [coffee](http://coffeescript.org/), [coffeelint](https://www.npmjs.com/package/coffeelint) |
| Crystal | [crystal](https://crystal-lang.org/) !! |
| CSS | [csslint](http://csslint.net/), [prettier](https://github.com/prettier/prettier), [stylelint](https://github.com/stylelint/stylelint) |

View file

@ -145,6 +145,11 @@ let s:default_registry = {
\ 'suggested_filetypes': ['c', 'cpp'],
\ 'description': 'Fix C/C++ files with clang-format.',
\ },
\ 'cmakeformat': {
\ 'function': 'ale#fixers#cmakeformat#Fix',
\ 'suggested_filetypes': ['cmake'],
\ 'description': 'Fix CMake files with cmake-format.',
\ },
\ 'gofmt': {
\ 'function': 'ale#fixers#gofmt#Fix',
\ 'suggested_filetypes': ['go'],

View file

@ -0,0 +1,18 @@
" Author: Attila Maczak <attila@maczak.hu>
" Description: Integration of cmakeformat with ALE.
call ale#Set('cmake_cmakeformat_executable', 'cmake-format')
call ale#Set('cmake_cmakeformat_options', '')
function! ale#fixers#cmakeformat#Fix(buffer) abort
let l:executable = ale#Var(a:buffer, 'cmake_cmakeformat_executable')
let l:options = ale#Var(a:buffer, 'cmake_cmakeformat_options')
return {
\ 'command': ale#Escape(l:executable)
\ . ' -i '
\ . (empty(l:options) ? '' : ' ' . l:options)
\ . ' %t',
\ 'read_temporary_file': 1,
\}
endfunction

View file

@ -21,5 +21,23 @@ g:ale_cmake_cmakelint_options *g:ale_cmake_cmakelint_options*
This variable can be set to pass additional options to cmakelint.
===============================================================================
cmake-format *ale-cmake-cmakeformat*
g:ale_cmake_cmakeformat_executable *g:ale_cmake_cmakeformat_executable*
*b:ale_cmake_cmakeformat_executable*
Type: |String|
Default: `'cmakeformat'`
This variable can be set to change the path the cmake-format.
g:ale_cmake_cmakeformat_options *g:ale_cmake_cmakeformat_options*
*b:ale_cmake_cmakeformat_options*
Type: |String|
Default: `''`
This variable can be set to pass additional options to cmake-format.
===============================================================================
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:

View file

@ -54,6 +54,7 @@ CONTENTS *ale-contents*
cfn-python-lint.....................|ale-cloudformation-cfn-python-lint|
cmake.................................|ale-cmake-options|
cmakelint...........................|ale-cmake-cmakelint|
cmake-format........................|ale-cmake-cmakeformat|
cpp...................................|ale-cpp-options|
clang...............................|ale-cpp-clang|
clangd..............................|ale-cpp-clangd|
@ -432,7 +433,7 @@ Notes:
* Chef: `foodcritic`
* Clojure: `joker`
* CloudFormation: `cfn-python-lint`
* CMake: `cmakelint`
* CMake: `cmakelint`, `cmake-format`
* CoffeeScript: `coffee`, `coffeelint`
* Crystal: `crystal`!!
* CSS: `csslint`, `prettier`, `stylelint`

View file

@ -0,0 +1,40 @@
Before:
Save g:ale_cmake_cmakeformat_executable
Save g:ale_cmake_cmakeformat_options
" Use an invalid global executable, so we don't match it.
let g:ale_cmake_cmakeformat_executable = 'xxxinvalid'
let g:ale_cmake_cmakeformat_options = ''
call ale#test#SetDirectory('/testplugin/test/fixers')
After:
Restore
call ale#test#RestoreDirectory()
Execute(The cmakeformat callback should return the correct default values):
call ale#test#SetFilename('../cmake_files/CMakeList.txt')
AssertEqual
\ {
\ 'read_temporary_file': 1,
\ 'command': ale#Escape('xxxinvalid')
\ . ' -i '
\ . ' %t',
\ },
\ ale#fixers#cmakeformat#Fix(bufnr(''))
Execute(The cmakeformat callback should include custom cmakeformat options):
let g:ale_cmake_cmakeformat_options = "-r '(a) -> a'"
call ale#test#SetFilename('../cmake_files/CMakeList.txt')
AssertEqual
\ {
\ 'read_temporary_file': 1,
\ 'command': ale#Escape('xxxinvalid')
\ . ' -i '
\ . ' ' . g:ale_cmake_cmakeformat_options
\ . ' %t',
\ },
\ ale#fixers#cmakeformat#Fix(bufnr(''))