I'd like to know if clang-format could be setup to reduce non-compound_statement
into { non-compound_statement; }
in iteration_statement
.
statement
: labeled_statement
| compound_statement
| expression_statement
| selection_statement
| iteration_statement
| jump_statement
;
iteration_statement
: WHILE '(' expression ')' statement
| DO statement WHILE '(' expression ')' ';'
| FOR '(' expression_statement expression_statement ')' statement
| FOR '(' expression_statement expression_statement expression ')' statement
;
Example
Input:
if (exp) foo = 1;
Output:
if (exp) { foo = 1; }
Then the beautifier would indent as needed.
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.
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.
Short answer: YES. The clang-format tool has a -sort-includes option. Changing the order of #include directives can definitely change the behavior of existing code, and may break existing code.
What you want to do is outside of the scope of what clang-format tries to achieve:
- The only lexical elements clang-format should touch are: whitespaces, string-literals and comments. Any other changes ranging from ordering includes to removing superfluous paranthesis are not in the scope of this tool.
Source: http://clang-developers.42468.n3.nabble.com/Design-clang-format-td3980439.html
However clang tidy can, the feature flag is called readability-braces-around-statements
.
Source: http://clang.llvm.org/extra/clang-tidy/checks/readability-braces-around-statements.html
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