#!/usr/bin/env bash set -euo pipefail REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" cd "$REPO_ROOT" MODE="default" CHECKS=() usage() { cat <<'EOF' Usage: scripts/lint.sh [check ...] [--hook|--ci] Checks: format cppcheck actionlint Modes: --hook Run format --check --git --ci Run format --check plus any available linters Default: format --check EOF } while [[ $# -gt 0 ]]; do case "$1" in --hook) MODE="hook" shift ;; --ci) MODE="ci" shift ;; -h|--help) usage exit 0 ;; --*) printf 'Unknown option: %s\n' "$1" >&2 usage >&2 exit 2 ;; *) CHECKS+=("$1") shift ;; esac done run_format() { "$REPO_ROOT/scripts/format-code.sh" --check "$@" } run_cppcheck() { if command -v cppcheck >/dev/null 2>&1; then "$REPO_ROOT/scripts/check-quality.sh" else printf 'cppcheck not installed; skipping\n' fi } run_actionlint() { if ! command -v actionlint >/dev/null 2>&1; then printf 'actionlint not installed; skipping\n' return 0 fi if [[ ! -d "$REPO_ROOT/.github/workflows" ]]; then printf 'No GitHub workflows found; skipping actionlint\n' return 0 fi actionlint } run_check() { case "$1" in format) shift run_format "$@" ;; cppcheck) run_cppcheck ;; actionlint) run_actionlint ;; *) printf 'Unknown check: %s\n' "$1" >&2 exit 2 ;; esac } if [[ "$MODE" == "hook" ]]; then run_check format --git exit 0 fi if [[ "$MODE" == "ci" ]]; then run_check format run_check cppcheck run_check actionlint exit 0 fi if [[ ${#CHECKS[@]} -eq 0 ]]; then run_check format exit 0 fi for check in "${CHECKS[@]}"; do run_check "$check" done