clang-format

How to call clang-format over a cpp project folder?

流过昼夜 提交于 2019-12-04 07:35:03
问题 Is there a way to call something like clang-format --style=Webkit for an entire cpp project folder, rather than running it separately for each file? I am using clang-format.py and vim to do this, but I assume there is a way to apply this once. 回答1: What about: clang-format -i -style=WebKit *.cpp *.h in the project folder. The -i option makes it inplace (by default formatted output is written to stdout). 回答2: Unfortunately, there is no way to apply clang-format recursively. *.cpp will only

Why are my Xcode plugins (such as clang format) installed with Alcatraz no longer working after updating to new version of Xcode?

本小妞迷上赌 提交于 2019-12-04 07:23:17
问题 Today I updated to Xcode 6.3.2 and I can't run the Clang code formatting – it seems like it's not even installed. Everytime I update Xcode, I have to reinstall Alcatraz and most of the packages (why btw?) to make them work on the new version of Xcode. This time I reinstalled all packages (like VVDocumenter, Color picker, etc), but the ClangFormat doesn't work – it doesn't even appear in the "Edit" menu. Any idea why? btw. I tried to restart Xcode as well as the Mac itself :) EDIT (Solution):

clang-format: Align asterisk (*) of pointer declaration with variable name

女生的网名这么多〃 提交于 2019-12-03 12:18:40
问题 I am using the following options in my .clang-format file: AlignConsecutiveDeclarations: true PointerAlignment: Right The current formatting result is the following: char * var1; SomeOtherType *var2; int var3; The result I was expecting would be: char *var1; //note the changed position of * SomeOtherType *var2; int var3; How can I configure clang-format to align the asterix (*) with the variable name rather then with the type when I am using the AlignConsecutiveDeclarations option? 回答1:

Can clang format add braces to single line if statements etc

被刻印的时光 ゝ 提交于 2019-12-03 06:28:31
问题 Is there an option for clang-format to add braces to all if()/do/while statements etc? eg if( i == 42 ) std::cout << "You found the meaning of life\n"; else std::cout << "Wrong!\n"; to if( i == 42 ) { std::cout << "You found the meaning of life\n"; } else { std::cout << "Wrong!\n"; } Using $ clang-format --version clang-format version 3.6.0 回答1: clang-tidy can make syntactic changes to your code using FIXITS clang-tidy YOUR_FILE.cpp -fix -checks="readability-braces-around-statements" --

clang-format: Align asterisk (*) of pointer declaration with variable name

时光毁灭记忆、已成空白 提交于 2019-12-03 02:39:23
I am using the following options in my .clang-format file: AlignConsecutiveDeclarations: true PointerAlignment: Right The current formatting result is the following: char * var1; SomeOtherType *var2; int var3; The result I was expecting would be: char *var1; //note the changed position of * SomeOtherType *var2; int var3; How can I configure clang-format to align the asterix (*) with the variable name rather then with the type when I am using the AlignConsecutiveDeclarations option? PointerAlignment: Right is unfortunately not implemented yet. See https://github.com/llvm-mirror/clang/blob

Can clang format add braces to single line if statements etc

五迷三道 提交于 2019-12-02 19:59:28
Is there an option for clang-format to add braces to all if()/do/while statements etc? eg if( i == 42 ) std::cout << "You found the meaning of life\n"; else std::cout << "Wrong!\n"; to if( i == 42 ) { std::cout << "You found the meaning of life\n"; } else { std::cout << "Wrong!\n"; } Using $ clang-format --version clang-format version 3.6.0 clang-tidy can make syntactic changes to your code using FIXITS clang-tidy YOUR_FILE.cpp -fix -checks="readability-braces-around-statements" -- COMPILE_OPTIONS Updated: clang-tidy is a bit of a heavyweight tool for this as it needs compile options to parse

Why are my Xcode plugins (such as clang format) installed with Alcatraz no longer working after updating to new version of Xcode?

匆匆过客 提交于 2019-12-02 13:54:28
Today I updated to Xcode 6.3.2 and I can't run the Clang code formatting – it seems like it's not even installed. Everytime I update Xcode, I have to reinstall Alcatraz and most of the packages (why btw?) to make them work on the new version of Xcode. This time I reinstalled all packages (like VVDocumenter, Color picker, etc), but the ClangFormat doesn't work – it doesn't even appear in the "Edit" menu. Any idea why? btw. I tried to restart Xcode as well as the Mac itself :) EDIT (Solution): Solution for Xcode 6.3.x (If this does not work, use the general solution below.) In terminal, enter

clang-format removes new lines in array definition with designators

╄→гoц情女王★ 提交于 2019-12-02 00:04:41
I like to define my array values with a designator, when possible: enum Mode { NONE, SPLIT_FILES, SINGLE_FILE, INVALID }; const std::string ModeName[] = { [NONE] = "NONE", [SPLIT_FILES] = "SPLIT_FILES", [SINGLE_FILE] = "SINGLE_FILE", [INVALID] = "INVALID" }; Running this through clang-format (3.5) mangles the new lines and makes it less readable: enum RecorderMode { REC_NONE, REC_SPLIT_FILES, REC_SINGLE_FILE, REC_INVALID }; const std::string RecorderModeName[] = {[REC_NONE] = "NONE", [REC_SPLIT_FILES] = "SPLIT_FILES", [REC_SINGLE_FILE] = "SINGLE_FILE", [REC_INVALID] = "INVALID" }; The array

clang-format stack all if-statement arguments if they are too long

隐身守侯 提交于 2019-12-01 22:39:02
问题 I have an if statement that has several or ed arguments. I have stacked them vertically as below for readability. if (health.flag_a || health.flag_b || health.flag_c || health.flag_d || health.flag_e || health.flag_f || health.flag_g || health.flag_h || health.flag_i || health.flag_k) { do_something(); return false; } clang-format converts this to: if (health.flag_a || health.flag_b || health.flag_c || health.flag_d || health.flag_e || health.flag_f || health.flag_g || health.flag_h || health

clang-format stack all if-statement arguments if they are too long

旧街凉风 提交于 2019-12-01 21:14:27
I have an if statement that has several or ed arguments. I have stacked them vertically as below for readability. if (health.flag_a || health.flag_b || health.flag_c || health.flag_d || health.flag_e || health.flag_f || health.flag_g || health.flag_h || health.flag_i || health.flag_k) { do_something(); return false; } clang-format converts this to: if (health.flag_a || health.flag_b || health.flag_c || health.flag_d || health.flag_e || health.flag_f || health.flag_g || health.flag_h || health.flag_i || health.flag_k) { do_something(); return false; } I want clang-format to stack them like