From 459a3bf888bc394d9168593a6cce4e6fdff2f9ad Mon Sep 17 00:00:00 2001 From: Robert Adam Date: Sat, 29 Aug 2020 19:35:55 +0200 Subject: [PATCH] MAINT: Added clang-format support The used .clang-format file has been generated using clang-format 6 (shipped with Ubuntu 18.04) and is therefore backwards compatible with all clang-format versions until v6. --- .clang-format | 86 +++++++++++++++++++++++++++++++++ scripts/runClangFormat.sh | 16 ++++++ src/mumble/TextToSpeech_win.cpp | 3 ++ 3 files changed, 105 insertions(+) create mode 100644 .clang-format create mode 100755 scripts/runClangFormat.sh diff --git a/.clang-format b/.clang-format new file mode 100644 index 000000000..404838be0 --- /dev/null +++ b/.clang-format @@ -0,0 +1,86 @@ +--- +Language: Cpp +AccessModifierOffset: -4 +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: true +# Setting AlignConsecutiveDeclarations to true would be nice but it doesn't work right with PointerAlignment=Right +AlignConsecutiveDeclarations: false +AlignEscapedNewlines: Left +AlignOperands: true +AlignTrailingComments: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: InlineOnly +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: false +BinPackArguments: true +BinPackParameters: true +BreakBeforeBinaryOperators: NonAssignment +BreakBeforeBraces: Attach +BreakBeforeTernaryOperators: true +BreakConstructorInitializers: BeforeColon +BreakStringLiterals: true +ColumnLimit: 120 +CompactNamespaces: false +ConstructorInitializerAllOnOneLineOrOnePerLine: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: false +DerivePointerAlignment: false +DisableFormat: false +FixNamespaceComments: true +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IncludeBlocks: Preserve +IncludeCategories: + # Global.h must always be included last + - Regex: 'Global.h' + Priority: 10000 + # Since a lot of windows-headers rely on windows.h, it has to be included first + - Regex: 'windows.h' + Priority: 1 + # Assign a priority < INT_MAX to all other includes in order to be able to force headers + # to come after them + - Regex: '.*' + Priority: 10 +IndentCaseLabels: true +IndentPPDirectives: AfterHash +IndentWidth: 4 +IndentWrappedFunctionNames: true +KeepEmptyLinesAtTheStartOfBlocks: false +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 3 +NamespaceIndentation: Inner +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 60 +PointerAlignment: Right +ReflowComments: true +SortIncludes: true +SortUsingDeclarations: true +SpaceAfterCStyleCast: true +SpaceAfterTemplateKeyword: false +SpaceBeforeAssignmentOperators: true +SpaceBeforeParens: ControlStatements +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: true +SpacesInContainerLiterals: true +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Cpp11 +TabWidth: 4 +UseTab: ForContinuationAndIndentation +... + diff --git a/scripts/runClangFormat.sh b/scripts/runClangFormat.sh new file mode 100755 index 000000000..b6984b713 --- /dev/null +++ b/scripts/runClangFormat.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +# +# Copyright 2005-2020 The Mumble Developers. All rights reserved. +# Use of this source code is governed by a BSD-style license +# that can be found in the LICENSE file at the root of the +# Mumble source tree or at . + +currentDir=$(dirname $0) + +mainDir="$currentDir/.." + +cd "$mainDir" + +find -type f \( -iname "*.cpp" -o -iname "*.c" -o -iname "*.hpp" -o -iname "*.h" -o -iname "*.cxx" -o -iname "*.cc" \) \ + -a -not -ipath "./3rdparty/*" -a -not -path "./.git/*" -a -not -ipath "./build/*" \ + | xargs clang-format --style=file -i diff --git a/src/mumble/TextToSpeech_win.cpp b/src/mumble/TextToSpeech_win.cpp index f70c2c847..56706de44 100644 --- a/src/mumble/TextToSpeech_win.cpp +++ b/src/mumble/TextToSpeech_win.cpp @@ -5,8 +5,11 @@ #include "TextToSpeech.h" +// As the include order seems to make a difference, disable clang-format for them +// clang-format off #include #include +// clang-format on #undef FAILED #define FAILED(Status) (static_cast(Status)<0)