@owenpan Thanks to LLVM weekly I’ve spotted RemoveBracesLLVM in clang-format. I know it says experimental, though it really looks promising/useful for our code as we have a similar style guide rule.
Your documentation states: This option will be renamed and expanded to support other styles.
however it ain’t clear to me which options you have in mind.
Reading through the unit tests, I feel the only divination we have from this rule is the allowed level of nesting before {} are needed. Which in our case is at 1 while you have it at 2 levels deep. Let me make it practical, see examples below.
Is this an option you already had on your list? If not, can this be added?
LLVM:
verifyFormat("if (isa<FunctionDecl>(D)) {\n"
" for (auto *A : D.attrs())\n"
" for (ssize_t i : llvm::seq<ssize_t>(count))\n"
" handleAttrOnDecl(D, A, i);\n"
"}",
"if (isa<FunctionDecl>(D)) {\n"
" for (auto *A : D.attrs()) {\n"
" for (ssize_t i : llvm::seq<ssize_t>(count)) {\n"
" handleAttrOnDecl(D, A, i);\n"
" }\n"
" }\n"
"}",
Style);
Ours:
verifyFormat("if (isa<FunctionDecl>(D)) {\n"
" for (auto *A : D.attrs()) {\n"
" for (ssize_t i : llvm::seq<ssize_t>(count))\n"
" handleAttrOnDecl(D, A, i);\n"
" }\n"
"}",
"if (isa<FunctionDecl>(D)) {\n"
" for (auto *A : D.attrs()) {\n"
" for (ssize_t i : llvm::seq<ssize_t>(count)) {\n"
" handleAttrOnDecl(D, A, i);\n"
" }\n"
" }\n"
"}",
Style);
LLVM:
verifyFormat("if (a)\n"
" if (b)\n"
" c;\n"
" else\n"
" d;\n"
"else\n"
" e;",
"if (a) {\n"
" if (b) {\n"
" c;\n"
" } else {\n"
" d;\n"
" }\n"
"} else {\n"
" e;\n"
"}",
Style);
Ours:
verifyFormat("if (a) {\n"
" if (b)\n"
" c;\n"
" else\n"
" d;\n"
" }\n"
"else {\n"
" e;"
"}\n",
"if (a) {\n"
" if (b) {\n"
" c;\n"
" } else {\n"
" d;\n"
" }\n"
"} else {\n"
" e;\n"
"}",
Style);
LLVM:
verifyFormat("if (isa<FunctionDecl>(D))\n"
" for (auto *A : D.attrs())\n"
" handleAttr(A);",
"if (isa<FunctionDecl>(D)) {\n"
" for (auto *A : D.attrs()) {\n"
" handleAttr(A);\n"
" }\n"
"}",
Style);
Ours:
verifyFormat("if (isa<FunctionDecl>(D)) {\n"
" for (auto *A : D.attrs())\n"
" handleAttr(A);"
"}\n",
"if (isa<FunctionDecl>(D)) {\n"
" for (auto *A : D.attrs()) {\n"
" handleAttr(A);\n"
" }\n"
"}",
Style);