Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell clang-format to keep whitespace between binary operators as they are

Is it possible to instruct clang-format not to change

z = sqrt(x*x + y*y);

into

z = sqrt(x * x + y * y);

That is, to leave whitespaces between binary operators up to the programmer.

like image 857
Lukas Avatar asked May 30 '17 10:05

Lukas


People also ask

What is clang tidy?

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.

How do I change my clang format?

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.

Where does clang format look for clang format?

Standalone Tool. clang-format is located in clang/tools/clang-format and can be used to format C/C++/Java/JavaScript/JSON/Objective-C/Protobuf/C# code.

How do you use clang format?

You can install clang-format and git-clang-format via npm install -g clang-format . To automatically format a file according to Electron C++ code style, run clang-format -i path/to/electron/file.cc . It should work on macOS/Linux/Windows.


1 Answers

Unfortunately, clang-format does not directly support this feature (most recent release is clang 7 but this might change in the future). The closest feature it currently supports is to not insert spaces before the assignment operator [SpaceBeforeAssignmentOperators]. Based on that, I believe that it might not be too complicated to extend clang-format to support other binary operators as well but I am not familiar with the clang-format code base so I might as well be wrong.

like image 75
Stefan Ivanov Avatar answered Nov 15 '22 00:11

Stefan Ivanov