#!/usr/bin/env bash

set -eu

DIR="$1"

cd "$DIR"

export PATH="$(go env GOPATH)/bin:$PATH"
for FILE in $(find . -name '*.go'); do
  if [ "YES" == "$(bash ./.github/scripts/is_autogenerated_file.sh "$FILE")" ]; then
    echo "Skip autogenerated file: $FILE" >&2
    continue
  fi

  if [[ "$FILE" == *"allocator_go1.18.go"* ]]; then
    echo "Skip allocator_go1.18.go rule: $FILE" >&2
    continue
  fi

  bash ./.github/scripts/format-go-code.sh "$FILE"
done
