summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md2
-rw-r--r--autoload/ale/fix/registry.vim5
-rw-r--r--autoload/ale/fixers/cmakeformat.vim18
-rw-r--r--doc/ale-cmake.txt18
-rw-r--r--doc/ale.txt3
-rw-r--r--test/fixers/test_cmakeformat_fixer_callback.vader40
6 files changed, 84 insertions, 2 deletions
diff --git a/README.md b/README.md
index 62c6d68f..bdff1112 100644
--- a/README.md
+++ b/README.md
@@ -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) |
diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim
index 98a35b7e..90450b34 100644
--- a/autoload/ale/fix/registry.vim
+++ b/autoload/ale/fix/registry.vim
@@ -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'],
diff --git a/autoload/ale/fixers/cmakeformat.vim b/autoload/ale/fixers/cmakeformat.vim
new file mode 100644
index 00000000..f40ed6ed
--- /dev/null
+++ b/autoload/ale/fixers/cmakeformat.vim
@@ -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
diff --git a/doc/ale-cmake.txt b/doc/ale-cmake.txt
index fb46336f..602637b1 100644
--- a/doc/ale-cmake.txt
+++ b/doc/ale-cmake.txt
@@ -22,4 +22,22 @@ g:ale_cmake_cmakelint_options *g:ale_cmake_cmakelint_options*
===============================================================================
+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:
diff --git a/doc/ale.txt b/doc/ale.txt
index 9b91d3a0..c8ec6652 100644
--- a/doc/ale.txt
+++ b/doc/ale.txt
@@ -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`
diff --git a/test/fixers/test_cmakeformat_fixer_callback.vader b/test/fixers/test_cmakeformat_fixer_callback.vader
new file mode 100644
index 00000000..9263d6fa
--- /dev/null
+++ b/test/fixers/test_cmakeformat_fixer_callback.vader
@@ -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(''))