#!/usr/bin/env bash set -euo pipefail BUILD_DIR=build if [ ! -f "${BUILD_DIR}/compile_commands.json" ]; then echo "compile_commands.json not found; running cmake configure..." cmake -S . -B "${BUILD_DIR}" -DCMAKE_EXPORT_COMPILE_COMMANDS=ON fi if ! command -v clang-tidy >/dev/null 2>&1; then echo "clang-tidy not found in PATH" exit 1 fi # Prefer files tracked by git; fallback to find if git rev-parse --is-inside-work-tree >/dev/null 2>&1; then FILES=$(git ls-files '*.cpp' '*.cxx' '*.cc' '*.h' '*.hpp' || true) else FILES=$(find . -iname "*.cpp" -o -iname "*.cc" -o -iname "*.cxx" -o -iname "*.h" -o -iname "*.hpp") fi if [ -z "${FILES}" ]; then echo "No source files found for clang-tidy" exit 0 fi for f in ${FILES}; do echo "Running clang-tidy on ${f}" clang-tidy "${f}" -p "${BUILD_DIR}" || true done