Skip to content

Commit 38349d1

Browse files
committed
Merge branch 'kn/clang-format-updates'
Update ".clang-format" and ".editorconfig" to match our style guide a bit better. * kn/clang-format-updates: meson: add rule to run 'git clang-format' clang-format: add 'RemoveBracesLLVM' to the main config clang-format: set 'ColumnLimit' to 0
2 parents a35b8c8 + 3f7e447 commit 38349d1

File tree

3 files changed

+28
-29
lines changed

3 files changed

+28
-29
lines changed

.clang-format

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,15 @@ UseTab: Always
1212
TabWidth: 8
1313
IndentWidth: 8
1414
ContinuationIndentWidth: 8
15-
ColumnLimit: 80
15+
16+
# While we do want to enforce a character limit of 80 characters, we often
17+
# allow lines to overflow that limit to prioritize readability. Setting a
18+
# character limit here with penalties has been finicky and creates too many
19+
# false positives.
20+
#
21+
# NEEDSWORK: It would be nice if we can find optimal settings to ensure we
22+
# can re-enable the limit here.
23+
ColumnLimit: 0
1624

1725
# C Language specifics
1826
Language: Cpp
@@ -210,16 +218,11 @@ MaxEmptyLinesToKeep: 1
210218
# No empty line at the start of a block.
211219
KeepEmptyLinesAtTheStartOfBlocks: false
212220

213-
# Penalties
214-
# This decides what order things should be done if a line is too long
215-
PenaltyBreakAssignment: 5
216-
PenaltyBreakBeforeFirstCallParameter: 5
217-
PenaltyBreakComment: 5
218-
PenaltyBreakFirstLessLess: 0
219-
PenaltyBreakOpenParenthesis: 300
220-
PenaltyBreakString: 5
221-
PenaltyExcessCharacter: 10
222-
PenaltyReturnTypeOnItsOwnLine: 300
223-
224221
# Don't sort #include's
225222
SortIncludes: false
223+
224+
# Remove optional braces of control statements (if, else, for, and while)
225+
# according to the LLVM coding style. This avoids braces on simple
226+
# single-statement bodies of statements but keeps braces if one side of
227+
# if/else if/.../else cascade has multi-statement body.
228+
RemoveBracesLLVM: true

ci/run-style-check.sh

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,5 @@
55

66
baseCommit=$1
77

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 \
8+
git clang-format --style=file:.clang-format \
259
--diff --extensions c,h "$baseCommit"

meson.build

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2133,6 +2133,18 @@ if headers_to_check.length() != 0 and compiler.get_argument_syntax() == 'gcc'
21332133
alias_target('check-headers', hdr_check)
21342134
endif
21352135

2136+
git_clang_format = find_program('git-clang-format', required: false, native: true)
2137+
if git_clang_format.found()
2138+
run_target('style',
2139+
command: [
2140+
git_clang_format,
2141+
'--style', 'file',
2142+
'--diff',
2143+
'--extensions', 'c,h'
2144+
]
2145+
)
2146+
endif
2147+
21362148
foreach key, value : {
21372149
'DIFF': diff.full_path(),
21382150
'GIT_SOURCE_DIR': meson.project_source_root(),

0 commit comments

Comments
 (0)