#!/usr/bin/env bash
#MISE alias=["format"]
set -euxo pipefail

# Used for shellcheck which needs explicit args
scripts=("$PWD"/scripts/*.sh "$PWD"/e2e/{test_,run_}* "$PWD"/e2e/*.sh)
# Used for shfmt which will run only on files it can
scripts_dirs=("$PWD"/scripts "$PWD"/e2e)
cargo clippy --fix --allow-staged --allow-dirty -- -Dwarnings
shellcheck -x "${scripts[@]}"
shfmt -w  -i 2 -ci -bn "${scripts_dirs[@]}"
prettier -w $(git ls-files '*.yml' '*.yaml')
markdownlint --fix .
actionlint
toml-sort -i settings.toml --spaces-indent-inline-array 4

cat >rustfmt.toml <<EOF
unstable_features = true
imports_granularity = "Module"
EOF
cargo fmt --all
rm rustfmt.toml
