feat(clang): add claude suggestion

This commit is contained in:
2025-09-09 11:11:53 +08:00
parent cfc13ff82c
commit d5350c35a8
9 changed files with 360 additions and 1 deletions

View File

@@ -1,4 +1,77 @@
# cpp-linter-template
# C++ Linter Template
這是一個展示如何在 C++ 專案中整合 linter 工具的模板專案。
## 目的
- 展示 clang-tidy 在舊 C++ 代碼中的應用
- 提供漸進式導入 linter 的範例
- Azure DevOps CI/CD 整合範例
## 快速開始
### 1. 本地開發環境設定
```bash
# 安裝相依套件 (Ubuntu/Debian)
sudo apt install clang-tidy clang-format cmake build-essential
# 安裝相依套件 (macOS)
brew install llvm cmake
# 克隆專案
git clone <your-repo-url>
cd cpp-linter-template
```
### 2. 執行 Linter
```bash
# 使用提供的腳本
./scripts/run-linter.sh
# 或手動執行
clang-tidy src/*.cpp src/*.h tests/*.cpp --config-file=.clang-tidy
```
### 3. 建構專案
```bash
mkdir build && cd build
cmake ..
make
./main
```
## Linter 配置說明
### 當前採用階段一設定:
- 只檢查最關鍵的錯誤
- 不會因 linter 警告而中斷 CI
- 適合舊代碼逐步改進
### 後續階段計劃
- 階段二:增加記憶體和資源管理檢查
- 階段三:加入可讀性和現代化建議
- 階段四:強制執行,警告視為錯誤
## 在 Azure DevOps 中使用
1. 將此專案推送到 Azure DevOps
2. 設定 Pipeline 使用 azure-pipelines.yml
3. 建立 Pull Request 時會自動執行 linter
## 自定義配置
編輯 .clang-tidy 檔案來調整檢查規則:
```yaml
# 增加更多檢查
Checks: '-*,clang-analyzer-*,bugprone-*,readability-*'
```
## 檔案說明
`.clang-tidy:` Linter 配置檔
`.clang-format`: 程式碼格式化配置
`azure-pipelines.yml`: Azure DevOps CI/CD 配置
`scripts/run-linter.sh`: 本地執行 linter 腳本
## 注意事項
- 此模板使用 C++98 標準,適合舊代碼
- Linter 設定較為寬鬆,適合逐步導入
- 可以根據團隊需求調整檢查規則
## 專案結構
cpp-linter-template/