diff --git a/scripts/check-all b/scripts/check-all new file mode 100755 index 0000000..2569950 --- /dev/null +++ b/scripts/check-all @@ -0,0 +1,54 @@ +#!/bin/bash + +# script/check-all: Run full checks for Python and non-Python files +# +# Runs project checks and validates formatting/lint state for common +# non-Python files. +# +# Usage: +# ./scripts/check-all +# +# Examples: +# ./scripts/check-all + +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +cd "$SCRIPT_DIR/.." + +# shellcheck source=scripts/.lib/output.sh +source "$SCRIPT_DIR/.lib/output.sh" + +collect_shell_files() { + local files=() + local file shebang + + while IFS= read -r -d '' file; do + shebang="$(head -n 1 "$file" 2>/dev/null || true)" + if [[ $shebang =~ ^\#\!.*(ba|z|k)?sh([[:space:]]|$) ]]; then + files+=("$file") + fi + done < <(find scripts .devcontainer -type f -print0) + + if [[ ${#files[@]} -eq 0 ]]; then + return 0 + fi + + printf '%s\0' "${files[@]}" +} + +log_header "Running Python checks" +"$SCRIPT_DIR/check" + +log_header "Checking JSON/JSONC/Markdown with Prettier" +npx --yes prettier --check "**/*.{json,jsonc,md,yml,yaml}" + +log_header "Checking shell formatting with shfmt" +mapfile -d '' -t shell_files < <(collect_shell_files) +if [[ ${#shell_files[@]} -gt 0 ]]; then + shfmt -d "${shell_files[@]}" +else + log_info "No shell files found" +fi + +log_success "All checks passed" diff --git a/scripts/format b/scripts/format new file mode 100755 index 0000000..4cc7812 --- /dev/null +++ b/scripts/format @@ -0,0 +1,33 @@ +#!/bin/bash + +# script/format: Format code with Ruff formatter +# +# Runs Ruff format and applies formatting changes. Automatically cleans up any +# accidental package installations after running. +# +# Usage: +# ./scripts/format +# +# Examples: +# ./scripts/format + +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +cd "$SCRIPT_DIR/.." + +# shellcheck source=scripts/.lib/output.sh +source "$SCRIPT_DIR/.lib/output.sh" + +if [[ -z ${VIRTUAL_ENV:-} ]]; then + # shellcheck source=/dev/null + source "$HOME/.venv/bin/activate" +fi + +log_header "Running Ruff format" +uv run --active ruff format . + +# Clean up any accidental package installation from uv run +"$SCRIPT_DIR/clean" --minimal + +log_success "Formatting completed" diff --git a/scripts/format-all b/scripts/format-all new file mode 100755 index 0000000..ad6c9f0 --- /dev/null +++ b/scripts/format-all @@ -0,0 +1,54 @@ +#!/bin/bash + +# script/format-all: Format Python and non-Python files +# +# Runs the Python formatter workflow and then formats common non-Python files +# with Prettier and shell scripts with shfmt. +# +# Usage: +# ./scripts/format-all +# +# Examples: +# ./scripts/format-all + +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +cd "$SCRIPT_DIR/.." + +# shellcheck source=scripts/.lib/output.sh +source "$SCRIPT_DIR/.lib/output.sh" + +collect_shell_files() { + local files=() + local file shebang + + while IFS= read -r -d '' file; do + shebang="$(head -n 1 "$file" 2>/dev/null || true)" + if [[ $shebang =~ ^\#\!.*(ba|z|k)?sh([[:space:]]|$) ]]; then + files+=("$file") + fi + done < <(find scripts .devcontainer -type f -print0) + + if [[ ${#files[@]} -eq 0 ]]; then + return 0 + fi + + printf '%s\0' "${files[@]}" +} + +log_header "Formatting Python files" +"$SCRIPT_DIR/format" + +log_header "Formatting JSON/JSONC/Markdown with Prettier" +npx --yes prettier --write "**/*.{json,jsonc,md,yml,yaml}" + +log_header "Formatting shell scripts with shfmt" +mapfile -d '' -t shell_files < <(collect_shell_files) +if [[ ${#shell_files[@]} -gt 0 ]]; then + shfmt -w "${shell_files[@]}" +else + log_info "No shell files found" +fi + +log_success "All formatting completed" diff --git a/scripts/lint b/scripts/lint index 3a56224..e0c42e0 100755 --- a/scripts/lint +++ b/scripts/lint @@ -1,9 +1,10 @@ #!/bin/bash -# script/lint: Run linting tools and apply formatting +# script/lint: Run format and lint-fix in one command # -# Runs Ruff format and Ruff check with auto-fix enabled. Automatically cleans up -# any accidental package installations after running. +# Convenience wrapper that runs scripts/format and scripts/lint-fix in sequence. +# This preserves the previous behavior while exposing explicit 3-mode workflows: +# check, fix, and format. # # Usage: # ./scripts/lint @@ -16,21 +17,5 @@ set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" cd "$SCRIPT_DIR/.." -# shellcheck source=scripts/.lib/output.sh -source "$SCRIPT_DIR/.lib/output.sh" - -if [[ -z ${VIRTUAL_ENV:-} ]]; then - # shellcheck source=/dev/null - source "$HOME/.venv/bin/activate" -fi - -log_header "Running Ruff format" -uv run --active ruff format . - -log_header "Running Ruff check" -uv run --active ruff check . --fix - -# Clean up any accidental package installation from uv run -"$SCRIPT_DIR/clean" --minimal - -log_success "Linting completed" +"$SCRIPT_DIR/format" +"$SCRIPT_DIR/lint-fix" diff --git a/scripts/lint-all b/scripts/lint-all new file mode 100755 index 0000000..fc948df --- /dev/null +++ b/scripts/lint-all @@ -0,0 +1,19 @@ +#!/bin/bash + +# script/lint-all: Apply lint and formatting fixes across file types +# +# Runs Python lint/format workflow and then applies non-Python formatting. +# +# Usage: +# ./scripts/lint-all +# +# Examples: +# ./scripts/lint-all + +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +cd "$SCRIPT_DIR/.." + +"$SCRIPT_DIR/format-all" +"$SCRIPT_DIR/lint-fix" diff --git a/scripts/lint-fix b/scripts/lint-fix new file mode 100755 index 0000000..830ced8 --- /dev/null +++ b/scripts/lint-fix @@ -0,0 +1,33 @@ +#!/bin/bash + +# script/lint-fix: Apply lint fixes with Ruff +# +# Runs Ruff check with auto-fix enabled. Automatically cleans up any accidental +# package installations after running. +# +# Usage: +# ./scripts/lint-fix +# +# Examples: +# ./scripts/lint-fix + +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +cd "$SCRIPT_DIR/.." + +# shellcheck source=scripts/.lib/output.sh +source "$SCRIPT_DIR/.lib/output.sh" + +if [[ -z ${VIRTUAL_ENV:-} ]]; then + # shellcheck source=/dev/null + source "$HOME/.venv/bin/activate" +fi + +log_header "Running Ruff check with auto-fix" +uv run --active ruff check . --fix + +# Clean up any accidental package installation from uv run +"$SCRIPT_DIR/clean" --minimal + +log_success "Lint fixes applied"