@chengzhao-dev/dsh-cpp-workflow 0.6.19 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +11 -26
- package/README.md +13 -28
- package/cordis.patch.yml +1 -1
- package/lib/client.js +33 -21
- package/lib/comment-policy.js +15 -6
- package/lib/index.js +1 -1
- package/lib/workspace.js +0 -15
- package/package.json +7 -7
- package/skills/building-cpp/SKILL.md +34 -21
- package/skills/building-cpp/assets/templates/projects/common/running-build.sh +5 -1
- package/skills/building-cpp/project/vscode/01-extensions.md +28 -0
- package/skills/building-cpp/project/vscode/02-settings.md +39 -0
- package/skills/building-cpp/references/build-script.md +14 -7
- package/skills/building-cpp/references/environment.md +8 -1
- package/skills/building-cpp/steps/01-build.md +8 -8
- package/skills/building-cpp/steps/02-tooling.md +17 -9
- package/skills/building-cpp/steps/03-check.md +16 -14
- package/skills/developing-cpp/SKILL.md +37 -25
- package/skills/developing-cpp/references/comments/comment-rules.md +181 -0
- package/skills/developing-cpp/references/comments/comment-style.md +80 -0
- package/skills/developing-cpp/references/comments/examples/declaration-class.md +66 -0
- package/skills/developing-cpp/references/comments/examples/declaration-constructor.md +22 -0
- package/skills/developing-cpp/references/comments/examples/declaration-enum.md +48 -0
- package/skills/developing-cpp/references/comments/examples/declaration-file.md +66 -0
- package/skills/developing-cpp/references/comments/examples/declaration-function.md +127 -0
- package/skills/developing-cpp/references/comments/examples/declaration-member.md +23 -0
- package/skills/developing-cpp/references/comments/examples/declaration-predicate.md +14 -0
- package/skills/developing-cpp/references/comments/examples/declaration-struct.md +18 -0
- package/skills/developing-cpp/references/comments/examples/implementation-body.md +64 -0
- package/skills/developing-cpp/references/comments/examples/implementation-todo.md +16 -0
- package/skills/developing-cpp/references/comments/glossary/comment-terms.md +93 -0
- package/skills/developing-cpp/references/design/examples/behavior-sentence.md +14 -0
- package/skills/developing-cpp/references/design/examples/coordinate-table.md +31 -0
- package/skills/developing-cpp/references/design/examples/header-place.md +26 -0
- package/skills/developing-cpp/references/design/examples/library-boundary.md +30 -0
- package/skills/developing-cpp/references/design/examples/library-split.md +7 -0
- package/skills/developing-cpp/references/design/examples/move-result.md +39 -0
- package/skills/developing-cpp/references/design/examples/preview-read.md +40 -0
- package/skills/developing-cpp/references/{project-design.md → design/project-design.md} +57 -5
- package/skills/developing-cpp/references/{change-model.md → editing/01-edit-operations.md} +5 -3
- package/skills/developing-cpp/references/{priority.md → editing/02-rule-priority.md} +2 -2
- package/skills/developing-cpp/references/exceptions/examples/throw-boundary.md +28 -0
- package/skills/developing-cpp/references/exceptions/examples/throw-build-mode.md +38 -0
- package/skills/developing-cpp/references/exceptions/examples/throw-catch.md +21 -0
- package/skills/developing-cpp/references/exceptions/examples/throw-destructor.md +21 -0
- package/skills/developing-cpp/references/exceptions/examples/throw-format.md +13 -0
- package/skills/developing-cpp/references/exceptions/examples/throw-message.md +16 -0
- package/skills/developing-cpp/references/exceptions/examples/throw-when.md +27 -0
- package/skills/developing-cpp/references/{exceptions.md → exceptions/throw-rules.md} +78 -23
- package/skills/developing-cpp/references/{glossary.md → language/glossary/language-terms.md} +2 -2
- package/skills/developing-cpp/references/language/language-basics/01-objects.md +15 -0
- package/skills/developing-cpp/references/language/language-basics/02-initialization.md +26 -0
- package/skills/developing-cpp/references/language/language-basics/03-deduction.md +12 -0
- package/skills/developing-cpp/references/language/language-basics/04-const.md +25 -0
- package/skills/developing-cpp/references/language/language-basics/05-expressions.md +23 -0
- package/skills/developing-cpp/references/language/language-basics/06-functions.md +15 -0
- package/skills/developing-cpp/references/language/language-basics/07-classes.md +15 -0
- package/skills/developing-cpp/references/language/language-basics/08-raii.md +15 -0
- package/skills/developing-cpp/references/language/language-basics/09-templates.md +26 -0
- package/skills/developing-cpp/references/language/language-basics/10-checklist.md +10 -0
- package/skills/developing-cpp/references/language/performance/01-measure.md +22 -0
- package/skills/developing-cpp/references/language/performance/02-complexity.md +13 -0
- package/skills/developing-cpp/references/language/performance/03-memory.md +14 -0
- package/skills/developing-cpp/references/language/performance/04-undefined-behavior.md +28 -0
- package/skills/developing-cpp/references/language/performance/05-pitfalls.md +17 -0
- package/skills/developing-cpp/references/language/performance/06-false-optimizations.md +13 -0
- package/skills/developing-cpp/references/language/performance/07-checklist.md +8 -0
- package/skills/developing-cpp/references/language/standard-library/01-containers.md +29 -0
- package/skills/developing-cpp/references/language/standard-library/02-access.md +14 -0
- package/skills/developing-cpp/references/language/standard-library/03-iteration.md +18 -0
- package/skills/developing-cpp/references/language/standard-library/04-algorithms.md +26 -0
- package/skills/developing-cpp/references/language/standard-library/05-string.md +13 -0
- package/skills/developing-cpp/references/language/standard-library/06-format.md +106 -0
- package/skills/developing-cpp/references/language/standard-library/07-time.md +13 -0
- package/skills/developing-cpp/references/language/standard-library/08-random.md +13 -0
- package/skills/developing-cpp/references/language/standard-library/09-files.md +14 -0
- package/skills/developing-cpp/references/language/standard-library/10-checklist.md +9 -0
- package/skills/developing-cpp/references/language/value-types/01-width.md +17 -0
- package/skills/developing-cpp/references/language/value-types/02-signed.md +26 -0
- package/skills/developing-cpp/references/language/value-types/03-integer-roles.md +38 -0
- package/skills/developing-cpp/references/language/value-types/04-enum.md +24 -0
- package/skills/developing-cpp/references/language/value-types/05-strong-type.md +17 -0
- package/skills/developing-cpp/references/language/value-types/06-const-method.md +22 -0
- package/skills/developing-cpp/references/language/value-types/07-nodiscard.md +15 -0
- package/skills/developing-cpp/references/language/value-types/08-comparison.md +10 -0
- package/skills/developing-cpp/references/language/value-types/09-subscript.md +15 -0
- package/skills/developing-cpp/references/language/value-types/10-float-bool.md +13 -0
- package/skills/developing-cpp/references/language/value-types/11-checklist.md +8 -0
- package/skills/developing-cpp/references/{layout.md → layout/01-source-layout.md} +10 -4
- package/skills/developing-cpp/references/{file-template.md → layout/02-file-template.md} +10 -4
- package/skills/developing-cpp/references/layout/03-declaration-order.md +138 -0
- package/skills/developing-cpp/references/naming/examples/naming-accessor.md +17 -0
- package/skills/developing-cpp/references/naming/examples/naming-basic.md +3 -0
- package/skills/developing-cpp/references/naming/examples/naming-current-prefix.md +19 -0
- package/skills/developing-cpp/references/naming/examples/naming-lookup.md +18 -0
- package/skills/developing-cpp/references/naming/examples/naming-lower-layer.md +39 -0
- package/skills/developing-cpp/references/naming/examples/naming-multiple-return.md +20 -0
- package/skills/developing-cpp/references/naming/examples/naming-player-value.md +16 -0
- package/skills/developing-cpp/references/naming/examples/naming-predicate.md +18 -0
- package/skills/developing-cpp/references/naming/examples/naming-rename.md +5 -0
- package/skills/developing-cpp/references/naming/examples/naming-responsibility.md +19 -0
- package/skills/developing-cpp/references/naming/examples/naming-role.md +21 -0
- package/skills/developing-cpp/references/naming/examples/naming-state-change.md +57 -0
- package/skills/developing-cpp/references/{naming.md → naming/identifier-names.md} +37 -9
- package/skills/developing-cpp/references/{google-cpp-style.md → style/google-cpp-style.md} +11 -10
- package/skills/developing-cpp/scripts/checking-comments.mjs +71 -14
- package/skills/developing-cpp/scripts/checking-declaration-order.mjs +357 -0
- package/skills/developing-cpp/steps/01-behavior.md +5 -5
- package/skills/developing-cpp/steps/02-boundary.md +10 -10
- package/skills/developing-cpp/steps/03-declaration.md +16 -14
- package/skills/developing-cpp/steps/04-implementation.md +21 -17
- package/skills/engineering/SKILL.md +87 -0
- package/skills/{configuring-cmake/assets/cmake → engineering/references/cmake/assets}/CompileSettings.cmake +2 -0
- package/skills/{building-cpp/references/linking.md → engineering/references/cmake/linking/01-libraries.md} +7 -48
- package/skills/engineering/references/cmake/linking/02-rpath.md +25 -0
- package/skills/engineering/references/cmake/linking/03-undefined-reference.md +20 -0
- package/skills/engineering/references/cmake/linking/04-inspect.md +21 -0
- package/skills/{configuring-cmake/references/modules.md → engineering/references/cmake/modules/functions.md} +8 -5
- package/skills/{configuring-cmake/references → engineering/references/cmake/standard}/cxx-standard.md +5 -4
- package/skills/engineering/references/cmake/standard/examples/standard.md +19 -0
- package/skills/{building-cpp/references → engineering/references/cmake/standard}/standards/README.md +9 -9
- package/skills/{building-cpp/references → engineering/references/cmake/standard}/standards/c++20/README.md +1 -1
- package/skills/engineering/references/cmake/targets/examples/glob.md +22 -0
- package/skills/engineering/references/cmake/targets/examples/rpath.md +24 -0
- package/skills/{configuring-cmake/examples/cmake.md → engineering/references/cmake/targets/examples/target.md} +2 -70
- package/skills/{configuring-cmake/references/cmake.md → engineering/references/cmake/targets/rules.md} +18 -11
- package/skills/{building-cpp/references/testing.md → engineering/references/cmake/testing/ctest.md} +11 -4
- package/skills/{building-cpp/references/encoding.md → engineering/references/formatting/01-encoding.md} +1 -1
- package/skills/engineering/references/formatting/02-clang-format.md +20 -0
- package/skills/engineering/references/formatting/03-clang-tidy.md +58 -0
- package/skills/engineering/references/formatting/04-clangd.md +90 -0
- package/skills/engineering/references/formatting/examples/clang-format.md +38 -0
- package/skills/engineering/references/formatting/examples/clang-tidy.md +43 -0
- package/skills/{building-cpp/examples/tooling.md → engineering/references/formatting/examples/clangd.md} +1 -80
- package/skills/{configuring-cmake → engineering}/steps/01-targets.md +6 -6
- package/skills/{configuring-cmake → engineering}/steps/02-modules.md +4 -4
- package/skills/{configuring-cmake → engineering}/steps/03-check.md +3 -2
- package/templates/cpp-workflow-project/SKILL.md +1 -1
- package/skills/building-cpp/references/static-analysis.md +0 -148
- package/skills/configuring-cmake/SKILL.md +0 -68
- package/skills/developing-cpp/examples/comments-declaration.md +0 -313
- package/skills/developing-cpp/examples/comments-implementation.md +0 -66
- package/skills/developing-cpp/examples/exceptions.md +0 -173
- package/skills/developing-cpp/examples/naming.md +0 -168
- package/skills/developing-cpp/examples/structure.md +0 -194
- package/skills/developing-cpp/references/comment-terms.md +0 -75
- package/skills/developing-cpp/references/comments.md +0 -223
- package/skills/developing-cpp/references/declaration-order.md +0 -118
- package/skills/developing-cpp/references/language.md +0 -123
- package/skills/developing-cpp/references/performance.md +0 -83
- package/skills/developing-cpp/references/standard-library.md +0 -138
- package/skills/developing-cpp/references/types.md +0 -154
- /package/skills/{configuring-cmake/assets/cmake → engineering/references/cmake/assets}/LinkSettings.cmake +0 -0
- /package/skills/{building-cpp/references → engineering/references/cmake/standard}/standards/c++11/README.md +0 -0
- /package/skills/{building-cpp/references → engineering/references/cmake/standard}/standards/c++11/cmake-snippet.cmake +0 -0
- /package/skills/{building-cpp/references → engineering/references/cmake/standard}/standards/c++14/README.md +0 -0
- /package/skills/{building-cpp/references → engineering/references/cmake/standard}/standards/c++14/cmake-snippet.cmake +0 -0
- /package/skills/{building-cpp/references → engineering/references/cmake/standard}/standards/c++17/README.md +0 -0
- /package/skills/{building-cpp/references → engineering/references/cmake/standard}/standards/c++17/cmake-snippet.cmake +0 -0
- /package/skills/{building-cpp/references → engineering/references/cmake/standard}/standards/c++20/cmake-snippet.cmake +0 -0
- /package/skills/{building-cpp/references → engineering/references/cmake/standard}/standards/c++23/README.md +0 -0
- /package/skills/{building-cpp/references → engineering/references/cmake/standard}/standards/c++23/cmake-snippet.cmake +0 -0
- /package/skills/{building-cpp → engineering/references/formatting}/scripts/checking-encoding.mjs +0 -0
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
# 静态分析与语言服务
|
|
2
|
-
|
|
3
|
-
三件语言工具各管一段:`clang-format` 排版、`clang-tidy` 诊断、`clangd` 提供补全/跳转/诊断。它们都读同一份编译数据库,但职责不重叠。编辑器侧只保留 CMake Tools 作为配置、构建、运行和调试入口;C/C++ 扩展只做 `CMake: Debug` 的调试后端,不参与语言服务。
|
|
4
|
-
|
|
5
|
-
## clang-format
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
clang-format --dry-run --Werror src/*.cpp include/*.h tests/*.cpp
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
- 检查用 `--dry-run --Werror`;需要自动修复时单独跑 `clang-format -i`,不要在构建脚本里悄悄改源码。
|
|
12
|
-
- 工程必须有根 `.clang-format`;缺失时先复制配置,不要回退到内置风格,回退会掩盖配置缺失。
|
|
13
|
-
- 只扫描项目源码:`src/`、`include/`、`apps/`、`tests/` 等实际存在的目录;不扫描 `build/`、第三方、生成文件。
|
|
14
|
-
- 配置文件在工程根 `.clang-format`;不要依赖用户主目录或编辑器内置配置。
|
|
15
|
-
- `BasedOnStyle: Google`、`Standard: Latest`;clang-format 21/22 不接受 `c++23`,`Latest` 按工具支持的最高标准解析。列宽、缩进与包含顺序以工程根 `.clang-format` 为准;工程显式写 `ColumnLimit` 时按工程值执行,模板资产不写 `ColumnLimit`。
|
|
16
|
-
- 格式化失败就是失败,不要用 `// clang-format off` 绕过;确需关闭时只包住无法排版的宏或表格,并写一句理由。
|
|
17
|
-
|
|
18
|
-
## clang-tidy
|
|
19
|
-
|
|
20
|
-
```bash
|
|
21
|
-
clang-tidy -p build/clang \
|
|
22
|
-
--header-filter="^$(pwd -P)/(include|src|apps|tests)/" \
|
|
23
|
-
--warnings-as-errors='*' \
|
|
24
|
-
src/*.cpp apps/*.cpp tests/*.cpp
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
- `-p` 指向当前编译器的构建目录,读取 `compile_commands.json`。
|
|
28
|
-
- `--header-filter` 控制哪些头文件的诊断被显示,不改变 clang-tidy 实际解析哪些头;模板实例化可能让一条根因产生多条警告,警告条数不等于缺陷条数。按根因修,不要按条数修。
|
|
29
|
-
- `--header-filter` 用项目头目录的白名单,不要用 `.*` 把系统头和第三方头一并纳入。clang-tidy 按绝对路径匹配,所以上面用 `$(pwd -P)` 前缀;上面是常见目录,工程用别的顶层目录时按实际替换。`--exclude-header-filter` 到 clang-tidy 19 才加入,16/17/18 都没有,不要依赖它。
|
|
30
|
-
- 系统头默认被排除,不要加 `--system-headers`。
|
|
31
|
-
- 只扫描项目源文件;不要把 `build/` 或第三方源码传给 clang-tidy。
|
|
32
|
-
- `--warnings-as-errors='*'` 把警告当失败;修代码,不要新增 `NOLINT`。确需抑制时写 `// NOLINT(检查名): 理由`,理由必须具体。
|
|
33
|
-
- 配置在工程根 `.clang-tidy`;默认集合是 `google-*`、`portability-avoid-pragma-once` 加 `readability-identifier-naming`(第二条去掉 `#pragma once`,与路径式守卫一致)。关闭某条时逐条写理由,不整族关闭;命名规则只配项目确实统一的项,不设 `FunctionCase`。
|
|
34
|
-
- 没有编译数据库时先回到 `building-cpp` 的定构建生成;不要用 `--` 手工拼编译参数绕过。
|
|
35
|
-
- `clang-tidy` 的诊断可能指向头文件;修头文件里的声明或实现,不要只改调用点。
|
|
36
|
-
|
|
37
|
-
## clangd
|
|
38
|
-
|
|
39
|
-
`.clangd`:
|
|
40
|
-
|
|
41
|
-
```yaml
|
|
42
|
-
CompileFlags:
|
|
43
|
-
CompilationDatabase: build/clang
|
|
44
|
-
Diagnostics:
|
|
45
|
-
Suppress:
|
|
46
|
-
- pp_file_not_found
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
- `CompilationDatabase` 指向当前编译器目录;GCC 模式改 `build/gcc`。
|
|
50
|
-
- 不要在 `.clangd` 写 `-std`:它会覆盖 `compile_commands.json`,把 C++23 工程降成旧标准。标准只由构建声明和编译数据库决定。
|
|
51
|
-
- 静态检查规则只在 `.clang-tidy` 里维护;clangd 读取同一份配置,不要在这里复制检查列表。
|
|
52
|
-
- `Suppress` 只放确实无法避免的解析噪声(如 `pp_file_not_found`),并写理由。
|
|
53
|
-
|
|
54
|
-
`--query-driver`:
|
|
55
|
-
|
|
56
|
-
- 它是 clangd 的命令行参数,不是 `.clangd` 的 YAML 键。
|
|
57
|
-
- 作用:允许 clangd 执行编译器驱动,读取系统头路径;只对编译数据库里出现的驱动生效。
|
|
58
|
-
- 写在 `.vscode/settings.json`:
|
|
59
|
-
|
|
60
|
-
```jsonc
|
|
61
|
-
{
|
|
62
|
-
"clangd.arguments": [
|
|
63
|
-
"--query-driver=/usr/bin/clang++",
|
|
64
|
-
"--header-insertion=never",
|
|
65
|
-
"--background-index"
|
|
66
|
-
]
|
|
67
|
-
}
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
- 路径用绝对路径;多个驱动用逗号分隔。GCC 模式指向 `/usr/bin/g++`。
|
|
71
|
-
- 不要写 `--query-driver=*` 或宽泛的 glob;这等于允许 clangd 执行任意匹配的驱动。
|
|
72
|
-
- 如果编译数据库里的编译器是相对路径,clangd 可能拒绝执行;用绝对路径重新 configure。
|
|
73
|
-
- `--query-driver` 只影响 clangd,不影响 clang-tidy;tidy 用编译数据库里的命令。
|
|
74
|
-
|
|
75
|
-
## 编辑器
|
|
76
|
-
|
|
77
|
-
`.vscode/extensions.json` 推荐:
|
|
78
|
-
|
|
79
|
-
```json
|
|
80
|
-
{
|
|
81
|
-
"recommendations": [
|
|
82
|
-
"llvm-vs-code-extensions.vscode-clangd",
|
|
83
|
-
"ms-vscode.cmake-tools",
|
|
84
|
-
"ms-vscode.cpptools"
|
|
85
|
-
]
|
|
86
|
-
}
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
`.vscode/settings.json` 固定:
|
|
90
|
-
|
|
91
|
-
```jsonc
|
|
92
|
-
{
|
|
93
|
-
"clangd.arguments": [
|
|
94
|
-
"--query-driver=/usr/bin/clang++",
|
|
95
|
-
"--header-insertion=never",
|
|
96
|
-
"--background-index"
|
|
97
|
-
],
|
|
98
|
-
"cmake.buildDirectory": "${workspaceFolder}/build/clang",
|
|
99
|
-
"cmake.generator": "Ninja",
|
|
100
|
-
"cmake.buildBeforeRun": true,
|
|
101
|
-
"cmake.exportCompileCommandsFile": true,
|
|
102
|
-
"cmake.debugConfig": {
|
|
103
|
-
"type": "cppdbg",
|
|
104
|
-
"request": "launch",
|
|
105
|
-
"MIMode": "lldb",
|
|
106
|
-
"miDebuggerPath": "/usr/bin/lldb",
|
|
107
|
-
"stopAtEntry": false
|
|
108
|
-
},
|
|
109
|
-
"C_Cpp.intelliSenseEngine": "disabled"
|
|
110
|
-
}
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
- 配置、构建、运行和调试只从 CMake Tools 进入;不要同时维护 `tasks.json` 或 `launch.json`,否则会出现第二套构建或启动路径。
|
|
114
|
-
- C/C++ 扩展只作为 CMake 快速调试的 `cppdbg` 后端;IntelliSense 关闭,补全、跳转、诊断和格式化只由 clangd 提供。
|
|
115
|
-
- 不推荐与 clangd 冲突的 C++ 智能提示插件;只保留一个语言服务。
|
|
116
|
-
- 不把 `compile_commands.json` 提交进仓库;它是构建产物。
|
|
117
|
-
- 切换编译器时同时改 `.clangd`、`settings.json` 和构建目录;三处不一致会让诊断指向旧代码。GCC 模式把 `MIMode` 改为 `gdb`、`miDebuggerPath` 改为 `/usr/bin/gdb`。
|
|
118
|
-
|
|
119
|
-
## 门禁分级
|
|
120
|
-
|
|
121
|
-
`--warnings-as-errors='*'` 是默认门禁。若项目必须把一组诊断先设为观察项,按检查名逐条写进项目脚本,不按 `*` 整族降级:
|
|
122
|
-
|
|
123
|
-
| 级别 | 典型检查 | 处理 |
|
|
124
|
-
| --- | --- | --- |
|
|
125
|
-
| 失败 | `google-*`、`readability-identifier-naming`、项目声明的致命集 | 修代码;不允许用 NOLINT 掩盖 |
|
|
126
|
-
| 失败 | 编译诊断、链接诊断、格式检查 | 直接失败 |
|
|
127
|
-
| 观察 | 迁移期暂时无法修完的个别 `google-*` 子项 | 在项目技能里列清单、写负责人和退出条件;不默认全仓关闭 |
|
|
128
|
-
|
|
129
|
-
- 致命集宁可小、可解释,也不要把所有检查一刀切。
|
|
130
|
-
- 观察项不是免死金牌:新代码不应新增观察项,已有项只能减少。
|
|
131
|
-
- 关闭某条检查时,在 `.clang-tidy` 里写一行理由,并在项目技能里记录退出条件。
|
|
132
|
-
|
|
133
|
-
## 版本与一致性
|
|
134
|
-
|
|
135
|
-
- `clang-format` / `clang-tidy` ≥ 16;clang 模式下与 `clang++`、`clangd` 同主版本。
|
|
136
|
-
- 混版本常见症状:格式化结果与 CI 不同、clangd 诊断与 tidy 不一致、选项被静默忽略。
|
|
137
|
-
- 检查器在 `--live` 时核对版本;不要用「能跑就行」绕过。
|
|
138
|
-
|
|
139
|
-
## 失败分诊
|
|
140
|
-
|
|
141
|
-
| 现象 | 可能原因 | 处理 |
|
|
142
|
-
| --- | --- | --- |
|
|
143
|
-
| `clang-tidy` 报找不到编译数据库 | 没 configure 或路径错 | 回到 `building-cpp` 的定构建生成 `build/<compiler>/compile_commands.json` |
|
|
144
|
-
| clangd 报找不到系统头 | 编译数据库里的编译器是相对路径 | 用绝对路径重新 configure,或配 `--query-driver` |
|
|
145
|
-
| 格式化结果与 CI 不同 | 版本不同或配置不是工程根那份 | 统一版本,确认 `.clang-format` 在工程根 |
|
|
146
|
-
| tidy 报系统头 | 加了 `--system-headers` 或 header-filter 过宽 | 去掉 `--system-headers`,用项目头目录白名单 |
|
|
147
|
-
| 大量 `readability-*` | 代码风格未统一 | 回到 `developing-cpp` 的定声明 / 定实现修声明与实现,不要批量 NOLINT |
|
|
148
|
-
| clangd 与 tidy 诊断不一致 | 两者读的数据库/版本不同 | 统一 `CompilationDatabase` 与工具版本 |
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: configuring-cmake
|
|
3
|
-
description: 编写或重构 C++11–C++23 工程的 CMake 时使用:CMakeLists.txt、cmake 模块、target 属性、依赖与输出目录、语言标准;新工程默认 C++23。不用于 Quarto、Python 或非 C++ 文档。
|
|
4
|
-
metadata:
|
|
5
|
-
short-description: CMake 配置三步
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
# configuring-cmake
|
|
9
|
-
|
|
10
|
-
## 适用场景
|
|
11
|
-
|
|
12
|
-
本技能处理 CMake 文件与 target 契约:`CMakeLists.txt`、`cmake/` 模块、`target_*` 命令、目标属性、include 与链接边界、输出目录、共享库运行时路径、`FetchContent`、preset 与安装导出。函数体、类型、命名、异常和源码注释只开 `developing-cpp`;配置完成后要跑构建、格式化、静态检查或入口脚本时开 `building-cpp`。
|
|
13
|
-
|
|
14
|
-
一次改动同时碰到源码和 CMake 时先开 `developing-cpp` 定行为与边界,再用本技能把源文件、库和程序写进 target,最后到 `building-cpp` 跑检查。只改一个 target 的 include、链接或标准时走单点修正;新工程、新组件、换语言标准或抽公共函数时走整段重构。
|
|
15
|
-
|
|
16
|
-
存在项目技能 `cpp-workflow-project` 时先读它的 `SKILL.md`、`environment.json` 和 `stages/stage-table.md`。`environment.json` 的 `standard` 是 target 标准的唯一来源;缺失、非法或与现有 target 不一致时停在定 target,不猜标准。构建目录、编译器和工具版本由 `building-cpp` 的定构建负责,本技能只写 target 契约;target 图与 CMake 写法以本技能为权威,`building-cpp` 只读不修改。
|
|
17
|
-
|
|
18
|
-
## 三种操作
|
|
19
|
-
|
|
20
|
-
一次只选一种,范围(单点、整段)是任务属性。操作与域的判据、边界和交接见 `../developing-cpp/references/change-model.md`;四类改动是域,不是操作。
|
|
21
|
-
|
|
22
|
-
| 操作 | 什么时候用 | 从哪步进 |
|
|
23
|
-
| --- | --- | --- |
|
|
24
|
-
| 写作(起稿) | 新增 target、改公共 include 或链接边界、换语言标准 | 第 1 步;新工程走到第 3 步 |
|
|
25
|
-
| 改写 | target 图与标准不变,模块、函数或目录结构不对 | 从第 2 步重走,可到第 3 步 |
|
|
26
|
-
| 润色 | 只改函数名、注释措辞或错误消息 | 第 2 步 |
|
|
27
|
-
|
|
28
|
-
三种操作共用这些约束:不发明项目没有声明的 target、标准、编译器或目录;不覆盖已有 `CMakeLists.txt`;不用全局 `include_directories()`、`add_definitions()`、`CMAKE_CXX_FLAGS` 给所有 target 加料;不写 `file(GLOB ...)`;不把 `main()` 编进库;库与程序不下载依赖,只有测试需要时调用 `LinkSettings_FetchGoogleTest`。后一步发现前一步没做完,退回那一步。
|
|
29
|
-
|
|
30
|
-
## 步骤
|
|
31
|
-
|
|
32
|
-
| 步 | 名称 | 文件 | 一句话 |
|
|
33
|
-
| --- | --- | --- | --- |
|
|
34
|
-
| 1 | 定 target 与标准 | `steps/01-targets.md` | target 图、PUBLIC/PRIVATE、标准、输出目录与编译数据库 |
|
|
35
|
-
| 2 | 定模块与函数 | `steps/02-modules.md` | 何时抽函数、文件与命名、导入、注释与 2 空格排版 |
|
|
36
|
-
| 3 | 通过检查 | `steps/03-check.md` | configure、构建、编译数据库与实际 `-std` 核对 |
|
|
37
|
-
|
|
38
|
-
每步只打开同号的一个步骤文件。判不准才打开 `examples/cmake.md`;`references/cmake.md` 保存 target、链接、输出、RPATH、依赖与反模式的完整条文,`references/cxx-standard.md` 保存 C++11–C++23 的标准映射,`references/modules.md` 保存函数与模块契约。可复制的函数在 `assets/cmake/`:`CompileSettings.cmake` 放标准与警告,`LinkSettings.cmake` 放构建期 RPATH 与 GoogleTest 依赖;一个文件按性质收一组函数。
|
|
39
|
-
|
|
40
|
-
本轮激活按三条上限走:
|
|
41
|
-
|
|
42
|
-
- 只开当前步对应的一个步骤文件;同一改动域内不同时展开两个技能的步骤。跨域按 `源码 → configuring-cmake → building-cpp` 的顺序逐段进入,前一段结论落下再开下一段。
|
|
43
|
-
- 条文只开该步点名的一份;同号案例留到下一次激活。
|
|
44
|
-
- 标准档只打开项目技能声明的那一档,没有声明时用本技能已有的新工程默认,不把其余标准档读进来。
|
|
45
|
-
|
|
46
|
-
项目技能列出了检查命令时只跑那一条,没有时跑插件根目录的 `npm test`;退出码为 0 后在同一轮结束 goal,不再继续走没有失败的步骤。
|
|
47
|
-
|
|
48
|
-
五档标准的语言设施、工具映射与降档仍由 `building-cpp/references/standards/` 维护;本技能只负责这些标准在 CMake 里怎么写。
|
|
49
|
-
|
|
50
|
-
### 四类改动
|
|
51
|
-
|
|
52
|
-
四类改动是操作内部的域:操作定入口,域定层次。四域的定义、边界与次序见 `../developing-cpp/references/change-model.md`;一次改动混了两类时,按「内容 → 结构 → 版式 → 措辞」拆开做,前一类落定并经检查再进下一类。
|
|
53
|
-
|
|
54
|
-
| 类型 | 典型请求 | 入口步骤 |
|
|
55
|
-
| --- | --- | --- |
|
|
56
|
-
| 内容 | 新增 target、改公共 include 或链接边界、换语言标准 | `steps/01-targets.md` |
|
|
57
|
-
| 结构 | 抽函数、拆模块、调导入位置 | `steps/02-modules.md` |
|
|
58
|
-
| 版式 | 只改 2 空格、行宽或注释形态 | `steps/02-modules.md` |
|
|
59
|
-
| 措辞 | 只改函数名、注释措辞或错误消息 | `steps/02-modules.md` |
|
|
60
|
-
|
|
61
|
-
## 完成判据
|
|
62
|
-
|
|
63
|
-
- [ ] target 图显式:程序 target 叫 `app`,库 target 用组件名,程序链接库,库的公共 include 用 `PUBLIC`;没有全局 include、全局编译选项或 GLOB。
|
|
64
|
-
- [ ] 每个 target 的标准来自 `environment.json`;`target_compile_features` 与 `CXX_STANDARD`、`CXX_STANDARD_REQUIRED ON`、`CXX_EXTENSIONS OFF` 同时存在,live 的 `compile_commands.json` 最后一条 `-std=` 与声明一致,不是 `gnu++NN`。
|
|
65
|
-
- [ ] 复用的 CMake 函数放在 `cmake/` 模块里,文件名用 UpperCamelCase,函数名用 `<ModuleName>_` 加 PascalCase,有目标与参数校验,根 `CMakeLists.txt` 通过 `CMAKE_MODULE_PATH` 导入;没有重复片段和未使用的旧模块。
|
|
66
|
-
- [ ] 公开函数上方写中文 `#` 契约:一句功能、空行、边界,再用 `:param` / `:keyword` 标参数;不写 `#[[.rst:` 与 `.. command::`,完整写法见 `references/cmake.md`;函数组之间用 `#---`,不画 `#===...===#` 方框。
|
|
67
|
-
- [ ] `CMakeLists.txt` 与 `*.cmake` 用 UTF-8 无 BOM、LF、2 空格缩进、不用 tab;行宽按团队约定,默认 80 列。
|
|
68
|
-
- [ ] configure 与构建通过,构建产物不落在源码目录;没有改源码语义,也没有覆盖已有工程文件。
|
|
@@ -1,313 +0,0 @@
|
|
|
1
|
-
# 正反例:声明注释与文件头
|
|
2
|
-
|
|
3
|
-
## 文件头
|
|
4
|
-
|
|
5
|
-
**差**:
|
|
6
|
-
|
|
7
|
-
```cpp
|
|
8
|
-
// board.h
|
|
9
|
-
// 作者:chengzhao-dev
|
|
10
|
-
// 创建:2026-01-01
|
|
11
|
-
// 修改:2026-03-02 增加 CompletesLine
|
|
12
|
-
```
|
|
13
|
-
|
|
14
|
-
**好**:
|
|
15
|
-
|
|
16
|
-
```cpp
|
|
17
|
-
/// @file cell.h
|
|
18
|
-
/// @brief 格子相关类型定义。
|
|
19
|
-
///
|
|
20
|
-
/// 封装了格子的状态枚举 `CellState` 以及格子实体 `Cell`。
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
文件头只介绍这个文件里有什么,不写作者和变更史,也不把读者指去另一个文件。
|
|
24
|
-
|
|
25
|
-
## 类型注释:概念与约定,不是功能清单
|
|
26
|
-
|
|
27
|
-
**差**:
|
|
28
|
-
|
|
29
|
-
```cpp
|
|
30
|
-
/// 井字棋棋盘。
|
|
31
|
-
///
|
|
32
|
-
/// 提供检查坐标区间、检查棋盘格子是否为空、获取棋盘格子类型、放置棋子、清空棋盘和判定终局的功能。
|
|
33
|
-
/// 棋盘为 3 行 3 列。
|
|
34
|
-
class Board {
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
问题有两处:把成员函数抄了一遍,接口一改就过期;「棋盘为 3 行 3 列」被拆成单独一句,读者不知道它在回答什么问题。
|
|
38
|
-
|
|
39
|
-
**差**(把别的类型和以后才发生的事都写进来):
|
|
40
|
-
|
|
41
|
-
```cpp
|
|
42
|
-
/// 井字棋棋盘。
|
|
43
|
-
///
|
|
44
|
-
/// 棋盘只保存 3×3 的格子状态和规则判断,不含回合推进:谁该落子、落子被拒后怎么提示留在 Game。
|
|
45
|
-
///
|
|
46
|
-
/// 棋盘是值语义,可以自由拷贝;所有查询都是 const,对局和搜索可以交替读取同一棋盘。
|
|
47
|
-
class Board {
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
第二段说的是 `Game` 负责什么,读者读完仍不知道 `Board` 是什么,重构一次这句话就过期;后两段里的可拷贝、`const` 查询在类声明里已经写清,「搜索要读同一棋盘」还不是现在的调用方。读者真正需要的是这个类型是什么;格子数由成员声明表达,失败方式写在各自函数上。
|
|
51
|
-
|
|
52
|
-
**好**(纯数据与尺寸由成员表达):
|
|
53
|
-
|
|
54
|
-
```cpp
|
|
55
|
-
/// 井字棋棋盘。
|
|
56
|
-
class Board {
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
**好**(类有不变量,第二段直接写不变量):
|
|
60
|
-
|
|
61
|
-
```cpp
|
|
62
|
-
/// 一局井字棋。
|
|
63
|
-
///
|
|
64
|
-
/// 棋盘、当前玩家和落子历史同步推进;落子被拒时三者都不变。
|
|
65
|
-
class Game {
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
纯数据结构和枚举只写一句名词短语;类有不变量,且第二段不是重复 `cells_`、`kRowCount` 这类领域尺寸时,才保留第二段。第二段直接写不变量,不加「限制:」这类标签。函数各自的契约下沉到函数注释,设计理由与分层写进书稿。
|
|
69
|
-
|
|
70
|
-
## 构造函数与析构函数:标签 + 职责
|
|
71
|
-
|
|
72
|
-
**差**:
|
|
73
|
-
|
|
74
|
-
```cpp
|
|
75
|
-
/// 构造函数:创建一个空棋盘。
|
|
76
|
-
Board() = default;
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
「创建」复述了声明,读者仍不知道构造完成后棋盘里是什么、`cells_` 的每个元素是否已经有值。
|
|
80
|
-
|
|
81
|
-
**好**:
|
|
82
|
-
|
|
83
|
-
```cpp
|
|
84
|
-
/// 默认构造函数:得到空棋盘,每个格子都是 kEmpty。
|
|
85
|
-
Board() = default;
|
|
86
|
-
|
|
87
|
-
/// 析构函数:保证通过接口指针正确删除派生类对象。
|
|
88
|
-
virtual ~Ai();
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
`= default` 本身不说明成员被初始化成什么;`cells_{}` 把每个 `CellState` 初始化成 `kEmpty`,这条后置条件从签名上看不出来。标签说明这是哪一类特殊成员,冒号后写它建立的状态或承担的职责。
|
|
92
|
-
|
|
93
|
-
## 风格理由不进注释
|
|
94
|
-
|
|
95
|
-
**差**(在十几个函数上各写一遍):
|
|
96
|
-
|
|
97
|
-
```cpp
|
|
98
|
-
/// 检查坐标是否在范围内。函数名用 UpperCamel 而不是 snake_case,与标准库区分。
|
|
99
|
-
[[nodiscard]] static bool IsInRange(Position position) noexcept;
|
|
100
|
-
|
|
101
|
-
/// 检查格子是否为空。函数名用 UpperCamel 而不是 snake_case,与标准库区分。
|
|
102
|
-
[[nodiscard]] bool IsCellEmpty(Position position) const;
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
**好**(只写契约):
|
|
106
|
-
|
|
107
|
-
```cpp
|
|
108
|
-
/// 检查坐标是否落在棋盘下标区间内。
|
|
109
|
-
[[nodiscard]] static bool IsInRange(Position position) noexcept;
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
命名与风格约定写进项目文档和读者正文,注释里不解释「为什么用这种命名」。
|
|
113
|
-
|
|
114
|
-
## 第一句:结果、保证或检查项
|
|
115
|
-
|
|
116
|
-
**差**:
|
|
117
|
-
|
|
118
|
-
```cpp
|
|
119
|
-
/// 检查坐标。
|
|
120
|
-
/// 返回格子类型;越界会抛异常。
|
|
121
|
-
CellState GetState(Position position) const;
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
前两句都没有直接回答“合法时拿到什么、越界时发生什么”,读者要读完三句才拼出合同。
|
|
125
|
-
|
|
126
|
-
**好**:
|
|
127
|
-
|
|
128
|
-
```cpp
|
|
129
|
-
/// 坐标越界时抛出 std::out_of_range;合法坐标返回该格类型。
|
|
130
|
-
///
|
|
131
|
-
/// @param position 行列坐标。
|
|
132
|
-
/// @throws std::out_of_range 坐标不在棋盘范围内。
|
|
133
|
-
CellState GetState(Position position) const;
|
|
134
|
-
```
|
|
135
|
-
|
|
136
|
-
第一句就是结果、失败方式或检查项;后面的标签只补参数与异常细节,不再重复这句话。
|
|
137
|
-
|
|
138
|
-
**差**(比较函数却先写“比较”):
|
|
139
|
-
|
|
140
|
-
```cpp
|
|
141
|
-
/// 比较两个坐标。
|
|
142
|
-
friend bool operator==(const Position&, const Position&) = default;
|
|
143
|
-
```
|
|
144
|
-
|
|
145
|
-
**好**:
|
|
146
|
-
|
|
147
|
-
```cpp
|
|
148
|
-
/// 检查两个坐标的行与列是否都相同。
|
|
149
|
-
friend bool operator==(const Position&, const Position&) = default;
|
|
150
|
-
```
|
|
151
|
-
|
|
152
|
-
布尔查询和 `operator==` 的第一句都用「检查…是否…」,让读者先看到被检查的条件,而不是一个同义反复的动词。
|
|
153
|
-
|
|
154
|
-
## 函数契约
|
|
155
|
-
|
|
156
|
-
**差**:
|
|
157
|
-
|
|
158
|
-
```cpp
|
|
159
|
-
/// 尝试执行一次落子。
|
|
160
|
-
///
|
|
161
|
-
/// @param move 落子。
|
|
162
|
-
/// @returns 落子执行成功返回 kPlaced,被拒绝返回 kOccupied。
|
|
163
|
-
[[nodiscard]] PlaceResult TryPlace(const Move& move);
|
|
164
|
-
```
|
|
165
|
-
|
|
166
|
-
`@param move 落子` 是把类型名翻译成中文,没有信息;`@returns` 不是 Doxygen 标签;没有说被拒绝的条件,调用方只能读实现。
|
|
167
|
-
|
|
168
|
-
**好**:
|
|
169
|
-
|
|
170
|
-
```cpp
|
|
171
|
-
/// 尝试执行一次落子。
|
|
172
|
-
///
|
|
173
|
-
/// 只有本局仍在进行、且落子玩家正是当前玩家时才继续,棋盘、轮次、历史三者一起更新。
|
|
174
|
-
///
|
|
175
|
-
/// @param move 待执行的落子,玩家必须是当前轮到的玩家。
|
|
176
|
-
/// @return 落子写入棋盘并换手时返回 kPlaced;对局已结束或上述任一条件不满足时返回 kOccupied,
|
|
177
|
-
/// 棋盘和轮次都不变。
|
|
178
|
-
[[nodiscard]] PlaceResult TryPlace(const Move& move);
|
|
179
|
-
```
|
|
180
|
-
|
|
181
|
-
## 布尔查询只写检查什么
|
|
182
|
-
|
|
183
|
-
**差**:
|
|
184
|
-
|
|
185
|
-
```cpp
|
|
186
|
-
/// 检查指定坐标上的棋盘格子是否为空。
|
|
187
|
-
[[nodiscard]] bool IsCellEmpty(Position position) const;
|
|
188
|
-
```
|
|
189
|
-
|
|
190
|
-
**好**:
|
|
191
|
-
|
|
192
|
-
```cpp
|
|
193
|
-
/// 检查指定坐标上的棋盘格子是否为空。
|
|
194
|
-
///
|
|
195
|
-
/// @param position 待检查的坐标。
|
|
196
|
-
/// @return 坐标在棋盘内且该格为空时返回 true;越界或该格已有状态时返回 false。
|
|
197
|
-
[[nodiscard]] bool IsCellEmpty(Position position) const;
|
|
198
|
-
```
|
|
199
|
-
|
|
200
|
-
布尔查询的第一句写「检查…是否…」,`@return` 写成立与不成立的条件;能力边界不写成否定清单,调用方要满足的条件用正向限定或 `@pre`。
|
|
201
|
-
|
|
202
|
-
## 枚举
|
|
203
|
-
|
|
204
|
-
**差**:
|
|
205
|
-
|
|
206
|
-
```cpp
|
|
207
|
-
enum class Player : std::uint8_t {
|
|
208
|
-
kCross, // X
|
|
209
|
-
kNought // O
|
|
210
|
-
};
|
|
211
|
-
```
|
|
212
|
-
|
|
213
|
-
**好**:
|
|
214
|
-
|
|
215
|
-
```cpp
|
|
216
|
-
/// 对局结果。
|
|
217
|
-
enum class GameResult : std::uint8_t {
|
|
218
|
-
kInProgress = 0, ///< 对局尚未结束
|
|
219
|
-
kCrossWin = 1, ///< 对局由 X 获胜
|
|
220
|
-
kNoughtWin = 2, ///< 对局由 O 获胜
|
|
221
|
-
kDraw = 3, ///< 对局以平局结束
|
|
222
|
-
};
|
|
223
|
-
```
|
|
224
|
-
|
|
225
|
-
行尾注释必须以枚举主体的同一个词开头,写成完整的状态或结果;需要补原因时用「主体 + 结果:原因」,冒号前后都不能空。不写「X 成线」「尚未结束」这种只有谓语的片段,同一枚举要么全写要么全不写。
|
|
226
|
-
|
|
227
|
-
## 数据成员
|
|
228
|
-
|
|
229
|
-
**差**:
|
|
230
|
-
|
|
231
|
-
```cpp
|
|
232
|
-
Board board_; // 对局棋盘。
|
|
233
|
-
std::array<std::array<CellState, kColumnCount>, kRowCount> cells_{}; // 存储棋盘格子。
|
|
234
|
-
```
|
|
235
|
-
|
|
236
|
-
前一句把名字翻译了一遍;后一句只复述声明,没有说清两层下标各是什么。
|
|
237
|
-
|
|
238
|
-
**好**:
|
|
239
|
-
|
|
240
|
-
```cpp
|
|
241
|
-
/// 棋盘格子数组:外层下标是行,内层下标是列。
|
|
242
|
-
std::array<std::array<CellState, kColumnCount>, kRowCount> cells_{};
|
|
243
|
-
/// 当前玩家:开局由 X 先手。
|
|
244
|
-
Player current_player_ = Player::kCross;
|
|
245
|
-
/// 对局结果:落子被拒时保持原值。
|
|
246
|
-
GameResult result_ = GameResult::kInProgress;
|
|
247
|
-
/// 落子历史:按落子次序保存。
|
|
248
|
-
std::vector<Move> history_;
|
|
249
|
-
```
|
|
250
|
-
|
|
251
|
-
主注释写在声明上一行,类数据成员(含私有)统一用 `///`;第一句先说是哪个成员,再用全角冒号补名字和类型看不出、只属于该成员的范围、轴向、哨兵与所有权。类级初值与状态迁移写在类注释,成员注释不重复。行尾不写补充;`///<` 只给枚举项和 `struct` 短字段。名字已经说明存放对象的 `board_` 不写「对局棋盘」。
|
|
252
|
-
|
|
253
|
-
## 完整声明:后置条件与轴向
|
|
254
|
-
|
|
255
|
-
把上面的规则放在一起,`Board` 的声明是这样:
|
|
256
|
-
|
|
257
|
-
```cpp
|
|
258
|
-
/// 井字棋棋盘。
|
|
259
|
-
class Board {
|
|
260
|
-
public:
|
|
261
|
-
/// 默认构造函数:得到空棋盘,每个格子都是 kEmpty。
|
|
262
|
-
Board() = default;
|
|
263
|
-
|
|
264
|
-
private:
|
|
265
|
-
/// 棋盘格子数组:外层下标是行,内层下标是列。
|
|
266
|
-
std::array<std::array<CellState, kColumnCount>, kRowCount> cells_{};
|
|
267
|
-
};
|
|
268
|
-
```
|
|
269
|
-
|
|
270
|
-
类注释只说这个类型是什么;构造注释补的是 `= default` 配合 `cells_{}` 才建立的后置条件;`cells_` 的上一行先说是棋盘格子数组,再用全角冒号补轴向。行尾不写补充;`{}` 带来的空格子已经由构造注释表达。三处各说一件事,没有一句复述签名。
|
|
271
|
-
|
|
272
|
-
## 配置注释
|
|
273
|
-
|
|
274
|
-
**差**:
|
|
275
|
-
|
|
276
|
-
```yaml
|
|
277
|
-
# 这是 clang-format 配置
|
|
278
|
-
# 详见某文档
|
|
279
|
-
ColumnLimit: 100
|
|
280
|
-
```
|
|
281
|
-
|
|
282
|
-
**好**:
|
|
283
|
-
|
|
284
|
-
```yaml
|
|
285
|
-
# 列宽、缩进、包含顺序都取 Google 预设,不逐项覆盖。
|
|
286
|
-
Language: Cpp
|
|
287
|
-
BasedOnStyle: Google
|
|
288
|
-
Standard: Latest
|
|
289
|
-
```
|
|
290
|
-
|
|
291
|
-
解释为什么选预设,不写策略头,不指文档路径。
|
|
292
|
-
|
|
293
|
-
## 不该进注释的东西
|
|
294
|
-
|
|
295
|
-
**差**:
|
|
296
|
-
|
|
297
|
-
```cpp
|
|
298
|
-
// 2026-03-02 把 Board 从 Game 里拆出来,因为之前 Game 太长。
|
|
299
|
-
// 参见 https://example.com/2026/03/02/refactor
|
|
300
|
-
// 其余成员见下方注释,两处不重复。
|
|
301
|
-
// 本团队要求所有类注释写满五行。
|
|
302
|
-
```
|
|
303
|
-
|
|
304
|
-
**好**:
|
|
305
|
-
|
|
306
|
-
```cpp
|
|
307
|
-
/// @file board.h
|
|
308
|
-
/// @brief 棋盘状态与规则判断。
|
|
309
|
-
///
|
|
310
|
-
/// 定义 Board 的查询、落子与清空棋盘。
|
|
311
|
-
```
|
|
312
|
-
|
|
313
|
-
变更史进提交说明,外部资料进文档,团队流程进规范文件;注释只写这个文件或这个类型自己的内容,不把读者指去别的文件。
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
# 正反例:实现注释
|
|
2
|
-
|
|
3
|
-
实现注释只写本层为什么停在这里;声明注释、文件头与配置注释见 `comments-declaration.md`。
|
|
4
|
-
|
|
5
|
-
## 实现注释
|
|
6
|
-
|
|
7
|
-
**差**:
|
|
8
|
-
|
|
9
|
-
```cpp
|
|
10
|
-
// 遍历所有空格
|
|
11
|
-
for (const auto& position : empty_cells) {
|
|
12
|
-
// 尝试落子
|
|
13
|
-
const bool wins = game.PreviewWin(position, state) == WinPreviewResult::kWouldWin;
|
|
14
|
-
// 如果能赢
|
|
15
|
-
if (wins) {
|
|
16
|
-
// 返回这次落子的位置
|
|
17
|
-
return position;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
每行都在复述代码。
|
|
23
|
-
|
|
24
|
-
**好**:
|
|
25
|
-
|
|
26
|
-
```cpp
|
|
27
|
-
Cell::SetStateResult Cell::SetState(CellState state) noexcept {
|
|
28
|
-
// 传入状态为 kEmpty,不设置格子状态。
|
|
29
|
-
if (state == CellState::kEmpty) {
|
|
30
|
-
return SetStateResult::kNoInput;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// 格子已有状态,不进行覆盖。
|
|
34
|
-
if (state_ != CellState::kEmpty) {
|
|
35
|
-
return SetStateResult::kOccupied;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// 格子状态为空,更新为传入的状态。
|
|
39
|
-
state_ = state;
|
|
40
|
-
return SetStateResult::kUpdated;
|
|
41
|
-
}
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
每一支的上一行一句,写这一支的后果;`//` 里的枚举值不包反引号。空行与注释的边界:
|
|
45
|
-
|
|
46
|
-
- 多条独立拒绝:每个 `if` 上一行一句,写拒绝后棋盘怎样。
|
|
47
|
-
- 成功设置:上一行一句,写为什么到这里才改棋盘。
|
|
48
|
-
- 次序依赖的一对 `if`:第一组上方一句说明次序不能反,第二个不复制。
|
|
49
|
-
- 循环上方已有阶段说明时,循环里的 `if` 不再加;单表达式谓词不加。
|
|
50
|
-
|
|
51
|
-
## TODO
|
|
52
|
-
|
|
53
|
-
**差**:
|
|
54
|
-
|
|
55
|
-
```cpp
|
|
56
|
-
// TODO: 参考 xxx
|
|
57
|
-
// FIXME: 这里可能有问题
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
**好**:
|
|
61
|
-
|
|
62
|
-
```cpp
|
|
63
|
-
// TODO: 阶段 5 - 给 MinimaxAi 加置换表,减少重复局面的搜索。
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
有定位、有动作、能搜索。
|