Skip to content

Commit 42efde4

Browse files
dschogitster
authored andcommitted
clang-format: adjust line break penalties
We really, really, really want to limit the columns to 80 per line: One of the few consistent style comments on the Git mailing list is that the lines should not have more than 80 columns/line (even if 79 columns/line would make more sense, given that the code is frequently viewed as diff, and diffs adding an extra character). The penalty of 5 for excess characters is way too low to guarantee that, though, as pointed out by Brandon Williams. From the existing clang-format examples and documentation, it appears that 100 is a penalty deemed appropriate for Stuff You Really Don't Want, so let's assign that as the penalty for "excess characters", i.e. overly long lines. While at it, adjust the penalties further: we are actually not that keen on preventing new line breaks within comments or string literals, so the penalty of 100 seems awfully high. Likewise, we are not all that adamant about keeping line breaks away from assignment operators (a lot of Git's code breaks immediately after the `=` character just to keep that 80 columns/line limit). We do frown a little bit more about functions' return types being on their own line than the penalty 0 would suggest, so this was adjusted, too. Finally, we do not particularly fancy breaking before the first parameter in a call, but if it keeps the line shorter than 80 columns/line, that's what we do, so lower the penalty for breaking before a call's first parameter, but not quite as much as introducing new line breaks to comments. Signed-off-by: Johannes Schindelin <[email protected]> Reviewed-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2118805 commit 42efde4

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

.clang-format

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,13 @@ KeepEmptyLinesAtTheStartOfBlocks: false
153153

154154
# Penalties
155155
# This decides what order things should be done if a line is too long
156-
PenaltyBreakAssignment: 100
157-
PenaltyBreakBeforeFirstCallParameter: 100
158-
PenaltyBreakComment: 100
156+
PenaltyBreakAssignment: 10
157+
PenaltyBreakBeforeFirstCallParameter: 30
158+
PenaltyBreakComment: 10
159159
PenaltyBreakFirstLessLess: 0
160-
PenaltyBreakString: 100
161-
PenaltyExcessCharacter: 5
162-
PenaltyReturnTypeOnItsOwnLine: 0
160+
PenaltyBreakString: 10
161+
PenaltyExcessCharacter: 100
162+
PenaltyReturnTypeOnItsOwnLine: 5
163163

164164
# Don't sort #include's
165165
SortIncludes: false

0 commit comments

Comments
 (0)