From b2d63c2b6dd61f7170590fc325b14f9355fef085 Mon Sep 17 00:00:00 2001 From: Julian Pawlowski Date: Sun, 12 Apr 2026 12:11:38 +0000 Subject: [PATCH] chore(scripts): add explicit format/fix/check modes for all file types Split lint workflow into three clearly separated modes: - scripts/format: Python-only formatting (Ruff format) - scripts/lint-fix: Python-only lint auto-fixes (Ruff check --fix) - scripts/lint: convenience wrapper (delegates to format + lint-fix) Add all-in-one scripts covering Python and non-Python files (Prettier for JSON/JSONC/Markdown/YAML, shfmt for shell scripts): - scripts/format-all: format all file types - scripts/check-all: check-only for all file types (CI/CD parity) - scripts/lint-all: format-all + lint-fix in one command Release-Notes: skip User-Impact: none --- scripts/check-all | 54 ++++++++++++++++++++++++++++++++++++++++++++++ scripts/format | 33 ++++++++++++++++++++++++++++ scripts/format-all | 54 ++++++++++++++++++++++++++++++++++++++++++++++ scripts/lint | 27 ++++++----------------- scripts/lint-all | 19 ++++++++++++++++ scripts/lint-fix | 33 ++++++++++++++++++++++++++++ 6 files changed, 199 insertions(+), 21 deletions(-) create mode 100755 scripts/check-all create mode 100755 scripts/format create mode 100755 scripts/format-all create mode 100755 scripts/lint-all create mode 100755 scripts/lint-fix 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"