2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-30 14:07:59 +00:00

revise .clang-format and add a C formatting script in util

- add util/cformat.sh, which runs clang-format on all C files with
  the default .clang-format, and on all header files with a slightly
  modified version.
- use correct bracing after multi-line control statements
- stop aligning variable declarations to avoid problems with pointer
  alignment, but retain aligned declarations in header files so that
  struct definitions look cleaner.
- static function prototypes in C files can skip the line break after
  the return type, but function prototypes in header files still have
  the line break.
- don't break-before-brace in function definitions. ISC style calls
  for braces on the same line when function parameters fit on a single
  line, and a line break if they don't, but clang-format doesn't yet
  support that distinction. one-line function definitions are about
  four times more common than multi-line, so let's use the option that
  deviates less.
This commit is contained in:
Evan Hunt
2020-02-13 10:16:25 -08:00
parent 67b68e06ad
commit 0255a97473
3 changed files with 49 additions and 9 deletions

View File

@@ -1,20 +1,35 @@
BasedOnStyle: LLVM BasedOnStyle: LLVM
IndentWidth: 8 IndentWidth: 8
UseTab: Always UseTab: Always
BreakBeforeBraces: Linux BreakBeforeBraces: Custom
BraceWrapping:
AfterClass: false
AfterEnum: false
AfterStruct: false
AfterUnion: false
AfterControlStatement: MultiLine
AfterFunction: false # should also be MultiLine, but not yet supported
AfterExternBlock: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: true
AllowShortIfStatementsOnASingleLine: false AllowShortIfStatementsOnASingleLine: false
IndentCaseLabels: false IndentCaseLabels: false
AlwaysBreakAfterReturnType: All AlwaysBreakAfterReturnType: TopLevelDefinitions
Cpp11BracedListStyle: false Cpp11BracedListStyle: false
ColumnLimit: 80 ColumnLimit: 80
AlignAfterOpenBracket: Align AlignAfterOpenBracket: Align
AlignConsecutiveDeclarations: true AlignConsecutiveDeclarations: false
AlignConsecutiveMacros: true
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AlwaysBreakBeforeMultilineStrings: false AlwaysBreakBeforeMultilineStrings: false
BreakBeforeBinaryOperators: None BreakBeforeBinaryOperators: None
BreakBeforeTernaryOperators: true BreakBeforeTernaryOperators: true
AlignEscapedNewlines: Left AlignEscapedNewlines: Left
DerivePointerAlignment: false DerivePointerAlignment: false
PointerAlignment: Right PointerAlignment: Right
PointerBindsToType: false
IncludeBlocks: Regroup IncludeBlocks: Regroup
IncludeCategories: IncludeCategories:
- Regex: '^<isc/' - Regex: '^<isc/'
@@ -36,15 +51,11 @@ IncludeCategories:
- Regex: '".*"' - Regex: '".*"'
Priority: 9 Priority: 9
KeepEmptyLinesAtTheStartOfBlocks: false KeepEmptyLinesAtTheStartOfBlocks: false
MaxEmptyLinesToKeep: 1
# Taken from git's rules PenaltyBreakAssignment: 30
PenaltyBreakAssignment: 10
# PenaltyBreakBeforeFirstCallParameter: 30
PenaltyBreakComment: 10 PenaltyBreakComment: 10
PenaltyBreakFirstLessLess: 0 PenaltyBreakFirstLessLess: 0
PenaltyBreakString: 10 PenaltyBreakString: 10
PenaltyExcessCharacter: 100 PenaltyExcessCharacter: 100
Standard: Cpp11 Standard: Cpp11
ContinuationIndentWidth: 8 ContinuationIndentWidth: 8

28
util/cformat.sh Normal file
View File

@@ -0,0 +1,28 @@
#!/bin/sh
#
# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# See the COPYRIGHT file distributed with this work for additional
# information regarding copyright ownership.
# use the main .clang-format for C files
find bin lib -name "*.c" |
xargs clang-format --style=file --sort-includes -i
# set up a temporary .clang-format file for headers ONLY
cp -f .clang-format .clang-format.bak
sed -e 's/\(AlignConsecutiveDeclarations\).*/\1: true/' \
-e 's/\(AlwaysBreakAfterReturnType\).*/\1: All/' \
.clang-format.bak > .clang-format
# modify header files
find bin lib -name "*.h" |
xargs clang-format --style=file --sort-includes -i
# restore the original .clang-format file
cp -f .clang-format.bak .clang-format
rm -f .clang-format.bak

View File

@@ -2573,6 +2573,7 @@
./util/COPYRIGHT.TOP X 2018,2019,2020 ./util/COPYRIGHT.TOP X 2018,2019,2020
./util/bindkeys.pl PERL 2009,2010,2011,2012,2014,2016,2017,2018,2019,2020 ./util/bindkeys.pl PERL 2009,2010,2011,2012,2014,2016,2017,2018,2019,2020
./util/branchsync.sh SH 2013,2016,2018,2019,2020 ./util/branchsync.sh SH 2013,2016,2018,2019,2020
./util/cformat.sh SH 2020
./util/check-ans-prereq.sh SH 2019,2020 ./util/check-ans-prereq.sh SH 2019,2020
./util/check-categories.sh SH 2015,2016,2017,2018,2019,2020 ./util/check-categories.sh SH 2015,2016,2017,2018,2019,2020
./util/check-changes PERL 2002,2004,2007,2012,2016,2018,2019,2020 ./util/check-changes PERL 2002,2004,2007,2012,2016,2018,2019,2020