已合并
chore: align format and pre-commit configs #686
chore: align format and pre-commit configs #686
已合并
ling-DT创建于 6月5日
2 个文件变更+194-209
M.clang-format+118-191
@@ -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 of3+# 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(总是在开括号后换行)
19AlignAfterOpenBracket: Align5AlignAfterOpenBracket: Align
20- 
21-# 连续赋值时,对齐所有等号
22AlignConsecutiveAssignments: false6AlignConsecutiveAssignments: false
23- 
24-# 连续声明时,对齐所有声明的变量名
25AlignConsecutiveDeclarations: false7AlignConsecutiveDeclarations: false
26- 8+AlignEscapedNewlines: Left
27-# 右对齐逃脱换行(使用反斜杠换行)的反斜杠9+AlignOperands: true
28-AlignEscapedNewlines: Right
29- 
30-# 水平对齐二元和三元表达式的操作数
31-AlignOperands: true
32- 
33-# 对齐连续的尾随的注释
34AlignTrailingComments: true10AlignTrailingComments: true
35- 11+AllowAllParametersOfDeclarationOnNextLine: true
36-# 不允许函数声明的所有参数在放在下一行12+AllowShortBlocksOnASingleLine: false
37-AllowAllParametersOfDeclarationOnNextLine: false
38- 
39-# 不允许短的块放在同一行
40-AllowShortBlocksOnASingleLine: true
41- 
42-# 允许短的case标签放在同一行
43AllowShortCaseLabelsOnASingleLine: false13AllowShortCaseLabelsOnASingleLine: false
44- 
45-# 允许短的函数放在同一行: None, InlineOnly(定义在类中), Empty(空函数), Inline(定义在类中,空函数), All
46AllowShortFunctionsOnASingleLine: Empty14AllowShortFunctionsOnASingleLine: Empty
47- 15+AllowShortIfStatementsOnASingleLine: true
48-# 允许短的if语句保持在同一行16+AllowShortLoopsOnASingleLine: true
49-AllowShortIfStatementsOnASingleLine: false17+AlwaysBreakAfterDefinitionReturnType: None
50- 
51-# 禁止将短的循环体(如单行语句)放在同一行
52-AllowShortLoopsOnASingleLine: false
53- 
54-# 总是在返回类型后换行: None, All, TopLevel(顶级函数,不包括在类中的函数),
55-# AllDefinitions(所有的定义,不包括声明), TopLevelDefinitions(所有的顶级函数的定义)
56AlwaysBreakAfterReturnType: None18AlwaysBreakAfterReturnType: None
57- 19+AlwaysBreakBeforeMultilineStrings: true
58-# 总是在多行string字面量前换行20+AlwaysBreakTemplateDeclarations: Yes
59-AlwaysBreakBeforeMultilineStrings: false
60- 
61-# 总是在template声明后换行
62-AlwaysBreakTemplateDeclarations: true
63- 
64-# false表示函数实参要么都在同一行,要么都各自一行
65BinPackArguments: true21BinPackArguments: true
66- 
67-# false表示所有形参要么都在同一行,要么都各自一行
68BinPackParameters: true22BinPackParameters: true
69- 
70-# 大括号换行,只有当BreakBeforeBraces设置为Custom时才有效
71BraceWrapping:23BraceWrapping:
72- # class定义后面24+ AfterClass: false
73- AfterClass: false
74- # 控制语句后面
75 AfterControlStatement: false25 AfterControlStatement: false
76- # enum定义后面26+ AfterEnum: false
77- AfterEnum: false27+ AfterFunction: false
78- # 函数定义后面28+ AfterNamespace: false
79- AfterFunction: true29+ AfterObjCDeclaration: false
80- # 命名空间定义后面30+ AfterStruct: false
81- AfterNamespace: false31+ AfterUnion: false
82- # struct定义后面
83- AfterStruct: false
84- # union定义后面
85- AfterUnion: false
86- # extern之后
87 AfterExternBlock: false32 AfterExternBlock: false
88- # catch之前33+ BeforeCatch: false
89- BeforeCatch: false34+ BeforeElse: false
90- # else之前35+ IndentBraces: false
91- BeforeElse: false36+ SplitEmptyFunction: true
92- # 缩进大括号37+ SplitEmptyRecord: true
93- IndentBraces: false38+ SplitEmptyNamespace: true
94- # 分离空函数39+BreakBeforeBinaryOperators: None
95- SplitEmptyFunction: false40+BreakBeforeBraces: Attach
96- # 分离空语句41+BreakBeforeInheritanceComma: false
97- SplitEmptyRecord: false42+BreakInheritanceList: BeforeColon
98- # 分离空命名空间43+BreakBeforeTernaryOperators: true
99- SplitEmptyNamespace: false44+BreakConstructorInitializersBeforeComma: false
100- 45+BreakConstructorInitializers: BeforeColon
101-# 在二元运算符前换行: None(在操作符后换行), NonAssignment(在非赋值的操作符前换行), All(在操作符前换行)46+BreakAfterJavaFieldAnnotations: false
102-BreakBeforeBinaryOperators: NonAssignment47+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- 
123CompactNamespaces: false50CompactNamespaces: false
124- 51+ConstructorInitializerAllOnOneLineOrOnePerLine: true
125-# 构造函数的初始化列表要么都在同一行,要么都各自一行
126-ConstructorInitializerAllOnOneLineOrOnePerLine: false
127- 
128-# 构造函数的初始化列表的缩进宽度
129ConstructorInitializerIndentWidth: 452ConstructorInitializerIndentWidth: 4
130- 
131-# 延续的行的缩进宽度
132ContinuationIndentWidth: 453ContinuationIndentWidth: 4
133- 
134-# 去除C++11的列表初始化的大括号{后和}前的空格
135Cpp11BracedListStyle: true54Cpp11BracedListStyle: true
136- 55+DisableFormat: false
137-# 继承最常用的指针和引用的对齐方式56+ExperimentalAutoDetectBinPacking: false
138-DerivePointerAlignment: false
139- 
140-# 固定命名空间注释
141FixNamespaceComments: true57FixNamespaceComments: 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))?$'
144IndentCaseLabels: true73IndentCaseLabels: true
145- 
146IndentPPDirectives: None74IndentPPDirectives: None
147- 75+IndentWidth: 2
148-# 缩进宽度
149-IndentWidth: 4
150- 
151-# 函数返回类型换行时,缩进函数声明或函数定义的函数名
152IndentWrappedFunctionNames: false76IndentWrappedFunctionNames: false
153- 77+JavaScriptQuotes: Leave
154-# 保留在块开始处的空行78+JavaScriptWrapImports: true
155KeepEmptyLinesAtTheStartOfBlocks: false79KeepEmptyLinesAtTheStartOfBlocks: false
156- 80+MacroBlockBegin: ''
157-# 连续空行的最大数量81+MacroBlockEnd: ''
158MaxEmptyLinesToKeep: 182MaxEmptyLinesToKeep: 1
159- 
160-# 命名空间的缩进: None, Inner(缩进嵌套的命名空间中的内容), All
161NamespaceIndentation: None83NamespaceIndentation: None
162- 84+ObjCBinPackProtocolList: Never
163-# 指针和引用的对齐: Left, Right, Middle85+ObjCBlockIndentWidth: 2
164-PointerAlignment: Left86+ObjCSpaceAfterProperty: false
165- 87+ObjCSpaceBeforeProtocolList: true
166-# 允许重新排版注释88+PenaltyBreakAssignment: 2
167-ReflowComments: true89+PenaltyBreakBeforeFirstCallParameter: 1
168- 90+PenaltyBreakComment: 300
169-# 允许排序#include91+PenaltyBreakFirstLessLess: 120
170-SortIncludes: false92+PenaltyBreakString: 1000
171- 93+PenaltyBreakTemplateDeclaration: 10
172-# 允许排序 using 声明94+PenaltyExcessCharacter: 1000000
173-SortUsingDeclarations: false95+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
176SpaceAfterCStyleCast: false127SpaceAfterCStyleCast: false
177- 
178-# 在Template 关键字后面添加空格
179SpaceAfterTemplateKeyword: true128SpaceAfterTemplateKeyword: true
180- 
181-# 在赋值运算符之前添加空格
182SpaceBeforeAssignmentOperators: true129SpaceBeforeAssignmentOperators: true
183- 130+SpaceBeforeCpp11BracedList: false
184-# SpaceBeforeCpp11BracedList: true131+SpaceBeforeCtorInitializerColon: true
185- 132+SpaceBeforeInheritanceColon: true
186-# SpaceBeforeCtorInitializerColon: true
187- 
188-# SpaceBeforeInheritanceColon: true
189- 
190-# 开圆括号之前添加一个空格: Never, ControlStatements, Always
191SpaceBeforeParens: ControlStatements133SpaceBeforeParens: ControlStatements
192- 134+SpaceBeforeRangeBasedForLoopColon: true
193-# SpaceBeforeRangeBasedForLoopColon: true
194- 
195-# 在空的圆括号中添加空格
196SpaceInEmptyParentheses: false135SpaceInEmptyParentheses: 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的数组和字典等)字面量中添加空格
208SpacesInContainerLiterals: true138SpacesInContainerLiterals: true
209- 139+SpacesInCStyleCastParentheses: false
210-# 在圆括号的(后和)前添加空格
211SpacesInParentheses: false140SpacesInParentheses: false
212- 
213-# 在方括号的[后和]前添加空格,lamda表达式和未指明大小的数组的声明不受影响
214SpacesInSquareBrackets: false141SpacesInSquareBrackets: 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
M.pre-commit-config.yaml+76-18
@@ -1,18 +1,76 @@
1-repos:1+# ---------------------------------------------------------------------------------------------------------
2- - repo: https://github.com/pre-commit/mirrors-clang-format2+# Copyright (c) 2026 Huawei Technologies Co., Ltd.
3- rev: v16.0.03+# 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-format5+# 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: local9+# ---------------------------------------------------------------------------------------------------------
10- hooks:10+minimum_pre_commit_version: 4.0.0
11- - id: oat-check11+exclude: ^LICENSES/|\.(html|csv|svg)$
12- name: OAT Compliance Check12+ 
13- entry: bash scripts/oat_check.sh13+default_stages: [pre-commit]
14- language: system14+ci:
15- pass_filenames: true15+ autofix_prs: false
16- types: [file]16+ autoupdate_schedule: monthly
17- stages: [commit]17+ 
18- verbose: true18+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