From 04df6ae311b1b7d13800f6d8d63ab340e3ee33af Mon Sep 17 00:00:00 2001 From: Tim Crawford Date: Mon, 19 Jul 2021 09:40:22 -0600 Subject: [PATCH] Add .clang-format Most options are configured to keep most of the current style. Signed-off-by: Tim Crawford --- .clang-format | 133 ++++++++++++++++++++++++++++++++++++++++ scripts/clang-format.sh | 16 +++++ scripts/deps.sh | 3 + 3 files changed, 152 insertions(+) create mode 100644 .clang-format create mode 100755 scripts/clang-format.sh diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..ff77f26 --- /dev/null +++ b/.clang-format @@ -0,0 +1,133 @@ +# https://releases.llvm.org/10.0.0/tools/clang/docs/ClangFormatStyleOptions.html +--- +Language: Cpp +AccessModifierOffset: -4 +AlignAfterOpenBracket: AlwaysBreak +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignConsecutiveMacros: true +AlignEscapedNewlines: DontAlign +AlignOperands: true +AlignTrailingComments: false +AllowAllArgumentsOnNextLine: true +AllowAllConstructorInitializersOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortBlocksOnASingleLine: Empty +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: Inline +AllowShortIfStatementsOnASingleLine: Never +AllowShortLambdasOnASingleLine: All +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: Yes +BinPackArguments: false +BinPackParameters: false +BraceWrapping: + AfterCaseLabel: false + AfterClass: true + AfterControlStatement: false + AfterEnum: false + AfterFunction: false + AfterNamespace: true + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false + SplitEmptyFunction: false + SplitEmptyRecord: false + SplitEmptyNamespace: false +BreakAfterJavaFieldAnnotations: false +BreakBeforeBinaryOperators: None +BreakBeforeBraces: Custom +BreakBeforeTernaryOperators: false +BreakConstructorInitializers: AfterColon +BreakInheritanceList: AfterColon +BreakStringLiterals: false +ColumnLimit: 96 +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false +ConstructorInitializerAllOnOneLineOrOnePerLine: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: false +DeriveLineEnding: false +DerivePointerAlignment: false +DisableFormat: false +ExperimentalAutoDetectBinPacking: true +FixNamespaceComments: false +ForEachMacros: + - foreach +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + SortPriority: 0 + - Regex: '^(<|"(gtest|gmock|isl|json)/)' + Priority: 3 + SortPriority: 0 + - Regex: '.*' + Priority: 1 + SortPriority: 0 +IncludeIsMainRegex: '(Test)?$' +IncludeIsMainSourceRegex: '' +IndentCaseLabels: true +IndentGotoLabels: false +IndentPPDirectives: BeforeHash +IndentWidth: 4 +IndentWrappedFunctionNames: false +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: false +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCBinPackProtocolList: Auto +ObjCBlockIndentWidth: 4 +ObjCSpaceAfterProperty: true +ObjCSpaceBeforeProtocolList: true + +PenaltyBreakAssignment: 10 +PenaltyBreakBeforeFirstCallParameter: 10 +PenaltyBreakComment: 100 +PenaltyBreakFirstLessLess: 5 +PenaltyBreakString: 100 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 5 +PenaltyReturnTypeOnItsOwnLine: 100 + +PointerAlignment: Middle +ReflowComments: false +SortIncludes: true +SortUsingDeclarations: true +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: true +SpaceBeforeSquareBrackets: false +SpaceInEmptyBlock: false +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInCStyleCastParentheses: false +SpacesInConditionalStatement: false +SpacesInContainerLiterals: true +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Latest +StatementMacros: + - ARRAY_SIZE + - xstr +TabWidth: 4 +UseCRLF: false +UseTab: Never +... diff --git a/scripts/clang-format.sh b/scripts/clang-format.sh new file mode 100755 index 0000000..a4d7e0c --- /dev/null +++ b/scripts/clang-format.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: GPL-3.0-only + +FILES=($(git ls-files '*.[ch]')) + +FMT_OPTS=( + "-style=file" + "--fallback-style=none" + "--Werror" +) + +if [[ "$1" = "apply" ]]; then + clang-format "${FMT_OPTS[@]}" -i "${FILES[@]}" +else + clang-format "${FMT_OPTS[@]}" --dry-run "${FILES[@]}" +fi diff --git a/scripts/deps.sh b/scripts/deps.sh index a5ebec1..c12e16b 100755 --- a/scripts/deps.sh +++ b/scripts/deps.sh @@ -19,6 +19,7 @@ if [[ "${ID}" =~ "debian" ]] || [[ "${ID_LIKE}" =~ "debian" ]]; then --yes \ avr-libc \ avrdude \ + clang-format \ curl \ gcc \ gcc-avr \ @@ -35,6 +36,7 @@ elif [[ "${ID}" =~ "fedora" ]] || [[ "${ID_LIKE}" =~ "fedora" ]]; then avr-gcc \ avr-libc \ avrdude \ + clang-tools-extra \ curl \ gcc \ make \ @@ -47,6 +49,7 @@ elif [[ "${ID}" =~ "arch" ]] || [[ "${ID_LIKE}" =~ "arch" ]]; then avr-gcc \ avr-libc \ avrdude \ + clang \ curl \ gcc \ make \