Files
cpp-linter-template/scripts/run-linter.sh
MH Hung f55d10ee07 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
2025-09-09 22:52:34 +08:00

40 lines
1.2 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# 本地執行 linter 的腳本
echo "Running clang-tidy on C++ files..."
# 檢查 clang-tidy 是否存在
if ! command -v clang-tidy &> /dev/null; then
echo "clang-tidy not found. Please install it first."
echo "Ubuntu/Debian: sudo apt install clang-tidy"
echo "macOS: brew install llvm"
exit 1
fi
# 尋找所有 C++ 檔案
CPP_FILES=$(find src tests -type f \( -name "*.cpp" -o -name "*.cxx" -o -name "*.cc" -o -name "*.c++" -o -name "*.h" -o -name "*.hpp" -o -name "*.hxx" \) 2>/dev/null)
if [ -z "$CPP_FILES" ]; then
echo "No C++ files found."
exit 0
fi
echo "Found files:"
echo "$CPP_FILES"
echo
# 若存在 compile_commands.json則使用 -p 指向 build 目錄以提高精準度
TIDY_CMD_BASE=(clang-tidy --config-file=.clang-tidy)
if [ -f "build/compile_commands.json" ]; then
echo "Detected build/compile_commands.json; using -p build"
TIDY_CMD_BASE+=( -p build )
else
echo "No compile_commands.json detected. For better results, run:"
echo " mkdir -p build && cd build && cmake .. -DCMAKE_EXPORT_COMPILE_COMMANDS=ON && cd -"
fi
# 執行 clang-tidy保持 Phase 1僅回報不讓流程失敗
echo "$CPP_FILES" | xargs -r "${TIDY_CMD_BASE[@]}"
echo "Linter check completed."