已合并
clang-format、pre-commit与devkit仓一致 #58
哈喽Kiter创建于 7月30日
clang-format、pre-commit与devkit仓一致 #58
已合并
共 4 个文件变更+1296-88
| @@ -1,96 +1,71 @@ | |||
| 1 | -Language: Cpp | 1 | +# Usage: |
| 2 | +# Using clang-format to reformat a file: | ||
| 3 | +# clang-format -i -style=Google <file> | ||
| 4 | + | ||
| 5 | +BasedOnStyle: Google | ||
| 6 | +ColumnLimit: 120 | ||
| 2 | AccessModifierOffset: -4 | 7 | AccessModifierOffset: -4 |
| 3 | -AlignConsecutiveAssignments: false | 8 | +SortIncludes: false |
| 4 | -AlignConsecutiveDeclarations: false | 9 | +BreakBeforeBraces: Custom |
| 5 | -AlignEscapedNewlines: DontAlign | 10 | + |
| 11 | +# 大括号换行配置 | ||
| 12 | +BraceWrapping: | ||
| 13 | + AfterCaseLabel: false | ||
| 14 | + AfterClass: false | ||
| 15 | + AfterControlStatement: false | ||
| 16 | + # AfterEnum: false (紧凑模式,左大括号和enum同行, enum Color {...), AfterEnum: true (左大括号和enum换行). | ||
| 17 | + AfterEnum: false | ||
| 18 | + AfterFunction: true | ||
| 19 | + AfterNamespace: false | ||
| 20 | + AfterStruct: false | ||
| 21 | + AfterUnion: false | ||
| 22 | + AfterExternBlock: false | ||
| 23 | + BeforeCatch: false | ||
| 24 | + BeforeElse: false | ||
| 25 | + IndentBraces: false | ||
| 26 | + SplitEmptyFunction: false | ||
| 27 | + SplitEmptyRecord: true | ||
| 28 | + SplitEmptyNamespace: true | ||
| 29 | + | ||
| 30 | +# Align | ||
| 31 | +AlignAfterOpenBracket: AlwaysBreak | ||
| 32 | +AlignEscapedNewlines: Left | ||
| 6 | AlignOperands: true | 33 | AlignOperands: true |
| 7 | AlignTrailingComments: true | 34 | AlignTrailingComments: true |
| 8 | AllowAllArgumentsOnNextLine: true | 35 | AllowAllArgumentsOnNextLine: true |
| 9 | -AllowShortLambdasOnASingleLine: Empty | 36 | +AllowAllParametersOfDeclarationOnNextLine: true |
| 10 | -AllowAllParametersOfDeclarationOnNextLine: false | 37 | +AlwaysBreakBeforeMultilineStrings: false |
| 38 | +AlwaysBreakTemplateDeclarations: true | ||
| 39 | +AttributeMacros: | ||
| 40 | + - __global__ | ||
| 41 | + - __aicore__ | ||
| 42 | + - __cube__ | ||
| 43 | + - __vector__ | ||
| 44 | + - __mix__ | ||
| 45 | + - __host__ | ||
| 46 | + - __aicpu__ | ||
| 47 | + - __simd_vf__ | ||
| 48 | + - __simt_vf__ | ||
| 49 | + - __gm__ | ||
| 50 | + - __ubuf__ | ||
| 51 | + - __kfc_workspace__ | ||
| 52 | + | ||
| 53 | +BinPackArguments: true | ||
| 54 | +BreakBeforeTernaryOperators: false | ||
| 55 | +SpacesBeforeTrailingComments: 1 | ||
| 56 | + | ||
| 57 | +# poniter aligment | ||
| 58 | +DerivePointerAlignment: false | ||
| 59 | +PointerAlignment: Left | ||
| 60 | + | ||
| 61 | +# single line layout | ||
| 11 | AllowShortBlocksOnASingleLine: false | 62 | AllowShortBlocksOnASingleLine: false |
| 12 | AllowShortCaseLabelsOnASingleLine: false | 63 | AllowShortCaseLabelsOnASingleLine: false |
| 13 | -AllowShortFunctionsOnASingleLine: false | 64 | +AllowShortFunctionsOnASingleLine: true |
| 14 | AllowShortIfStatementsOnASingleLine: false | 65 | AllowShortIfStatementsOnASingleLine: false |
| 15 | AllowShortLoopsOnASingleLine: false | 66 | AllowShortLoopsOnASingleLine: false |
| 16 | -AlwaysBreakAfterDefinitionReturnType: None | ||
| 17 | -AlwaysBreakBeforeMultilineStrings: false | ||
| 18 | -AlwaysBreakTemplateDeclarations: MultiLine | ||
| 19 | -BinPackArguments: true | ||
| 20 | -BinPackParameters: true | ||
| 21 | -AlignAfterOpenBracket: DontAlign | ||
| 22 | 67 | ||
| 23 | -BraceWrapping: | 68 | +# tab space |
| 24 | - AfterCaseLabel: false | ||
| 25 | - AfterClass: false | ||
| 26 | - AfterControlStatement: Never | ||
| 27 | - AfterEnum: false | ||
| 28 | - AfterFunction: true | ||
| 29 | - AfterNamespace: false | ||
| 30 | - AfterStruct: false | ||
| 31 | - AfterUnion: false | ||
| 32 | - AfterExternBlock: false | ||
| 33 | - BeforeCatch: false | ||
| 34 | - BeforeElse: false | ||
| 35 | - IndentBraces: false | ||
| 36 | - SplitEmptyFunction: true | ||
| 37 | - SplitEmptyRecord: true | ||
| 38 | - SplitEmptyNamespace: true | ||
| 39 | - | ||
| 40 | -BreakBeforeBinaryOperators: All | ||
| 41 | -BreakBeforeBraces: Custom | ||
| 42 | -BreakBeforeTernaryOperators: true | ||
| 43 | -BreakConstructorInitializersBeforeComma: false | ||
| 44 | -BreakInheritanceList: AfterColon | ||
| 45 | -ColumnLimit: 120 | ||
| 46 | -CommentPragmas: '^ IWYU pragma:' | ||
| 47 | -PackConstructorInitializers: CurrentLine | ||
| 48 | -ConstructorInitializerIndentWidth: 4 | ||
| 49 | -ContinuationIndentWidth: 4 | ||
| 50 | -Cpp11BracedListStyle: true | ||
| 51 | -DerivePointerAlignment: false | ||
| 52 | -DisableFormat: false | ||
| 53 | -ExperimentalAutoDetectBinPacking: false | ||
| 54 | -ForEachMacros: [ foreach ] | ||
| 55 | - | ||
| 56 | -IncludeCategories: | ||
| 57 | - - Regex: '^<' | ||
| 58 | - Priority: 3 | ||
| 59 | - - Regex: '^"hccl' | ||
| 60 | - Priority: 2 | ||
| 61 | - - Regex: '.*' | ||
| 62 | - Priority: 1 | ||
| 63 | - | ||
| 64 | -IndentCaseLabels: true | ||
| 65 | -IndentWidth: 4 | ||
| 66 | -IndentWrappedFunctionNames: false | ||
| 67 | -KeepEmptyLinesAtTheStartOfBlocks: false | ||
| 68 | -MacroBlockBegin: '' | ||
| 69 | -MacroBlockEnd: '' | ||
| 70 | -MaxEmptyLinesToKeep: 1 | ||
| 71 | -NamespaceIndentation: Inner | ||
| 72 | - | ||
| 73 | -PenaltyBreakBeforeFirstCallParameter: 19 | ||
| 74 | -PenaltyBreakComment: 300 | ||
| 75 | -PenaltyBreakFirstLessLess: 120 | ||
| 76 | -PenaltyBreakString: 1000 | ||
| 77 | -PenaltyExcessCharacter: 1000000 | ||
| 78 | -PenaltyReturnTypeOnItsOwnLine: 60 | ||
| 79 | - | ||
| 80 | -PointerAlignment: Right | ||
| 81 | -ReflowComments: true | ||
| 82 | -SortIncludes: false | ||
| 83 | -SpaceAfterCStyleCast: false | ||
| 84 | -SpaceBeforeAssignmentOperators: true | ||
| 85 | -SpaceBeforeParens: ControlStatements | ||
| 86 | -SpaceInEmptyParentheses: false | ||
| 87 | -SpacesBeforeTrailingComments: 1 | ||
| 88 | -SpacesInAngles: false | ||
| 89 | -SpacesInContainerLiterals: true | ||
| 90 | -SpacesInCStyleCastParentheses: false | ||
| 91 | -SpacesInParentheses: false | ||
| 92 | -SpacesInSquareBrackets: false | ||
| 93 | -Standard: Latest | ||
| 94 | -TabWidth: 4 | ||
| 95 | UseTab: Never | 69 | UseTab: Never |
| 96 | -UseCRLF: false | 70 | +IndentWidth: 4 |
| 71 | +TabWidth: 4 | ||
| @@ -1,11 +1,68 @@ | |||
| 1 | +minimum_pre_commit_version: 4.0.0 | ||
| 2 | +exclude: ^LICENSES/|\.(html|csv|svg|tsv)$ | ||
| 3 | + | ||
| 4 | +default_stages: [pre-commit] | ||
| 5 | +ci: | ||
| 6 | + autofix_prs: false | ||
| 7 | + autoupdate_schedule: monthly | ||
| 8 | + | ||
| 1 | repos: | 9 | repos: |
| 10 | + # pre-commit 基础检查 | ||
| 11 | + - repo: https://gitcode.com/pre-commit/pre-commit-hooks | ||
| 12 | + rev: v4.6.0 | ||
| 13 | + hooks: | ||
| 14 | + - id: trailing-whitespace | ||
| 15 | + exclude: \.md$ | ||
| 16 | + - id: end-of-file-fixer | ||
| 17 | + exclude: \.md$ | ||
| 18 | + - id: check-yaml | ||
| 19 | + args: ["--allow-multiple-documents"] | ||
| 20 | + - id: check-added-large-files | ||
| 21 | + - id: check-merge-conflict | ||
| 22 | + - id: detect-private-key | ||
| 23 | + - id: check-json | ||
| 24 | + exclude: ^\.devcontainer/devcontainer\.json$ | ||
| 25 | + | ||
| 26 | + # C++ 代码格式化检查 | ||
| 2 | - repo: https://gitcode.com/pre-commit-clang/mirrors-clang-format | 27 | - repo: https://gitcode.com/pre-commit-clang/mirrors-clang-format |
| 3 | rev: v18.1.8 | 28 | rev: v18.1.8 |
| 4 | hooks: | 29 | hooks: |
| 5 | - id: clang-format | 30 | - id: clang-format |
| 6 | - types_or: [c++, c] | 31 | + types_or: [file] |
P | |||
| 32 | + files: \.(c|h|cpp|hpp|cc|hh|cxx|hxx|asc)$ | ||
| 33 | + args: | ||
| 34 | + - "--style=file" | ||
| 35 | + - "--verbose" | ||
| 36 | + - "-i" | ||
| 7 | 37 | ||
| 8 | - # OAT compliance check (Open Source Audit Tool) | 38 | + # Python 代码检查 |
| 39 | + - repo: https://gitcode.com/gh_mirrors/ru/ruff-pre-commit | ||
| 40 | + rev: v0.14.14 | ||
| 41 | + hooks: | ||
| 42 | + - id: ruff-check | ||
| 43 | + args: | ||
| 44 | + - "--output-format" | ||
| 45 | + - "github" | ||
| 46 | + - "--fix" | ||
| 47 | + - "--extend-ignore" | ||
| 48 | + - "E402,E711,E712,E721,F401,F403,F405,F811,F821,F841,F523,E741,F601" | ||
| 49 | + types: [python] | ||
| 50 | + - id: ruff-format | ||
| 51 | + types: [python] | ||
| 52 | + | ||
| 53 | + # 拼写检查 | ||
| 54 | + - repo: https://gitcode.com/gh_mirrors/co/codespell | ||
| 55 | + rev: v2.4.1 | ||
| 56 | + hooks: | ||
| 57 | + - id: codespell | ||
| 58 | + args: [ | ||
| 59 | + "-L", | ||
| 60 | + "CANN,cann,NNAL,nnal,ASCEND,ascend,EnQue,CopyIn,ArchType,AND,ND,tbe,copyin,alog,Collet,Enque,Normale,OUTTER,OffsetT,REGIST,Te,ThirdParty,VOR,abl,ans,catched,commiter,devlop,dout,enque,ges,nIn,nd,outter,padd,parm,subtile", | ||
| 61 | + "--skip", | ||
| 62 | + "*.py,*.cpp,*.hpp,*.c,*.h,*.asc,*.cc", | ||
| 63 | + ] | ||
| 64 | + | ||
| 65 | + # OAT 合规性检查 (Open Source Audit Tool) | ||
| 9 | - repo: local | 66 | - repo: local |
| 10 | hooks: | 67 | hooks: |
| 11 | - id: oat-check | 68 | - id: oat-check |
| @@ -16,3 +73,17 @@ repos: | |||
| 16 | types: [file] | 73 | types: [file] |
| 17 | stages: [pre-commit] | 74 | stages: [pre-commit] |
| 18 | verbose: true | 75 | verbose: true |
| 76 | + | ||
| 77 | + # Markdown 链接有效性检查 | ||
| 78 | + - repo: local | ||
| 79 | + hooks: | ||
| 80 | + - id: markdown-link-check | ||
| 81 | + name: Markdown link check | ||
| 82 | + entry: env LYCHEE_VERSION=0.23.0 bash scripts/markdown_link_check.sh | ||
| 83 | + language: system | ||
| 84 | + files: \.(md|markdown|mdx)$ | ||
| 85 | + exclude: ^CHANGELOG(_en)?\.md$ | ||
| 86 | + pass_filenames: true | ||
| 87 | + always_run: true | ||
| 88 | + stages: [pre-commit, manual] | ||
| 89 | + verbose: true | ||
| @@ -0,0 +1,51 @@ | |||
| 1 | +# ---------------------------------------------------------------------------------------------------------- | ||
| 2 | +# Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | +# This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | +# CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 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 | +# Markdown link checker configuration for lychee. | ||
| 12 | +# The hook runs during pre-commit and can also be invoked manually for full docs/examples scans. | ||
| 13 | + | ||
| 14 | +verbose = "warn" | ||
| 15 | +no_progress = true | ||
| 16 | + | ||
| 17 | +max_redirects = 10 | ||
| 18 | +max_retries = 2 | ||
| 19 | +retry_wait_time = 2 | ||
| 20 | +timeout = 20 | ||
| 21 | +max_concurrency = 16 | ||
| 22 | +method = "get" | ||
| 23 | + | ||
| 24 | +# 429 is usually a rate-limit response from public documentation or code-hosting | ||
| 25 | +# sites. Keep it non-blocking so one busy host does not fail an unrelated push. | ||
| 26 | +accept = ["200..=299", "429"] | ||
| 27 | + | ||
| 28 | +hidden = true | ||
| 29 | +include_verbatim = false | ||
| 30 | +include_mail = false | ||
| 31 | +# include_fragments = "anchor-only" | ||
| 32 | +extensions = ["md", "markdown", "mdx"] | ||
| 33 | + | ||
| 34 | +exclude_loopback = true | ||
| 35 | +exclude_link_local = true | ||
| 36 | +exclude_private = true | ||
| 37 | + | ||
| 38 | +exclude = [ | ||
| 39 | + "^https://gitee\\.com/ascend/samples/tree/master/operator/ascendc$", | ||
| 40 | + "^https://gitee\\.com/ascend/samples/tree/master/operator/ascendc/0_introduction/3_add_kernellaunch/AddKernelInvocationNeo$", | ||
| 41 | + "^https://gitee\\.com/ascend/ascendc-api-adv/tree/master/examples$", | ||
| 42 | + "^https://github\\.com/ImageMagick/ImageMagick-Windows/releases$", | ||
| 43 | + "^https://docs\\.docker\\.com/$", | ||
| 44 | + "^https://docs\\.docker\\.com/reference/cli/docker/buildx/$", | ||
| 45 | + "^https://ccache\\.dev/documentation\\.html$", | ||
| 46 | +] | ||
| 47 | + | ||
| 48 | +exclude_path = [ | ||
| 49 | + "^tests/api/adv_api/hccl/cc/st/algorithm/README\\.md$", | ||
| 50 | + "^tests/api/adv_api/hccl/cc/st/algorithm/README_en\\.md$", | ||
| 51 | +] | ||
devkit exclude这个修改不需要同步过来