From 9576cdd055dcd7b433af6d3e03d8e1f1073b7774 Mon Sep 17 00:00:00 2001 From: Jiacheng Guo Date: Fri, 22 Oct 2021 16:54:17 +0800 Subject: [PATCH] ci: add auto format scripts --- .clang-format | 109 +++++++++++++++++++++++++++++++++++++++++ .gitignore | 1 - tools/ci/format_all.sh | 13 +++++ 3 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 .clang-format create mode 100755 tools/ci/format_all.sh diff --git a/.clang-format b/.clang-format new file mode 100644 index 000000000..20f9da872 --- /dev/null +++ b/.clang-format @@ -0,0 +1,109 @@ +--- +Language: Cpp +# BasedOnStyle: LLVM +AccessModifierOffset: -4 +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlines: Left +AlignOperands: false +AlignTrailingComments: false +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: InlineOnly +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: true +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: true +BinPackArguments: true +BinPackParameters: true +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: false + AfterEnum: false + AfterFunction: true + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeBinaryOperators: None +BreakBeforeBraces: Custom +BreakBeforeInheritanceComma: false +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +BreakConstructorInitializers: BeforeComma +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: true +ColumnLimit: 120 +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false +ConstructorInitializerAllOnOneLineOrOnePerLine: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DerivePointerAlignment: false +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: true +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IncludeCategories: + - Regex: '^<' + Priority: 2 + - Regex: '^".*/' + Priority: 5 + - Regex: '^"' + Priority: 1 +IncludeIsMainRegex: '(Test)?$' +IndentCaseLabels: false +IndentWidth: 4 +IndentWrappedFunctionNames: false +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: false +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCBlockIndentWidth: 2 +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 1000 +PointerAlignment: Right +ReflowComments: true +SortIncludes: true +SortUsingDeclarations: true +SpaceAfterCStyleCast: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeParens: ControlStatements +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Cpp11 +TabWidth: 4 +UseTab: Never +... + diff --git a/.gitignore b/.gitignore index dc26b1744..50bb4bb10 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ .cache -.clang-format compile_commands.json *.swp build/ diff --git a/tools/ci/format_all.sh b/tools/ci/format_all.sh new file mode 100755 index 000000000..07106ae15 --- /dev/null +++ b/tools/ci/format_all.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +pushd "$(pwd)" + +cd "${ESP_MATTER_PATH}" +SRC_FILES="$(find components device_hal examples -regextype posix-egrep -regex ".*\.(c|cpp|cxx|h|hpp|hxx)" |\ + grep -v -iE '/gen/|/build/|/zap-generated/')" +for SRC_FILE in ${SRC_FILES}; do + echo "formatting ${SRC_FILE}" + clang-format -i "${SRC_FILE}" +done + +popd