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:
@@ -32,6 +32,7 @@ stages:
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y clang-tidy clang-format cmake build-essential
|
||||
clang-tidy --version
|
||||
cmake --version
|
||||
|
||||
- task: Bash@3
|
||||
displayName: 'Check Code Format'
|
||||
@@ -42,14 +43,26 @@ stages:
|
||||
find src tests -name "*.cpp" -o -name "*.h" | xargs clang-format --dry-run --Werror
|
||||
|
||||
- task: Bash@3
|
||||
displayName: 'Run clang-tidy on all files'
|
||||
displayName: 'Configure build (export compile_commands)'
|
||||
inputs:
|
||||
targetType: 'inline'
|
||||
script: |
|
||||
echo "Running clang-tidy..."
|
||||
find src tests -name "*.cpp" -o -name "*.h" | xargs clang-tidy --config-file=.clang-tidy
|
||||
echo "Configuring CMake to export compile_commands.json..."
|
||||
mkdir -p build
|
||||
cd build
|
||||
cmake .. -DCMAKE_BUILD_TYPE=${{ variables.buildConfiguration }} -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
|
||||
ls -la
|
||||
|
||||
# 階段一:只顯示警告,不中斷 CI
|
||||
- task: Bash@3
|
||||
displayName: 'Run clang-tidy on all files (advisory)'
|
||||
inputs:
|
||||
targetType: 'inline'
|
||||
script: |
|
||||
echo "Running clang-tidy (Phase 1: advisory only)..."
|
||||
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" \))
|
||||
if [ -n "$FILES" ]; then
|
||||
echo "$FILES" | xargs -r clang-tidy -p build --config-file=.clang-tidy || true
|
||||
fi
|
||||
echo "Linter completed. Review warnings above."
|
||||
|
||||
- task: Bash@3
|
||||
@@ -57,7 +70,6 @@ stages:
|
||||
inputs:
|
||||
targetType: 'inline'
|
||||
script: |
|
||||
mkdir build
|
||||
cd build
|
||||
cmake .. -DCMAKE_BUILD_TYPE=${{ variables.buildConfiguration }}
|
||||
make -j$(nproc)
|
||||
@@ -81,8 +93,18 @@ stages:
|
||||
targetType: 'inline'
|
||||
script: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y clang-tidy
|
||||
sudo apt-get install -y clang-tidy cmake build-essential
|
||||
cmake --version
|
||||
|
||||
- task: Bash@3
|
||||
displayName: 'Configure build (export compile_commands)'
|
||||
inputs:
|
||||
targetType: 'inline'
|
||||
script: |
|
||||
echo "Configuring CMake to export compile_commands.json for PR analysis..."
|
||||
mkdir -p build
|
||||
cd build
|
||||
cmake .. -DCMAKE_BUILD_TYPE=${{ variables.buildConfiguration }} -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
|
||||
- task: Bash@3
|
||||
displayName: 'Analyze Changed Files Only'
|
||||
inputs:
|
||||
@@ -102,5 +124,5 @@ stages:
|
||||
echo "Changed C++ files:"
|
||||
echo "$CHANGED_FILES"
|
||||
|
||||
echo "Running clang-tidy on changed files..."
|
||||
echo "$CHANGED_FILES" | xargs clang-tidy --config-file=.clang-tidy -- -std=c++98
|
||||
echo "Running clang-tidy on changed files (advisory)..."
|
||||
echo "$CHANGED_FILES" | xargs -r clang-tidy -p build --config-file=.clang-tidy || true
|
||||
|
Reference in New Issue
Block a user