Skip to content

Commit af12714

Browse files
committed
Merge branch 'kn/clang-format-updates' into seen
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 7ad7333 + 9b5a6c8 commit af12714

3 files changed

Lines changed: 28 additions & 29 deletions

File tree

.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
@@ -2148,6 +2148,18 @@ if headers_to_check.length() != 0 and compiler.get_argument_syntax() == 'gcc'
21482148
alias_target('check-headers', hdr_check)
21492149
endif
21502150

2151+
git_clang_format = find_program('git-clang-format', required: false)
2152+
if git_clang_format.found()
2153+
run_target('style',
2154+
command: [
2155+
'git', 'clang-format',
2156+
'--style', 'file',
2157+
'--diff',
2158+
'--extensions', 'c,h'
2159+
]
2160+
)
2161+
endif
2162+
21512163
foreach key, value : {
21522164
'DIFF': diff.full_path(),
21532165
'GIT_SOURCE_DIR': meson.project_source_root(),

0 commit comments

Comments
 (0)