Is it possible to have clang-format align variable assignments in columns? For example:
int someInteger = 42; std::string someString = "string"; const unsigned someUnsigned = 42; #define SOME_INTEGER 42 #define SOME_STRING_LITERAL "string" #define SOME_CONSTANT 42 enum Enum { ONE = 1, TWO = 2, THREE = 3, FOUR = 4, FIVE = 5, SIX = 6, SEVEN = 7 };
is more readable than:
int someInteger = 42; const unsigned someUnsigned = 42; std::string someString = "string"; #define SOME_INTEGER 42 #define SOME_STRING_LITERAL "string" #define SOME_CONSTANT 42 enum Enum { ONE = 1, TWO = 2, THREE = 3, FOUR = 4, FIVE = 5, SIX = 6, SEVEN = 7 };
I realize that it may not be practical for clang-format to always do this, but when code as already been manually formatted like said code, it would be nice for clang-format to leave the formatting in place.
clang-format is a tool to automatically format C/C++/Objective-C code, so that developers don't need to worry about style issues during code reviews. It is highly recommended to format your changed C++ code before opening pull requests, which will save you and the reviewers' time.
clang-format supports two ways to provide custom style options: directly specify style configuration in the -style= command line option or use -style=file and put style configuration in the . clang-format or _clang-format file in the project directory.
clang-format file uses YAML format: key1: value1 key2: value2 # A comment. ... The configuration file can consist of several sections each having different Language: parameter denoting the programming language this section of the configuration is targeted at.
clang-tidy is a clang-based C++ “linter” tool. Its purpose is to provide an extensible framework for diagnosing and fixing typical programming errors, like style violations, interface misuse, or bugs that can be deduced via static analysis.
It looks like 3.7 supports something like this (haven't tested yet).
From the docs
AlignConsecutiveAssignments (bool)
If true, aligns consecutive assignments.This will align the assignment operators of consecutive lines. This will result in formattings like code int aaaa = 12; int b = 23; int ccc = 23; endcode
(sic)
Clang-format does not have any option to do this.
If you want to tell clang-format to leave certain lines alone, you can make it do so with // clang-format off
and // clang-format on
comments.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With