Skip to content

Commit bc3287e

Browse files
committed
Merge branch 'kn/clang-format-updates' into seen
* 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 editorconfig: set maximum line length to 120 characters
2 parents e56a707 + 728cf42 commit bc3287e

File tree

4 files changed

+29
-29
lines changed

4 files changed

+29
-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

.editorconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ insert_final_newline = true
77
[{*.{c,h,sh,bash,perl,pl,pm,txt,adoc},config.mak.*,Makefile}]
88
indent_style = tab
99
tab_width = 8
10+
max_line_length = 120
1011

1112
[*.py]
1213
indent_style = space

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+
clang_format = find_program('clang-format', required: false)
2152+
if 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)