已合并
chore: align format and pre-commit configs #686
ling-DT创建于 6月5日
chore: align format and pre-commit configs #686
已合并
共 2 个文件变更+194-209
| @@ -1,223 +1,150 @@ | |||
| 1 | -# ---------------------------------------------------------------------------------------------------------------------- | 1 | +--- |
| 2 | -# Copyright (c) 2026 Huawei Technologies Co., Ltd. | 2 | +Language: Cpp |
| 3 | -# This program is free software, you can redistribute it and/or modify it under the terms and contiditions of | 3 | +# BasedOnStyle: Google |
| 4 | -# CANN Open Software License Agreement Version 2.0 (the "License"). | 4 | +AccessModifierOffset: -1 |
| 5 | -# Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | -# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | -# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | -# See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | -# ---------------------------------------------------------------------------------------------------------------------- | ||
| 10 | - | ||
| 11 | -# 语言: None, Cpp, Java, JavaScript, ObjC, Proto, TableGen, TextProto | ||
| 12 | -Language: Cpp | ||
| 13 | -# BasedOnStyle: LLVM | ||
| 14 | - | ||
| 15 | -# 访问说明符(public、private等)的偏移 | ||
| 16 | -AccessModifierOffset: -4 | ||
| 17 | - | ||
| 18 | -# 开括号(开圆括号、开尖括号、开方括号)后的对齐: Align, DontAlign, AlwaysBreak(总是在开括号后换行) | ||
| 19 | AlignAfterOpenBracket: Align | 5 | AlignAfterOpenBracket: Align |
| 20 | - | ||
| 21 | -# 连续赋值时,对齐所有等号 | ||
| 22 | AlignConsecutiveAssignments: false | 6 | AlignConsecutiveAssignments: false |
| 23 | - | ||
| 24 | -# 连续声明时,对齐所有声明的变量名 | ||
| 25 | AlignConsecutiveDeclarations: false | 7 | AlignConsecutiveDeclarations: false |
| 26 | - | 8 | +AlignEscapedNewlines: Left |
| 27 | -# 右对齐逃脱换行(使用反斜杠换行)的反斜杠 | 9 | +AlignOperands: true |
| 28 | -AlignEscapedNewlines: Right | ||
| 29 | - | ||
| 30 | -# 水平对齐二元和三元表达式的操作数 | ||
| 31 | -AlignOperands: true | ||
| 32 | - | ||
| 33 | -# 对齐连续的尾随的注释 | ||
| 34 | AlignTrailingComments: true | 10 | AlignTrailingComments: true |
| 35 | - | 11 | +AllowAllParametersOfDeclarationOnNextLine: true |
| 36 | -# 不允许函数声明的所有参数在放在下一行 | 12 | +AllowShortBlocksOnASingleLine: false |
| 37 | -AllowAllParametersOfDeclarationOnNextLine: false | ||
| 38 | - | ||
| 39 | -# 不允许短的块放在同一行 | ||
| 40 | -AllowShortBlocksOnASingleLine: true | ||
| 41 | - | ||
| 42 | -# 允许短的case标签放在同一行 | ||
| 43 | AllowShortCaseLabelsOnASingleLine: false | 13 | AllowShortCaseLabelsOnASingleLine: false |
| 44 | - | ||
| 45 | -# 允许短的函数放在同一行: None, InlineOnly(定义在类中), Empty(空函数), Inline(定义在类中,空函数), All | ||
| 46 | AllowShortFunctionsOnASingleLine: Empty | 14 | AllowShortFunctionsOnASingleLine: Empty |
| 47 | - | 15 | +AllowShortIfStatementsOnASingleLine: true |
| 48 | -# 允许短的if语句保持在同一行 | 16 | +AllowShortLoopsOnASingleLine: true |
| 49 | -AllowShortIfStatementsOnASingleLine: false | 17 | +AlwaysBreakAfterDefinitionReturnType: None |
| 50 | - | ||
| 51 | -# 禁止将短的循环体(如单行语句)放在同一行 | ||
| 52 | -AllowShortLoopsOnASingleLine: false | ||
| 53 | - | ||
| 54 | -# 总是在返回类型后换行: None, All, TopLevel(顶级函数,不包括在类中的函数), | ||
| 55 | -# AllDefinitions(所有的定义,不包括声明), TopLevelDefinitions(所有的顶级函数的定义) | ||
| 56 | AlwaysBreakAfterReturnType: None | 18 | AlwaysBreakAfterReturnType: None |
| 57 | - | 19 | +AlwaysBreakBeforeMultilineStrings: true |
| 58 | -# 总是在多行string字面量前换行 | 20 | +AlwaysBreakTemplateDeclarations: Yes |
| 59 | -AlwaysBreakBeforeMultilineStrings: false | ||
| 60 | - | ||
| 61 | -# 总是在template声明后换行 | ||
| 62 | -AlwaysBreakTemplateDeclarations: true | ||
| 63 | - | ||
| 64 | -# false表示函数实参要么都在同一行,要么都各自一行 | ||
| 65 | BinPackArguments: true | 21 | BinPackArguments: true |
| 66 | - | ||
| 67 | -# false表示所有形参要么都在同一行,要么都各自一行 | ||
| 68 | BinPackParameters: true | 22 | BinPackParameters: true |
| 69 | - | ||
| 70 | -# 大括号换行,只有当BreakBeforeBraces设置为Custom时才有效 | ||
| 71 | BraceWrapping: | 23 | BraceWrapping: |
| 72 | - # class定义后面 | 24 | + AfterClass: false |
| 73 | - AfterClass: false | ||
| 74 | - # 控制语句后面 | ||
| 75 | AfterControlStatement: false | 25 | AfterControlStatement: false |
| 76 | - # enum定义后面 | 26 | + AfterEnum: false |
| 77 | - AfterEnum: false | 27 | + AfterFunction: false |
| 78 | - # 函数定义后面 | 28 | + AfterNamespace: false |
| 79 | - AfterFunction: true | 29 | + AfterObjCDeclaration: false |
| 80 | - # 命名空间定义后面 | 30 | + AfterStruct: false |
| 81 | - AfterNamespace: false | 31 | + AfterUnion: false |
| 82 | - # struct定义后面 | ||
| 83 | - AfterStruct: false | ||
| 84 | - # union定义后面 | ||
| 85 | - AfterUnion: false | ||
| 86 | - # extern之后 | ||
| 87 | AfterExternBlock: false | 32 | AfterExternBlock: false |
| 88 | - # catch之前 | 33 | + BeforeCatch: false |
| 89 | - BeforeCatch: false | 34 | + BeforeElse: false |
| 90 | - # else之前 | 35 | + IndentBraces: false |
| 91 | - BeforeElse: false | 36 | + SplitEmptyFunction: true |
| 92 | - # 缩进大括号 | 37 | + SplitEmptyRecord: true |
| 93 | - IndentBraces: false | 38 | + SplitEmptyNamespace: true |
| 94 | - # 分离空函数 | 39 | +BreakBeforeBinaryOperators: None |
| 95 | - SplitEmptyFunction: false | 40 | +BreakBeforeBraces: Attach |
| 96 | - # 分离空语句 | 41 | +BreakBeforeInheritanceComma: false |
| 97 | - SplitEmptyRecord: false | 42 | +BreakInheritanceList: BeforeColon |
| 98 | - # 分离空命名空间 | 43 | +BreakBeforeTernaryOperators: true |
| 99 | - SplitEmptyNamespace: false | 44 | +BreakConstructorInitializersBeforeComma: false |
| 100 | - | 45 | +BreakConstructorInitializers: BeforeColon |
| 101 | -# 在二元运算符前换行: None(在操作符后换行), NonAssignment(在非赋值的操作符前换行), All(在操作符前换行) | 46 | +BreakAfterJavaFieldAnnotations: false |
| 102 | -BreakBeforeBinaryOperators: NonAssignment | 47 | +BreakStringLiterals: true |
| 103 | - | 48 | +ColumnLimit: 120 |
| 104 | -# 在大括号前换行: Attach(始终将大括号附加到周围的上下文), Linux(除函数、命名空间和类定义,与Attach类似), | 49 | +CommentPragmas: '^ IWYU pragma:' |
| 105 | -# Mozilla(除枚举、函数、记录定义,与Attach类似), Stroustrup(除函数定义、catch、else,与Attach类似), | ||
| 106 | -# Allman(总是在大括号前换行), GNU(总是在大括号前换行,并对于控制语句的大括号增加额外的缩进), WebKit(在函数前换行), Custom | ||
| 107 | -# 注:这里认为语句块也属于函数 | ||
| 108 | -BreakBeforeBraces: Custom | ||
| 109 | - | ||
| 110 | -# 在三元运算符前换行 | ||
| 111 | -BreakBeforeTernaryOperators: false | ||
| 112 | - | ||
| 113 | -# 在构造函数的初始化列表的冒号后换行 | ||
| 114 | -BreakConstructorInitializers: AfterColon | ||
| 115 | - | ||
| 116 | -#BreakInheritanceList: AfterColon | ||
| 117 | - | ||
| 118 | -BreakStringLiterals: false | ||
| 119 | - | ||
| 120 | -# 每行字符的限制,0表示没有限制 | ||
| 121 | -ColumnLimit: 120 | ||
| 122 | - | ||
| 123 | CompactNamespaces: false | 50 | CompactNamespaces: false |
| 124 | - | 51 | +ConstructorInitializerAllOnOneLineOrOnePerLine: true |
| 125 | -# 构造函数的初始化列表要么都在同一行,要么都各自一行 | ||
| 126 | -ConstructorInitializerAllOnOneLineOrOnePerLine: false | ||
| 127 | - | ||
| 128 | -# 构造函数的初始化列表的缩进宽度 | ||
| 129 | ConstructorInitializerIndentWidth: 4 | 52 | ConstructorInitializerIndentWidth: 4 |
| 130 | - | ||
| 131 | -# 延续的行的缩进宽度 | ||
| 132 | ContinuationIndentWidth: 4 | 53 | ContinuationIndentWidth: 4 |
| 133 | - | ||
| 134 | -# 去除C++11的列表初始化的大括号{后和}前的空格 | ||
| 135 | Cpp11BracedListStyle: true | 54 | Cpp11BracedListStyle: true |
| 136 | - | 55 | +DisableFormat: false |
| 137 | -# 继承最常用的指针和引用的对齐方式 | 56 | +ExperimentalAutoDetectBinPacking: false |
| 138 | -DerivePointerAlignment: false | ||
| 139 | - | ||
| 140 | -# 固定命名空间注释 | ||
| 141 | FixNamespaceComments: true | 57 | FixNamespaceComments: true |
| 142 | - | 58 | +ForEachMacros: |
| 143 | -# 缩进case标签 | 59 | +# - foreach |
| 60 | + - Q_FOREACH | ||
| 61 | + - BOOST_FOREACH | ||
| 62 | +IncludeBlocks: Preserve | ||
| 63 | +IncludeCategories: | ||
| 64 | + - Regex: '^<ext/.*\.h>' | ||
| 65 | + Priority: 2 | ||
| 66 | + - Regex: '^<.*\.h>' | ||
| 67 | + Priority: 1 | ||
| 68 | + - Regex: '^<.*' | ||
| 69 | + Priority: 2 | ||
| 70 | + - Regex: '.*' | ||
| 71 | + Priority: 3 | ||
| 72 | +IncludeIsMainRegex: '([-_](test|unittest))?$' | ||
| 144 | IndentCaseLabels: true | 73 | IndentCaseLabels: true |
| 145 | - | ||
| 146 | IndentPPDirectives: None | 74 | IndentPPDirectives: None |
| 147 | - | 75 | +IndentWidth: 2 |
| 148 | -# 缩进宽度 | ||
| 149 | -IndentWidth: 4 | ||
| 150 | - | ||
| 151 | -# 函数返回类型换行时,缩进函数声明或函数定义的函数名 | ||
| 152 | IndentWrappedFunctionNames: false | 76 | IndentWrappedFunctionNames: false |
| 153 | - | 77 | +JavaScriptQuotes: Leave |
| 154 | -# 保留在块开始处的空行 | 78 | +JavaScriptWrapImports: true |
| 155 | KeepEmptyLinesAtTheStartOfBlocks: false | 79 | KeepEmptyLinesAtTheStartOfBlocks: false |
| 156 | - | 80 | +MacroBlockBegin: '' |
| 157 | -# 连续空行的最大数量 | 81 | +MacroBlockEnd: '' |
| 158 | MaxEmptyLinesToKeep: 1 | 82 | MaxEmptyLinesToKeep: 1 |
| 159 | - | ||
| 160 | -# 命名空间的缩进: None, Inner(缩进嵌套的命名空间中的内容), All | ||
| 161 | NamespaceIndentation: None | 83 | NamespaceIndentation: None |
| 162 | - | 84 | +ObjCBinPackProtocolList: Never |
| 163 | -# 指针和引用的对齐: Left, Right, Middle | 85 | +ObjCBlockIndentWidth: 2 |
| 164 | -PointerAlignment: Left | 86 | +ObjCSpaceAfterProperty: false |
| 165 | - | 87 | +ObjCSpaceBeforeProtocolList: true |
| 166 | -# 允许重新排版注释 | 88 | +PenaltyBreakAssignment: 2 |
| 167 | -ReflowComments: true | 89 | +PenaltyBreakBeforeFirstCallParameter: 1 |
| 168 | - | 90 | +PenaltyBreakComment: 300 |
| 169 | -# 允许排序#include | 91 | +PenaltyBreakFirstLessLess: 120 |
| 170 | -SortIncludes: false | 92 | +PenaltyBreakString: 1000 |
| 171 | - | 93 | +PenaltyBreakTemplateDeclaration: 10 |
| 172 | -# 允许排序 using 声明 | 94 | +PenaltyExcessCharacter: 1000000 |
| 173 | -SortUsingDeclarations: false | 95 | +PenaltyReturnTypeOnItsOwnLine: 200 |
| 174 | - | 96 | +PointerAlignment: Right |
| 175 | -# 在C风格类型转换后添加空格 | 97 | +RawStringFormats: |
| 98 | + - Language: Cpp | ||
| 99 | + Delimiters: | ||
| 100 | + - cc | ||
| 101 | + - CC | ||
| 102 | + - cpp | ||
| 103 | + - Cpp | ||
| 104 | + - CPP | ||
| 105 | + - 'c++' | ||
| 106 | + - 'C++' | ||
| 107 | + CanonicalDelimiter: '' | ||
| 108 | + BasedOnStyle: google | ||
| 109 | + - Language: TextProto | ||
| 110 | + Delimiters: | ||
| 111 | + - pb | ||
| 112 | + - PB | ||
| 113 | + - proto | ||
| 114 | + - PROTO | ||
| 115 | + EnclosingFunctions: | ||
| 116 | + - EqualsProto | ||
| 117 | + - EquivToProto | ||
| 118 | + - PARSE_PARTIAL_TEXT_PROTO | ||
| 119 | + - PARSE_TEST_PROTO | ||
| 120 | + - PARSE_TEXT_PROTO | ||
| 121 | + - ParseTextOrDie | ||
| 122 | + - ParseTextProtoOrDie | ||
| 123 | + CanonicalDelimiter: '' | ||
| 124 | + BasedOnStyle: google | ||
| 125 | +ReflowComments: true | ||
| 126 | +SortUsingDeclarations: true | ||
| 176 | SpaceAfterCStyleCast: false | 127 | SpaceAfterCStyleCast: false |
| 177 | - | ||
| 178 | -# 在Template 关键字后面添加空格 | ||
| 179 | SpaceAfterTemplateKeyword: true | 128 | SpaceAfterTemplateKeyword: true |
| 180 | - | ||
| 181 | -# 在赋值运算符之前添加空格 | ||
| 182 | SpaceBeforeAssignmentOperators: true | 129 | SpaceBeforeAssignmentOperators: true |
| 183 | - | 130 | +SpaceBeforeCpp11BracedList: false |
| 184 | -# SpaceBeforeCpp11BracedList: true | 131 | +SpaceBeforeCtorInitializerColon: true |
| 185 | - | 132 | +SpaceBeforeInheritanceColon: true |
| 186 | -# SpaceBeforeCtorInitializerColon: true | ||
| 187 | - | ||
| 188 | -# SpaceBeforeInheritanceColon: true | ||
| 189 | - | ||
| 190 | -# 开圆括号之前添加一个空格: Never, ControlStatements, Always | ||
| 191 | SpaceBeforeParens: ControlStatements | 133 | SpaceBeforeParens: ControlStatements |
| 192 | - | 134 | +SpaceBeforeRangeBasedForLoopColon: true |
| 193 | -# SpaceBeforeRangeBasedForLoopColon: true | ||
| 194 | - | ||
| 195 | -# 在空的圆括号中添加空格 | ||
| 196 | SpaceInEmptyParentheses: false | 135 | SpaceInEmptyParentheses: false |
| 197 | - | 136 | +SpacesBeforeTrailingComments: 2 |
| 198 | -# 在尾随的评论前添加的空格数(只适用于//) | 137 | +SpacesInAngles: false |
| 199 | -SpacesBeforeTrailingComments: 1 | ||
| 200 | - | ||
| 201 | -# 在尖括号的<后和>前添加空格 | ||
| 202 | -SpacesInAngles: false | ||
| 203 | - | ||
| 204 | -# 在C风格类型转换的括号中添加空格 | ||
| 205 | -SpacesInCStyleCastParentheses: false | ||
| 206 | - | ||
| 207 | -# 在容器(ObjC和JavaScript的数组和字典等)字面量中添加空格 | ||
| 208 | SpacesInContainerLiterals: true | 138 | SpacesInContainerLiterals: true |
| 209 | - | 139 | +SpacesInCStyleCastParentheses: false |
| 210 | -# 在圆括号的(后和)前添加空格 | ||
| 211 | SpacesInParentheses: false | 140 | SpacesInParentheses: false |
| 212 | - | ||
| 213 | -# 在方括号的[后和]前添加空格,lamda表达式和未指明大小的数组的声明不受影响 | ||
| 214 | SpacesInSquareBrackets: false | 141 | SpacesInSquareBrackets: false |
| 142 | +Standard: Auto | ||
| 143 | +StatementMacros: | ||
| 144 | + - Q_UNUSED | ||
| 145 | + - QT_REQUIRE_VERSION | ||
| 146 | +TabWidth: 2 | ||
| 147 | +UseTab: Never | ||
| 148 | +SortIncludes: false | ||
| 149 | +... | ||
| 215 | 150 | ||
| 216 | -# 标准: Cpp03, Cpp11, Auto | ||
| 217 | -Standard: Cpp11 | ||
| 218 | - | ||
| 219 | -# tab宽度 | ||
| 220 | -TabWidth: 4 | ||
| 221 | - | ||
| 222 | -# 使用tab字符: Never, ForIndentation, ForContinuationAndIndentation, Always | ||
| 223 | -UseTab: Never | ||
| @@ -1,18 +1,76 @@ | |||
| 1 | -repos: | 1 | +# --------------------------------------------------------------------------------------------------------- |
| 2 | - - repo: https://github.com/pre-commit/mirrors-clang-format | 2 | +# Copyright (c) 2026 Huawei Technologies Co., Ltd. |
| 3 | - rev: v16.0.0 | 3 | +# This program is free software, you can redistribute it and/or modify it under the terms and conditions of |
| 4 | - hooks: | 4 | +# CANN Open Software License Agreement Version 2.0 (the "License"). |
| 5 | - - id: clang-format | 5 | +# Please refer to the License for details. You may not use this file except in compliance with the License. |
| 6 | - types_or: [c++, c] | 6 | +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, |
| 7 | - | 7 | +# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. |
| 8 | - # OAT compliance check (Open Source Audit Tool) | 8 | +# See LICENSE in the root of the software repository for the full text of the License. |
| 9 | - - repo: local | 9 | +# --------------------------------------------------------------------------------------------------------- |
| 10 | - hooks: | 10 | +minimum_pre_commit_version: 4.0.0 |
| 11 | - - id: oat-check | 11 | +exclude: ^LICENSES/|\.(html|csv|svg)$ |
| 12 | - name: OAT Compliance Check | 12 | + |
| 13 | - entry: bash scripts/oat_check.sh | 13 | +default_stages: [pre-commit] |
| 14 | - language: system | 14 | +ci: |
| 15 | - pass_filenames: true | 15 | + autofix_prs: false |
| 16 | - types: [file] | 16 | + autoupdate_schedule: monthly |
| 17 | - stages: [commit] | 17 | + |
| 18 | - verbose: true | 18 | +repos: |
| 19 | + # pre-commit 基础检查 | ||
| 20 | + - repo: https://gitcode.com/pre-commit/pre-commit-hooks | ||
| 21 | + rev: v4.6.0 | ||
| 22 | + hooks: | ||
| 23 | + - id: trailing-whitespace | ||
| 24 | + - id: end-of-file-fixer | ||
| 25 | + - id: check-yaml | ||
| 26 | + args: ["--allow-multiple-documents"] | ||
| 27 | + - id: check-added-large-files | ||
| 28 | + - id: check-merge-conflict | ||
| 29 | + - id: detect-private-key | ||
| 30 | + - id: check-json | ||
| 31 | + | ||
| 32 | + # C++ 代码格式化检查 | ||
| 33 | + - repo: https://gitcode.com/pre-commit-clang/mirrors-clang-format | ||
| 34 | + rev: v18.1.8 | ||
| 35 | + hooks: | ||
| 36 | + - id: clang-format | ||
| 37 | + files: \.(c|h|cpp|hpp|cc|hh|cxx|hxx|asc)$ | ||
| 38 | + args: | ||
| 39 | + - "--style=file" | ||
| 40 | + - "--verbose" | ||
| 41 | + - "-i" | ||
| 42 | + exclude: ^build/|tests/third_party/ | ||
| 43 | + | ||
| 44 | + # Python 代码检查 | ||
| 45 | + - repo: https://gitcode.com/gh_mirrors/ru/ruff-pre-commit | ||
| 46 | + rev: v0.14.14 | ||
| 47 | + hooks: | ||
| 48 | + - id: ruff-check | ||
| 49 | + args: ["--output-format", "github", "--fix"] | ||
| 50 | + types: [python] | ||
| 51 | + - id: ruff-format | ||
| 52 | + types: [python] | ||
| 53 | + | ||
| 54 | + # 拼写检查 | ||
| 55 | + - repo: https://gitcode.com/gh_mirrors/co/codespell | ||
| 56 | + rev: v2.4.1 | ||
| 57 | + hooks: | ||
| 58 | + - id: codespell | ||
| 59 | + args: [ | ||
| 60 | + "-L", | ||
| 61 | + "CANN,cann,NNAL,nnal,ASCEND,ascend,EnQue,CopyIn,ArchType,AND,ND,tbe,copyin,alog", | ||
| 62 | + "--skip", | ||
| 63 | + "*.py,*.cpp,*.hpp,*.c,*.h", | ||
| 64 | + ] | ||
| 65 | + | ||
| 66 | + # OAT 合规性检查 (Open Source Audit Tool) | ||
| 67 | + - repo: local | ||
| 68 | + hooks: | ||
| 69 | + - id: oat-check | ||
| 70 | + name: OAT Compliance Check | ||
| 71 | + entry: bash scripts/oat_check.sh | ||
| 72 | + language: system | ||
| 73 | + pass_filenames: true | ||
| 74 | + types: [file] | ||
| 75 | + stages: [pre-commit] | ||
| 76 | + verbose: true | ||