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
This commit is contained in:
Julian Pawlowski 2026-04-12 12:11:38 +00:00
parent 3fda932442
commit b2d63c2b6d
6 changed files with 199 additions and 21 deletions

54
scripts/check-all Executable file
View file

@ -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"

33
scripts/format Executable file
View file

@ -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"

54
scripts/format-all Executable file
View file

@ -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"

View file

@ -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"

19
scripts/lint-all Executable file
View file

@ -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"

33
scripts/lint-fix Executable file
View file

@ -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"