Skip to content

Commit 1b8f306

Browse files
KarthikNayakgitster
authored andcommitted
ci/style-check: add RemoveBracesLLVM in CI job
For 'clang-format', setting 'RemoveBracesLLVM' to 'true', adds a check to ensure we avoid curly braces for single-statement bodies in conditional blocks. However, the option does come with two warnings [1]: This option will be renamed and expanded to support other styles. and Setting this option to true could lead to incorrect code formatting due to clang-format’s lack of complete semantic information. As such, extra care should be taken to review code changes made by this option. The latter seems to be of concern. While we want to experiment with the rule, adding it to the in-tree '.clang-format' could affect end-users. Let's only add it to the CI jobs for now. With time, we can evaluate its efficacy and decide if we want to add it to '.clang-format' or retract it entirely. We do so, by adding the existing rules in '.clang-format' and this rule to a temp file outside the working tree, which is then used by 'git clang-format'. This ensures we don't murk with files in-tree. [1]: https://clang.llvm.org/docs/ClangFormatStyleOptions.html#removebracesllvm Signed-off-by: Karthik Nayak <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 30c4f7e commit 1b8f306

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

ci/run-style-check.sh

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,21 @@
55

66
baseCommit=$1
77

8-
git clang-format --style file --diff --extensions c,h "$baseCommit"
8+
# Remove optional braces of control statements (if, else, for, and while)
9+
# according to the LLVM coding style. This avoids braces on simple
10+
# single-statement bodies of statements but keeps braces if one side of
11+
# if/else if/.../else cascade has multi-statement body.
12+
#
13+
# As this rule comes with a warning [1], we want to experiment with it
14+
# before adding it in-tree. since the CI job for the style check is allowed
15+
# to fail, appending the rule here allows us to validate its efficacy.
16+
# While also ensuring that end-users are not affected directly.
17+
#
18+
# [1]: https://clang.llvm.org/docs/ClangFormatStyleOptions.html#removebracesllvm
19+
{
20+
cat .clang-format
21+
echo "RemoveBracesLLVM: true"
22+
} >/tmp/clang-format-rules
23+
24+
git clang-format --style=file:/tmp/clang-format-rules \
25+
--diff --extensions c,h "$baseCommit"

0 commit comments

Comments
 (0)