good morning!!!!

Skip to content
Snippets Groups Projects
fmt.sh 967 B
Newer Older
Anmol Sethi's avatar
Anmol Sethi committed
#!/usr/bin/env bash

set -euo pipefail
Anmol Sethi's avatar
Anmol Sethi committed
cd "$(dirname "${0}")"
cd "$(git rev-parse --show-toplevel)"
Anmol Sethi's avatar
Anmol Sethi committed

gen() {
  # Unfortunately, this is the only way to ensure go.mod and go.sum are correct.
  # See https://github.com/golang/go/issues/27005
  go list ./... > /dev/null
  go mod tidy
Anmol Sethi's avatar
Anmol Sethi committed

  go generate ./...
}
Anmol Sethi's avatar
Anmol Sethi committed

fmt() {
  gofmt -w -s .
  go run go.coder.com/go-tools/cmd/goimports -w "-local=$(go list -m)" .
Anmol Sethi's avatar
Anmol Sethi committed
  go run mvdan.cc/sh/cmd/shfmt -i 2 -w -s -sr .
  # shellcheck disable=SC2046
  npx prettier \
    --write \
    --print-width 120 \
    --no-semi \
    --trailing-comma all \
    --loglevel silent \
    $(git ls-files "*.yaml" "*.yml" "*.md")
Anmol Sethi's avatar
Anmol Sethi committed

unstaged_files() {
  git ls-files --other --modified --exclude-standard
Anmol Sethi's avatar
Anmol Sethi committed
}

Anmol Sethi's avatar
Anmol Sethi committed
  if [[ ${CI-} && $(unstaged_files) != "" ]]; then
    echo "Files need generation or are formatted incorrectly."
Anmol Sethi's avatar
Anmol Sethi committed
    echo "Run:"
    echo "./ci/fmt.sh"
    echo
    git status
    git diff