#!/usr/bin/env bash
#
# Format all files in the project
#
# Copyright 2025 Google LLC
# SPDX-License-Identifier: Apache-2.0
#set -x # Uncomment to enable tracing.
set -euo pipefail
if ((EUID == 0)); then
echo "Please do not run as root"
exit
fi
TOP_DIR=$(git rev-parse --show-toplevel)
# Add license header to all files that don't already have it.
"${TOP_DIR}/bin/add_license"
# Format all TOML files.
"${TOP_DIR}/bin/format_toml_files"
if [[ $? -ne 0 ]]; then
exit 1
fi
# Format all Python code while organizing imports.
uv run --directory "${TOP_DIR}/py" ruff check --select I --fix --preview --unsafe-fixes .
uv run --directory "${TOP_DIR}/py" ruff format .
if [[ $? -ne 0 ]]; then
exit 1
fi
# Format all Go code.
go fmt -C "${TOP_DIR}/go" ./...
if [[ $? -ne 0 ]]; then
exit 1
fi
# Format all TypeScript code.
#
# TODO: Re-enable once we have biome configured and enabled because that is
# several times faster and compatible.
#
#pushd ${TOP_DIR}
#pnpm run format
#if [[ $? -ne 0 ]]; then
# exit 1
#fi
#popd