mirror of
https://github.com/vale981/apheleia
synced 2025-03-04 17:11:40 -05:00
Add cmake-format formatter (#172)
This commit is contained in:
parent
5cb7156ef5
commit
568862dc84
5 changed files with 218 additions and 1 deletions
|
@ -26,16 +26,18 @@ The format is based on [Keep a Changelog].
|
|||
scripts ([#170])
|
||||
* [`buildifier`](https://github.com/bazelbuild/buildtools)
|
||||
for [Bazel Build](https://bazel.build/) ([#171]).
|
||||
* [`cmake-format`](https://github.com/cheshirekow/cmake_format)
|
||||
for [CMake](https://cmake.org/) ([#172]).
|
||||
|
||||
[#168]: https://github.com/radian-software/apheleia/pull/168
|
||||
[#169]: https://github.com/radian-software/apheleia/pull/169
|
||||
[#170]: https://github.com/radian-software/apheleia/pull/170
|
||||
[#171]: https://github.com/radian-software/apheleia/pull/171
|
||||
[#172]: https://github.com/radian-software/apheleia/pull/172
|
||||
[#174]: https://github.com/radian-software/apheleia/pull/174
|
||||
[#182]: https://github.com/radian-software/apheleia/pull/182
|
||||
[#187]: https://github.com/radian-software/apheleia/pull/187
|
||||
|
||||
|
||||
## 3.2 (released 2023-02-25)
|
||||
### Features
|
||||
* You can use `apheleia-inhibit` as a file-local variable to disable
|
||||
|
|
|
@ -52,6 +52,7 @@
|
|||
(or (buffer-file-name)
|
||||
(apheleia-formatters-mode-extension)
|
||||
".c")))
|
||||
(cmake-format . ("cmake-format" "-"))
|
||||
(crystal-tool-format . ("crystal" "tool" "format" "-"))
|
||||
(dart-format . ("dart" "format"))
|
||||
(elm-format . ("elm-format" "--yes" "--stdin"))
|
||||
|
@ -209,6 +210,8 @@ rather than using this system."
|
|||
(c-ts-mode . clang-format)
|
||||
(c++-mode . clang-format)
|
||||
(caml-mode . ocamlformat)
|
||||
(cmake-mode . cmake-format)
|
||||
(cmake-ts-mode . cmake-format)
|
||||
(common-lisp-mode . lisp-indent)
|
||||
(crystal-mode . crystal-tool-format)
|
||||
(css-mode . prettier-css)
|
||||
|
|
2
test/formatters/installers/cmake-format.bash
Normal file
2
test/formatters/installers/cmake-format.bash
Normal file
|
@ -0,0 +1,2 @@
|
|||
apt-get install -y python3-pip
|
||||
pip3 install cmakelang
|
97
test/formatters/samplecode/cmake-format/in.cmake
Normal file
97
test/formatters/samplecode/cmake-format/in.cmake
Normal file
|
@ -0,0 +1,97 @@
|
|||
# The following multiple newlines should be collapsed into a single newline
|
||||
|
||||
|
||||
|
||||
|
||||
cmake_minimum_required(VERSION 2.8.11)
|
||||
project(cmakelang_test)
|
||||
|
||||
# This multiline-comment should be reflowed
|
||||
# into a single comment
|
||||
# on one line
|
||||
|
||||
# This comment should remain right before the command call.
|
||||
# Furthermore, the command call should be formatted
|
||||
# to a single line.
|
||||
add_subdirectories(foo bar baz
|
||||
foo2 bar2 baz2)
|
||||
|
||||
# This very long command should be wrapped
|
||||
set(HEADERS very_long_header_name_a.h very_long_header_name_b.h very_long_header_name_c.h)
|
||||
|
||||
# This command should be split into one line per entry because it has a long argument list.
|
||||
set(SOURCES source_a.cc source_b.cc source_d.cc source_e.cc source_f.cc source_g.cc source_h.cc)
|
||||
|
||||
# The string in this command should not be split
|
||||
set_target_properties(foo bar baz PROPERTIES COMPILE_FLAGS "-std=c++11 -Wall -Wextra")
|
||||
|
||||
# This command has a very long argument and can't be aligned with the command
|
||||
# end, so it should be moved to a new line with block indent + 1.
|
||||
some_long_command_name("Some very long argument that really needs to be on the next line.")
|
||||
|
||||
# This situation is similar but the argument to a KWARG needs to be on a
|
||||
# newline instead.
|
||||
set(CMAKE_CXX_FLAGS "-std=c++11 -Wall -Wno-sign-compare -Wno-unused-parameter -xx")
|
||||
|
||||
set(HEADERS header_a.h header_b.h # This comment should
|
||||
# be preserved, moreover it should be split
|
||||
# across two lines.
|
||||
header_c.h header_d.h)
|
||||
|
||||
|
||||
# This part of the comment should
|
||||
# be formatted
|
||||
# but...
|
||||
# cmake-format: off
|
||||
# This bunny should remain untouched:
|
||||
# . _ ∩
|
||||
# レヘヽ| |
|
||||
# (・x・)
|
||||
# c( uu}
|
||||
# cmake-format: on
|
||||
# while this part should
|
||||
# be formatted again
|
||||
|
||||
# This is a paragraph
|
||||
#
|
||||
# This is a second paragraph
|
||||
#
|
||||
# This is a third paragraph
|
||||
|
||||
# This is a comment
|
||||
# that should be joined
|
||||
|
||||
if(foo)
|
||||
if(sbar)
|
||||
# This comment is in-scope.
|
||||
add_library(foo_bar_baz foo.cc bar.cc # this is a comment for arg2
|
||||
# this is more comment for arg2, it should be joined with the first.
|
||||
baz.cc) # This comment is part of add_library
|
||||
|
||||
other_command(some_long_argument some_long_argument) # this comment is very long and gets split across some lines
|
||||
|
||||
other_command(some_long_argument some_long_argument some_long_argument) # this comment is even longer and wouldn't make sense to pack at the end of the command so it gets it's own lines
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
||||
# This very long command should be broken up along keyword arguments
|
||||
foo(nonkwarg_a nonkwarg_b HEADERS a.h b.h c.h d.h e.h f.h SOURCES a.cc b.cc d.cc DEPENDS foo bar baz)
|
||||
|
||||
# This command uses a string with escaped quote chars
|
||||
foo(some_arg some_arg "This is a \"string\" within a string")
|
||||
|
||||
# This command uses an empty string
|
||||
foo(some_arg some_arg "")
|
||||
|
||||
# This command uses a multiline string
|
||||
foo(some_arg some_arg "
|
||||
This string is on multiple lines
|
||||
")
|
||||
|
||||
# No, I really want this to look ugly
|
||||
# cmake-format: off
|
||||
add_library(a b.cc
|
||||
c.cc d.cc
|
||||
e.cc)
|
||||
# cmake-format: on
|
113
test/formatters/samplecode/cmake-format/out.cmake
Normal file
113
test/formatters/samplecode/cmake-format/out.cmake
Normal file
|
@ -0,0 +1,113 @@
|
|||
# The following multiple newlines should be collapsed into a single newline
|
||||
|
||||
cmake_minimum_required(VERSION 2.8.11)
|
||||
project(cmakelang_test)
|
||||
|
||||
# This multiline-comment should be reflowed into a single comment on one line
|
||||
|
||||
# This comment should remain right before the command call. Furthermore, the
|
||||
# command call should be formatted to a single line.
|
||||
add_subdirectories(foo bar baz foo2 bar2 baz2)
|
||||
|
||||
# This very long command should be wrapped
|
||||
set(HEADERS very_long_header_name_a.h very_long_header_name_b.h
|
||||
very_long_header_name_c.h)
|
||||
|
||||
# This command should be split into one line per entry because it has a long
|
||||
# argument list.
|
||||
set(SOURCES
|
||||
source_a.cc
|
||||
source_b.cc
|
||||
source_d.cc
|
||||
source_e.cc
|
||||
source_f.cc
|
||||
source_g.cc
|
||||
source_h.cc)
|
||||
|
||||
# The string in this command should not be split
|
||||
set_target_properties(foo bar baz PROPERTIES COMPILE_FLAGS
|
||||
"-std=c++11 -Wall -Wextra")
|
||||
|
||||
# This command has a very long argument and can't be aligned with the command
|
||||
# end, so it should be moved to a new line with block indent + 1.
|
||||
some_long_command_name(
|
||||
"Some very long argument that really needs to be on the next line.")
|
||||
|
||||
# This situation is similar but the argument to a KWARG needs to be on a newline
|
||||
# instead.
|
||||
set(CMAKE_CXX_FLAGS
|
||||
"-std=c++11 -Wall -Wno-sign-compare -Wno-unused-parameter -xx")
|
||||
|
||||
set(HEADERS
|
||||
header_a.h header_b.h # This comment should be preserved, moreover it should
|
||||
# be split across two lines.
|
||||
header_c.h header_d.h)
|
||||
|
||||
# This part of the comment should be formatted but...
|
||||
# cmake-format: off
|
||||
# This bunny should remain untouched:
|
||||
# . _ ∩
|
||||
# レヘヽ| |
|
||||
# (・x・)
|
||||
# c( uu}
|
||||
# cmake-format: on
|
||||
# while this part should be formatted again
|
||||
|
||||
# This is a paragraph
|
||||
#
|
||||
# This is a second paragraph
|
||||
#
|
||||
# This is a third paragraph
|
||||
|
||||
# This is a comment that should be joined
|
||||
|
||||
if(foo)
|
||||
if(sbar)
|
||||
# This comment is in-scope.
|
||||
add_library(
|
||||
foo_bar_baz
|
||||
foo.cc bar.cc # this is a comment for arg2 this is more comment for arg2,
|
||||
# it should be joined with the first.
|
||||
baz.cc) # This comment is part of add_library
|
||||
|
||||
other_command(
|
||||
some_long_argument some_long_argument) # this comment is very long and
|
||||
# gets split across some lines
|
||||
|
||||
other_command(
|
||||
some_long_argument some_long_argument some_long_argument) # this comment
|
||||
# is even longer
|
||||
# and wouldn't
|
||||
# make sense to
|
||||
# pack at the
|
||||
# end of the
|
||||
# command so it
|
||||
# gets it's own
|
||||
# lines
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# This very long command should be broken up along keyword arguments
|
||||
foo(nonkwarg_a nonkwarg_b
|
||||
HEADERS a.h b.h c.h d.h e.h f.h
|
||||
SOURCES a.cc b.cc d.cc
|
||||
DEPENDS foo
|
||||
bar baz)
|
||||
|
||||
# This command uses a string with escaped quote chars
|
||||
foo(some_arg some_arg "This is a \"string\" within a string")
|
||||
|
||||
# This command uses an empty string
|
||||
foo(some_arg some_arg "")
|
||||
|
||||
# This command uses a multiline string
|
||||
foo(some_arg some_arg "
|
||||
This string is on multiple lines
|
||||
")
|
||||
|
||||
# No, I really want this to look ugly
|
||||
# cmake-format: off
|
||||
add_library(a b.cc
|
||||
c.cc d.cc
|
||||
e.cc)
|
||||
# cmake-format: on
|
Loading…
Add table
Reference in a new issue