feat(linter): implement Phase 1 linter automation and docs
- Add .clang-tidy (analyzer + selected bugprone) and .clang-format (LLVM, 4-space, 100 cols) - Enhance scripts/run-linter.sh to use compile_commands.json when available - Add scripts/setup-hooks.sh pre-commit (format enforcement; advisory tidy) - Update azure-pipelines.yml to export compile_commands and run clang-tidy -p build - Fill docs/linter-setup.md and docs/coding-standards.md for Phase 1 - Add minimal tests in tests/test_main.cpp to ensure CI executes - Rewrite README with Phase 1 workflow
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
# Coding Standards (Phase 1)
|
||||
|
||||
## 語言與標準
|
||||
- C++98 為主要標準(舊代碼相容)。
|
||||
- 禁止使用危險 API:偏好安全封裝;必要時以註解說明風險與保護措施。
|
||||
|
||||
## 格式(由 `.clang-format` 強制)
|
||||
- BasedOnStyle: LLVM,IndentWidth: 4,ColumnLimit: 100。
|
||||
- 以 pre-commit 與 CI 確保格式一致性。
|
||||
|
||||
## 一般規範
|
||||
- 生命週期:new/delete 成對,避免裸指標長期持有;儘量早釋放資源。
|
||||
- 控制流:避免過深巢狀;優先早回傳以簡化邏輯。
|
||||
- 註解:描述「為何」而非「做什麼」。
|
||||
- 介面:標頭檔最小公開;避免不必要的 include,採前置宣告以降低耦合。
|
||||
|
||||
## Tidy 規則(Phase 1)
|
||||
- 啟用:`clang-analyzer-*` 與精選 `bugprone-*`,聚焦重大缺陷(洩漏、未定義行為)。
|
||||
- 停用:`modernize-*`、`readability-*`(後續階段再逐步導入)。
|
||||
|
||||
## 例外處理
|
||||
- 舊代碼可逐步改善;若需暫時抑制特定告警,請附上註解與追蹤項(TODO/issue)。
|
||||
|
Reference in New Issue
Block a user