@chengzhao-dev/dsh-cpp-workflow 0.7.9 → 0.7.11
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 +8 -7
- package/README.md +5 -4
- package/cordis.patch.yml +2 -2
- package/icon.svg +5 -5
- package/lib/client.js +542 -538
- package/lib/comment-policy.js +37 -33
- package/lib/workspace.js +8 -10
- package/locale/en.json +4 -4
- package/locale/zh.json +4 -4
- package/package.json +100 -100
- package/skills/building-cpp/SKILL.md +5 -5
- package/skills/building-cpp/assets/config/.clang-tidy +4 -5
- package/skills/building-cpp/assets/config/.clangd +5 -7
- package/skills/building-cpp/assets/config/.vscode/extensions.json +5 -5
- package/skills/building-cpp/assets/config/.vscode/settings.json +56 -58
- package/skills/building-cpp/examples/environment.md +13 -102
- package/skills/building-cpp/references/01-build-script.md +3 -3
- package/skills/building-cpp/references/02-environment.md +8 -8
- package/skills/building-cpp/scripts/checking-environment.mjs +424 -424
- package/skills/building-cpp/steps/01-build.md +10 -10
- package/skills/building-cpp/steps/02-tooling.md +6 -6
- package/skills/building-cpp/steps/03-check.md +2 -2
- package/skills/building-cpp/steps/04-vscode.md +4 -6
- package/skills/developing-cpp/SKILL.md +8 -9
- package/skills/developing-cpp/references/comments/01-comment-rules.md +50 -26
- package/skills/developing-cpp/references/comments/02-style.md +33 -25
- package/skills/developing-cpp/references/comments/examples/03-declaration-enum.md +14 -14
- package/skills/developing-cpp/references/comments/examples/04-declaration-file.md +12 -8
- package/skills/developing-cpp/references/comments/examples/05-declaration-function.md +20 -10
- package/skills/developing-cpp/references/comments/examples/06-declaration-member.md +4 -4
- package/skills/developing-cpp/references/comments/examples/07-declaration-predicate.md +2 -2
- package/skills/developing-cpp/references/comments/examples/08-declaration-struct.md +6 -6
- package/skills/developing-cpp/references/comments/examples/09-implementation-body.md +41 -41
- package/skills/developing-cpp/references/comments/glossary/01-comment-terms.md +17 -16
- package/skills/developing-cpp/references/design/01-project-design.md +21 -10
- package/skills/developing-cpp/references/design/02-raii.md +5 -4
- package/skills/developing-cpp/references/design/03-third-party.md +2 -2
- package/skills/developing-cpp/references/design/examples/02-coordinate-table.md +12 -12
- package/skills/developing-cpp/references/design/examples/03-header-place.md +1 -1
- package/skills/developing-cpp/references/design/examples/04-library-boundary.md +6 -6
- package/skills/developing-cpp/references/design/examples/06-move-result.md +29 -28
- package/skills/developing-cpp/references/design/examples/07-preview-read.md +24 -23
- package/skills/developing-cpp/references/design/examples/08-screen-enter-exit.md +19 -18
- package/skills/developing-cpp/references/design/examples/09-option-menu.md +6 -6
- package/skills/developing-cpp/references/design/session-layer.md +13 -22
- package/skills/developing-cpp/references/exceptions/01-exception-rules.md +57 -57
- package/skills/developing-cpp/references/exceptions/examples/01-throw-boundary.md +7 -20
- package/skills/developing-cpp/references/exceptions/examples/02-throw-build-mode.md +10 -11
- package/skills/developing-cpp/references/exceptions/examples/03-throw-catch.md +4 -4
- package/skills/developing-cpp/references/exceptions/examples/04-throw-destructor.md +9 -5
- package/skills/developing-cpp/references/exceptions/examples/07-throw-when.md +2 -2
- package/skills/developing-cpp/references/index.md +32 -35
- package/skills/developing-cpp/references/language/glossary/01-language-terms.md +3 -2
- package/skills/developing-cpp/references/language/language-basics/02-initialization.md +1 -1
- package/skills/developing-cpp/references/language/language-basics/05-expressions.md +9 -2
- package/skills/developing-cpp/references/language/language-basics/06-functions.md +2 -3
- package/skills/developing-cpp/references/language/language-basics/09-templates.md +3 -3
- package/skills/developing-cpp/references/language/language-basics/10-language-checklist.md +9 -9
- package/skills/developing-cpp/references/language/performance/03-memory.md +1 -1
- package/skills/developing-cpp/references/language/performance/07-checklist.md +6 -6
- package/skills/developing-cpp/references/language/standard-library/01-containers.md +4 -5
- package/skills/developing-cpp/references/language/standard-library/02-access.md +2 -5
- package/skills/developing-cpp/references/language/standard-library/05-string.md +1 -1
- package/skills/developing-cpp/references/language/standard-library/06-format.md +22 -20
- package/skills/developing-cpp/references/language/standard-library/{11-format-ecosystem.md → 07-format-ecosystem.md} +2 -11
- package/skills/developing-cpp/references/language/standard-library/{07-time.md → 08-time.md} +1 -1
- package/skills/developing-cpp/references/language/standard-library/{09-files.md → 10-files.md} +1 -1
- package/skills/developing-cpp/references/language/standard-library/11-library-checklist.md +8 -0
- package/skills/developing-cpp/references/language/value-types/02-signed.md +7 -7
- package/skills/developing-cpp/references/language/value-types/03-integer-roles.md +14 -2
- package/skills/developing-cpp/references/language/value-types/05-strong-type.md +2 -2
- package/skills/developing-cpp/references/language/value-types/06-const-method.md +5 -5
- package/skills/developing-cpp/references/language/value-types/07-nodiscard.md +1 -1
- package/skills/developing-cpp/references/language/value-types/08-comparison.md +1 -1
- package/skills/developing-cpp/references/language/value-types/09-subscript.md +1 -1
- package/skills/developing-cpp/references/language/value-types/11-checklist.md +7 -7
- package/skills/developing-cpp/references/layout/01-source-layout.md +13 -13
- package/skills/developing-cpp/references/layout/02-file-template.md +10 -10
- package/skills/developing-cpp/references/layout/03-declaration-order.md +83 -42
- package/skills/developing-cpp/references/naming/01-identifier-names.md +32 -30
- package/skills/developing-cpp/references/naming/examples/06-naming-lower-layer.md +15 -15
- package/skills/developing-cpp/references/naming/examples/07-naming-multiple-return.md +2 -2
- package/skills/developing-cpp/references/naming/examples/13-naming-state-change.md +24 -23
- package/skills/developing-cpp/references/naming/glossary/01-naming-terms.md +3 -3
- package/skills/developing-cpp/references/naming/glossary/02-position.md +9 -9
- package/skills/developing-cpp/references/naming/glossary/03-selection.md +5 -1
- package/skills/developing-cpp/references/naming/glossary/04-square.md +3 -3
- package/skills/developing-cpp/references/naming/glossary/05-scoring.md +2 -2
- package/skills/developing-cpp/references/naming/glossary/06-difficulty.md +7 -7
- package/skills/developing-cpp/references/naming/glossary/07-stream.md +1 -1
- package/skills/developing-cpp/references/style/01-google-cpp-style.md +13 -23
- package/skills/developing-cpp/scripts/checking-comments.mjs +961 -755
- package/skills/developing-cpp/scripts/checking-declaration-order.mjs +512 -515
- package/skills/developing-cpp/steps/01-behavior.md +0 -1
- package/skills/developing-cpp/steps/02-boundary.md +2 -3
- package/skills/developing-cpp/steps/03-declaration.md +9 -10
- package/skills/developing-cpp/steps/04-implementation.md +7 -8
- package/skills/engineering/SKILL.md +9 -10
- package/skills/engineering/references/cmake/assets/LinkSettings.cmake +1 -1
- package/skills/engineering/references/cmake/linking/02-rpath.md +5 -6
- package/skills/engineering/references/cmake/modules/01-functions.md +9 -9
- package/skills/engineering/references/cmake/standards/01-cxx-standard.md +6 -6
- package/skills/engineering/references/cmake/standards/index.md +8 -29
- package/skills/engineering/references/cmake/targets/01-target-rules.md +14 -13
- package/skills/engineering/references/cmake/targets/examples/01-rpath.md +1 -1
- package/skills/engineering/references/cmake/testing/01-ctest.md +3 -3
- package/skills/engineering/references/formatting/01-encoding.md +5 -5
- package/skills/engineering/references/formatting/02-clang-format.md +2 -2
- package/skills/engineering/references/formatting/03-clang-tidy.md +5 -5
- package/skills/engineering/references/formatting/04-clangd.md +32 -39
- package/skills/engineering/references/formatting/05-config-comments.md +88 -0
- package/skills/engineering/references/formatting/examples/02-clang-tidy.md +6 -6
- package/skills/engineering/references/formatting/examples/03-clangd.md +17 -17
- package/skills/engineering/references/index.md +5 -4
- package/skills/engineering/scripts/checking-encoding.mjs +369 -369
- package/skills/engineering/steps/01-targets.md +3 -3
- package/skills/engineering/steps/02-modules.md +1 -2
- package/skills/engineering/steps/03-check.md +2 -3
- package/templates/cpp-workflow-project/SKILL.md +1 -1
- package/templates/cpp-workflow-project/environment.json +4 -4
- package/skills/developing-cpp/references/design/examples/05-library-split.md +0 -8
- package/skills/developing-cpp/references/language/standard-library/10-library-checklist.md +0 -10
- package/skills/developing-cpp/references/naming/examples/02-naming-basic.md +0 -4
- package/skills/developing-cpp/references/naming/examples/10-naming-rename.md +0 -6
- package/skills/engineering/references/formatting/examples/04-config-comments.md +0 -70
- /package/skills/developing-cpp/references/language/standard-library/{08-random.md → 09-random.md} +0 -0
|
@@ -5,14 +5,14 @@
|
|
|
5
5
|
|
|
6
6
|
```bash
|
|
7
7
|
clang-tidy -p build/clang \
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
--header-filter="^$(pwd -P)/" \
|
|
9
|
+
--warnings-as-errors='*' \
|
|
10
|
+
src/*.cpp app/*.cpp tests/*.cpp
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
- `-p` 指向当前编译器的构建目录,读取 `compile_commands.json`。
|
|
14
14
|
- `--header-filter` 控制哪些头文件的诊断被显示,不改变 clang-tidy 实际解析哪些头;模板实例化可能让一条根因产生多条警告,警告条数不等于缺陷条数。按根因修,不要按条数修。
|
|
15
|
-
- `--header-filter`
|
|
15
|
+
- `--header-filter` 默认用工程根前缀 `^$(pwd -P)/`,只显示工程内头文件的诊断;工程根里还放着第三方头时,收窄成源码根白名单,如 `(include|src|app|tests)`,不要用 `.*` 把系统头和第三方头一并纳入。它是对头文件名的正则;`$(pwd -P)` 只是拼出绝对路径前缀的写法,不是文档强制。`--exclude-header-filter` 到 clang-tidy 19 才加入,16/17/18 都没有,不要依赖它。
|
|
16
16
|
- 系统头默认被排除,不要加 `--system-headers`。
|
|
17
17
|
- 只扫描项目源文件;不要把 `build/` 或第三方源码传给 clang-tidy。
|
|
18
18
|
- `--warnings-as-errors='*'` 把警告当失败;修代码,不要新增 `NOLINT`。确需抑制时写 `// NOLINT(检查名): 理由`,理由必须具体。
|
|
@@ -36,7 +36,7 @@ clang-tidy -p build/clang \
|
|
|
36
36
|
|
|
37
37
|
## 版本与一致性
|
|
38
38
|
|
|
39
|
-
- `
|
|
39
|
+
- 工具版本下限与 clang/gcc 模式的组合要求见 `building-cpp` 的 `02-environment.md`「版本与能力」,本文件不重复数值。Apple Clang 与 Homebrew LLVM 混装时,仍按同一 LLVM 主版本要求处理:工具版本不一致就统一到同一套工具链,不改检查项来迁就。
|
|
40
40
|
- 混版本常见症状:格式化结果与 CI 不同、clangd 诊断与 tidy 不一致、选项被静默忽略。
|
|
41
41
|
- 检查器在 `--live` 时核对版本;不要用「能跑就行」绕过。
|
|
42
42
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<!-- 读取时机:排版或工具配置时;读完能回答:clangd 与编辑器;预算:一次只开这一份(
|
|
1
|
+
<!-- 读取时机:排版或工具配置时;读完能回答:clangd 与编辑器;预算:一次只开这一份(84 行),不自动串联。 -->
|
|
2
2
|
# clangd 与编辑器
|
|
3
3
|
|
|
4
4
|
## clangd
|
|
@@ -7,13 +7,13 @@
|
|
|
7
7
|
|
|
8
8
|
```yaml
|
|
9
9
|
CompileFlags:
|
|
10
|
-
|
|
10
|
+
CompilationDatabase: build/clang
|
|
11
11
|
Diagnostics:
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
Suppress:
|
|
13
|
+
- pp_file_not_found
|
|
14
14
|
```
|
|
15
15
|
|
|
16
|
-
- `CompilationDatabase` 指向当前编译器目录;GCC 模式改 `build/gcc`。项目技能声明单一构建目录时指向该目录(如 `games/tictactoe/build
|
|
16
|
+
- `CompilationDatabase` 指向当前编译器目录;GCC 模式改 `build/gcc`。项目技能声明单一构建目录时指向该目录(如 `games/tictactoe/build`),不再按编译器分目录。目录必须与 `environment.json` 的 `compiler` 一致,切换编译器时两处同改。
|
|
17
17
|
- 不要在 `.clangd` 写 `-std`:它会覆盖 `compile_commands.json`,把 C++23 工程降成旧标准。标准只由构建声明和编译数据库决定。
|
|
18
18
|
- 静态检查规则只在 `.clang-tidy` 里维护;clangd 读取同一份配置,不要在这里复制检查列表。
|
|
19
19
|
- `Suppress` 只放确实无法避免的解析噪声(如 `pp_file_not_found`),并写理由。
|
|
@@ -26,11 +26,11 @@ Diagnostics:
|
|
|
26
26
|
|
|
27
27
|
```jsonc
|
|
28
28
|
{
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
"clangd.arguments": [
|
|
30
|
+
"--query-driver=/usr/bin/clang++",
|
|
31
|
+
"--header-insertion=never",
|
|
32
|
+
"--background-index"
|
|
33
|
+
]
|
|
34
34
|
}
|
|
35
35
|
```
|
|
36
36
|
|
|
@@ -45,38 +45,31 @@ Diagnostics:
|
|
|
45
45
|
|
|
46
46
|
```json
|
|
47
47
|
{
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
48
|
+
"recommendations": [
|
|
49
|
+
"llvm-vs-code-extensions.vscode-clangd",
|
|
50
|
+
"ms-vscode.cmake-tools",
|
|
51
|
+
"ms-vscode.cpptools"
|
|
52
|
+
]
|
|
53
53
|
}
|
|
54
54
|
```
|
|
55
55
|
|
|
56
|
-
`.vscode/settings.json`
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
"MIMode": "lldb",
|
|
74
|
-
"miDebuggerPath": "/usr/bin/lldb",
|
|
75
|
-
"stopAtEntry": false
|
|
76
|
-
},
|
|
77
|
-
"C_Cpp.intelliSenseEngine": "disabled"
|
|
78
|
-
}
|
|
79
|
-
```
|
|
56
|
+
`.vscode/settings.json` 的键、作用与取值规则(完整可复制件在 `building-cpp` 的 `assets/config/.vscode/settings.json`;工程内实际取值由该步骤落):
|
|
57
|
+
|
|
58
|
+
| 键 | 作用 | 取值规则 |
|
|
59
|
+
| --- | --- | --- |
|
|
60
|
+
| `clangd.arguments` | 传给 clangd 的参数 | `--query-driver=<绝对路径>` 与 `environment.json` 的编译器一致;只列当前构建用的一个驱动,确有多个时按上文用逗号分隔,不写 `*`;`--header-insertion=never`;`--background-index` |
|
|
61
|
+
| `cmake.buildDirectory` | 构建目录与编译数据库位置 | 与 `.clangd` 的 `CompilationDatabase` 同一目录:默认 `build/<compiler>`,工程声明单一目录时写该目录 |
|
|
62
|
+
| `cmake.generator` | 生成器 | `Ninja`,与入口脚本一致 |
|
|
63
|
+
| `cmake.configureOnOpen` | 打开工程时自动配置 | `false`,配置时机由入口脚本决定 |
|
|
64
|
+
| `cmake.buildBeforeRun` | 运行前先构建 | `true`,避免跑到旧产物 |
|
|
65
|
+
| `cmake.exportCompileCommandsFile` | 导出编译数据库 | `true`,供 clangd 与 clang-tidy 读取 |
|
|
66
|
+
| `cmake.debugConfig` | 调试后端 | `type` 仍是 `cppdbg`;clang 模式 `MIMode: lldb`、`miDebuggerPath: /usr/bin/lldb`,GCC 模式换 `gdb` 与其绝对路径 |
|
|
67
|
+
| `C_Cpp.intelliSenseEngine` | C/C++ 扩展的语言服务 | `disabled`,只保留 clangd |
|
|
68
|
+
| `editor.formatOnSave` | 保存即格式化 | 由工程决定;构建脚本不跑 `clang-format -i` |
|
|
69
|
+
| `[cpp]`、`[c]` 的 `editor.defaultFormatter` | 默认格式化器 | `llvm-vs-code-extensions.vscode-clangd` |
|
|
70
|
+
| `files.associations` | 头文件按哪种语言解析 | `*.h` 用 `cpp` |
|
|
71
|
+
| `files.encoding`、`files.eol` | 保存编码与行尾 | `utf8` 与 `\n`,与 `.editorconfig`、`.gitattributes`、`LineEnding: LF` 一致 |
|
|
72
|
+
| `files.exclude`、`search.exclude` | 隐藏构建产物与缓存 | `**/build`、`**/.cache` |
|
|
80
73
|
|
|
81
74
|
- 配置、构建、运行和调试只从 CMake Tools 进入;不要同时维护 `tasks.json` 或 `launch.json`,否则会出现第二套构建或启动路径。
|
|
82
75
|
- C/C++ 扩展只作为 CMake 快速调试的 `cppdbg` 后端;IntelliSense 关闭,补全、跳转、诊断和格式化只由 clangd 提供。
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
<!-- 读取时机:写或改配置文件注释、判注释句式时;读完能回答:配置文件注释的句式、抬头与固定值配置;预算:一次只开这一份(87 行),不自动串联。 -->
|
|
2
|
+
# 配置文件注释
|
|
3
|
+
|
|
4
|
+
配置分两类:运行时配置(如 `runtime.config`、`*.toml`、`*.ini`)一个键一项,注释写契约与后果;固定值配置(`.editorconfig`、`.clang-format`、`.clang-tidy`、`.clangd`、`.vscode/*.json`)的键与取值直白,注释写一句简短说明。
|
|
5
|
+
|
|
6
|
+
## 键注释
|
|
7
|
+
|
|
8
|
+
运行时配置的键注释用「对象:条件时,后果。」:对象与键名对得上,条件写清比较对象,后果写清谁报错、报什么;同类键取同一句式,便于并排核对。
|
|
9
|
+
|
|
10
|
+
**好**(完整文件):
|
|
11
|
+
|
|
12
|
+
```toml
|
|
13
|
+
# 本工程的工具配置。
|
|
14
|
+
#
|
|
15
|
+
# 定义构建工具路径与最低版本。
|
|
16
|
+
|
|
17
|
+
# ================================ 构建 ================================
|
|
18
|
+
|
|
19
|
+
# 构建工具的可执行文件:路径不存在或不可执行时,检查脚本报错退出。
|
|
20
|
+
build_tool = "/usr/bin/ninja"
|
|
21
|
+
|
|
22
|
+
# 构建工具的最低版本:版本低于此值时,检查脚本报错退出。
|
|
23
|
+
build_tool_min_version = "1.11"
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
**差**:
|
|
27
|
+
|
|
28
|
+
```toml
|
|
29
|
+
# build tool 路径
|
|
30
|
+
build_tool = "/usr/bin/ninja"
|
|
31
|
+
# 版本低于此值时报错退出
|
|
32
|
+
build_tool_min_version = "1.11"
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
第一条复述键名;第二条没有比较对象与执行者。`sed` 取值、CI 步骤这类实现细节同样不写进注释:注释给的是读者要遵守的契约与违反后的后果。
|
|
36
|
+
|
|
37
|
+
## 注释语法
|
|
38
|
+
|
|
39
|
+
- TOML 配置只有 `#` 一种注释;`#` 后空一格,句末用句号。JSON 只有 `.vscode/` 下的 `settings.json` 与 `extensions.json` 按 JSONC 写 `//`(见 `01-encoding.md`),其他 `.json`(如 `environment.json`)按 RFC 8259 不写注释;`.clang-format` 等 YAML 用 `#`。
|
|
40
|
+
- 注释紧贴键的上一行,键与注释之间不空行;不写行尾注释。
|
|
41
|
+
- 键块(注释 + 键)内部不空行,键块之间空一行。
|
|
42
|
+
- 文件有两个及以上对象时,每区第一行写一行 80 列等号横幅,标题居中,前后各空一行;`.editorconfig` 的横幅紧贴其下的节头,节按文件后缀分组,不按本仓目录命名。
|
|
43
|
+
- 数组键(用到时):键名后换行,一项一行,收尾 `]` 顶格;不给数组项加行尾注释。
|
|
44
|
+
|
|
45
|
+
## 抬头
|
|
46
|
+
|
|
47
|
+
标题不是必需:需要交代文件整体用途时写一行标题,第二行写 `#`,其后一到两行写文件内容或例外(`building-cpp` 的 `assets/config/.clang-format` 只有标题、`#` 与一行用途);只写内容,不写取舍理由、工具来源与跨文件关系;动词按文件性质取(定义、规定、约定),不要求统一用「定义」。
|
|
48
|
+
|
|
49
|
+
## 固定值配置
|
|
50
|
+
|
|
51
|
+
键注释写一句简短的中文说明,如 `# 每级缩进 4 个空格。`、`# 换行符用 CRLF。`;不套运行时的「对象:条件时,后果。」,也不写「对象:取值。」的词典式短句。
|
|
52
|
+
|
|
53
|
+
**好**:
|
|
54
|
+
|
|
55
|
+
```text
|
|
56
|
+
# 每级缩进 4 个空格。
|
|
57
|
+
indent_size = 4
|
|
58
|
+
|
|
59
|
+
# 换行符用 CRLF,提交时由 .gitattributes 归一。
|
|
60
|
+
end_of_line = crlf
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
**差**:
|
|
64
|
+
|
|
65
|
+
```text
|
|
66
|
+
# 缩进配置:未按 4 个空格缩进时,clang-format 报错退出。
|
|
67
|
+
indent_size = 4
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
固定值配置没有运行时那样的错误后果,套用后果句式会凭空承诺一个不存在的检查。
|
|
71
|
+
|
|
72
|
+
## 模板
|
|
73
|
+
|
|
74
|
+
新建运行时配置时按下面的骨架写,替换尖括号内容;键名与取值按项目实际,分组与句式不变;多对象时按正例加区域横幅,等号补到 80 列。第三行的动词按「抬头」一节取,骨架用「定义」只是示例。模板只示意标量键,用到数组键时按「注释语法」末条写。
|
|
75
|
+
|
|
76
|
+
```text
|
|
77
|
+
# <项目>的<用途>配置。
|
|
78
|
+
#
|
|
79
|
+
# 定义<条目>。
|
|
80
|
+
|
|
81
|
+
# ============================== <对象> ==============================
|
|
82
|
+
|
|
83
|
+
# <对象>:<条件>时,<执行者>报错退出。
|
|
84
|
+
<键> = "<值>"
|
|
85
|
+
|
|
86
|
+
# <对象>:<条件>时,<执行者>报错退出。
|
|
87
|
+
<键> = "<值>"
|
|
88
|
+
```
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
|
|
8
8
|
```yaml
|
|
9
9
|
Checks: >
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
-*,
|
|
11
|
+
bugprone-*
|
|
12
12
|
```
|
|
13
13
|
|
|
14
14
|
只留一族,其他全关,且没有理由。
|
|
@@ -17,9 +17,9 @@ Checks: >
|
|
|
17
17
|
|
|
18
18
|
```yaml
|
|
19
19
|
Checks: >
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
-*,
|
|
21
|
+
google-*,
|
|
22
|
+
readability-identifier-naming
|
|
23
23
|
```
|
|
24
24
|
|
|
25
25
|
保留 Google 检查主体和项目命名规则;关闭项逐条写理由,不整族关闭。不设 `FunctionCase`,Google 允许 `count()` / `set_count()` 这类访问器。
|
|
@@ -38,7 +38,7 @@ clang-tidy -p build/clang --system-headers src/main.cpp
|
|
|
38
38
|
|
|
39
39
|
```bash
|
|
40
40
|
clang-tidy -p build/clang --header-filter="^$(pwd -P)/(include|src)/" \
|
|
41
|
-
|
|
41
|
+
--warnings-as-errors='*' src/main.cpp
|
|
42
42
|
```
|
|
43
43
|
|
|
44
44
|
`--header-filter` 只列项目顶层目录,避免把第三方头纳入;系统头默认排除。工程有别的顶层目录时按实际替换。
|
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
```yaml
|
|
9
9
|
# .clangd
|
|
10
10
|
CompileFlags:
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
CompilationDatabase: build/clang
|
|
12
|
+
Add:
|
|
13
|
+
- --query-driver=/usr/bin/clang++
|
|
14
14
|
```
|
|
15
15
|
|
|
16
16
|
`--query-driver` 是 clangd 的命令行参数,不是 `.clangd` 的 YAML 键;写在这里不会生效。
|
|
@@ -20,17 +20,17 @@ CompileFlags:
|
|
|
20
20
|
```yaml
|
|
21
21
|
# .clangd
|
|
22
22
|
CompileFlags:
|
|
23
|
-
|
|
23
|
+
CompilationDatabase: build/clang
|
|
24
24
|
```
|
|
25
25
|
|
|
26
26
|
```jsonc
|
|
27
27
|
// .vscode/settings.json
|
|
28
28
|
{
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
"clangd.arguments": [
|
|
30
|
+
"--query-driver=/usr/bin/clang++",
|
|
31
|
+
"--header-insertion=never",
|
|
32
|
+
"--background-index"
|
|
33
|
+
]
|
|
34
34
|
}
|
|
35
35
|
```
|
|
36
36
|
|
|
@@ -41,16 +41,16 @@ CompileFlags:
|
|
|
41
41
|
```yaml
|
|
42
42
|
# 工程已经在 CMake 里声明 C++23
|
|
43
43
|
CompileFlags:
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
CompilationDatabase: build/clang
|
|
45
|
+
Add:
|
|
46
|
+
- -std=c++20 # 覆盖 compile_commands.json,C++23 补全/诊断全部降级
|
|
47
47
|
```
|
|
48
48
|
|
|
49
49
|
**好**:
|
|
50
50
|
|
|
51
51
|
```yaml
|
|
52
52
|
CompileFlags:
|
|
53
|
-
|
|
53
|
+
CompilationDatabase: build/clang
|
|
54
54
|
```
|
|
55
55
|
|
|
56
56
|
标准只来自 `compile_commands.json`。没有数据库时先回到定构建生成,不要在 `.clangd` 里猜一个 `-std`。
|
|
@@ -61,17 +61,17 @@ CompileFlags:
|
|
|
61
61
|
|
|
62
62
|
```yaml
|
|
63
63
|
CompileFlags:
|
|
64
|
-
|
|
64
|
+
CompilationDatabase: build/clang # 项目已切到 GCC,这里仍读 clang 的数据库
|
|
65
65
|
```
|
|
66
66
|
|
|
67
67
|
**好**:
|
|
68
68
|
|
|
69
69
|
```yaml
|
|
70
70
|
CompileFlags:
|
|
71
|
-
|
|
71
|
+
CompilationDatabase: build/gcc
|
|
72
72
|
```
|
|
73
73
|
|
|
74
|
-
|
|
74
|
+
目录与 `compiler` 的一致性要求见 `../04-clangd.md`;默认 clang 用 `build/clang`,切换 GCC 时改成 `build/gcc`,不要两套配置并存。
|
|
75
75
|
|
|
76
76
|
## 版本混装
|
|
77
77
|
|
|
@@ -89,7 +89,7 @@ clang++ 18, clang-format 17, clangd 16
|
|
|
89
89
|
clang++ 18.1.8, clang-format 18.1.8, clang-tidy 18.1.8, clangd 18.1.8
|
|
90
90
|
```
|
|
91
91
|
|
|
92
|
-
同主版本;`--live`
|
|
92
|
+
同主版本;`--live` 会核对。混装时的处理见 `../03-clang-tidy.md`「版本与一致性」。
|
|
93
93
|
|
|
94
94
|
## 把标准差异当成检查项
|
|
95
95
|
|
|
@@ -8,14 +8,15 @@
|
|
|
8
8
|
| 文件 | 读完能回答 | 预算 |
|
|
9
9
|
| --- | --- | --- |
|
|
10
10
|
| `cmake/linking/01-libraries.md` | 链接与库边界 | 一次只开这一份(62 行),不自动串联。 |
|
|
11
|
-
| `cmake/linking/02-rpath.md` | 输出目录与 RPATH | 一次只开这一份(
|
|
11
|
+
| `cmake/linking/02-rpath.md` | 输出目录与 RPATH | 一次只开这一份(24 行),不自动串联。 |
|
|
12
12
|
| `cmake/linking/03-undefined-reference.md` | undefined reference 分诊 | 一次只开这一份(20 行),不自动串联。 |
|
|
13
13
|
| `cmake/linking/04-inspect.md` | 验收:file 与 ldd | 一次只开这一份(20 行),不自动串联。 |
|
|
14
14
|
| `cmake/modules/01-functions.md` | CMake 模块与函数 | 一次只开这一份(119 行),不自动串联。 |
|
|
15
15
|
| `cmake/standards/01-cxx-standard.md` | C++ 标准与 CMake | 一次只开这一份(68 行),不自动串联。 |
|
|
16
16
|
| `cmake/standards/versions.md` | C++11–C++23 各档差异 | 一次只开这一份(43 行),不自动串联。 |
|
|
17
|
+
| `cmake/standards/index.md` | 标准选择表、工具共用矩阵与验证矩阵 | 一次只开这一份(144 行),不自动串联。 |
|
|
17
18
|
| `cmake/standards/examples/01-standard.md` | 正反例:标准只写一半 | 一次只开这一份(19 行),不自动串联。 |
|
|
18
|
-
| `cmake/targets/01-target-rules.md` | target、标准与产物目录 | 一次只开这一份(
|
|
19
|
+
| `cmake/targets/01-target-rules.md` | target、标准与产物目录 | 一次只开这一份(237 行),不自动串联。 |
|
|
19
20
|
| `cmake/targets/examples/01-rpath.md` | 正反例:共享库运行时路径 | 一次只开这一份(24 行),不自动串联。 |
|
|
20
21
|
| `cmake/testing/01-ctest.md` | 测试与 CTest | 一次只开这一份(61 行),不自动串联。 |
|
|
21
22
|
|
|
@@ -26,8 +27,8 @@
|
|
|
26
27
|
| `formatting/01-encoding.md` | 编码与行尾 | 一次只开这一份(54 行),不自动串联。 |
|
|
27
28
|
| `formatting/02-clang-format.md` | clang-format | 一次只开这一份(23 行),不自动串联。 |
|
|
28
29
|
| `formatting/03-clang-tidy.md` | clang-tidy 与静态检查门禁 | 一次只开这一份(58 行),不自动串联。 |
|
|
29
|
-
| `formatting/04-clangd.md` | clangd 与编辑器 | 一次只开这一份(
|
|
30
|
+
| `formatting/04-clangd.md` | clangd 与编辑器 | 一次只开这一份(84 行),不自动串联。 |
|
|
31
|
+
| `formatting/05-config-comments.md` | 配置文件注释的句式与抬头 | 一次只开这一份(87 行),不自动串联。 |
|
|
30
32
|
| `formatting/examples/01-clang-format.md` | 正反例:clang-format | 一次只开这一份(47 行),不自动串联。 |
|
|
31
33
|
| `formatting/examples/02-clang-tidy.md` | 正反例:clang-tidy | 一次只开这一份(43 行),不自动串联。 |
|
|
32
34
|
| `formatting/examples/03-clangd.md` | 正反例:clangd | 一次只开这一份(109 行),不自动串联。 |
|
|
33
|
-
| `formatting/examples/04-config-comments.md` | 正反例:配置文件注释 | 一次只开这一份(69 行),不自动串联。 |
|