format 1010 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/usr/bin/env bash
  2. goimports="goimports"
  3. find_files() {
  4. find . -not \( \
  5. \( \
  6. -wholename './output' \
  7. -o -wholename './_output' \
  8. -o -wholename './_gopath' \
  9. -o -wholename './release' \
  10. -o -wholename './target' \
  11. -o -wholename '*/third_party/*' \
  12. -o -wholename '*/vendor/*' \
  13. \) -prune \
  14. \) -name '*.go'
  15. }
  16. ignore_files=(
  17. "./openstack/compute/v2/extensions/quotasets/testing/fixtures.go"
  18. "./openstack/networking/v2/extensions/vpnaas/ikepolicies/testing/requests_test.go"
  19. )
  20. bad_files=$(find_files | xargs ${goimports} -l)
  21. final_files=()
  22. for bad_file in $bad_files; do
  23. found=
  24. for ignore_file in "${ignore_files[@]}"; do
  25. [[ "${bad_file}" == "${ignore_file}" ]] && { found=1; break; }
  26. done
  27. [[ -n $found ]] || final_files+=("$bad_file")
  28. done
  29. if [[ "${#final_files[@]}" -gt 0 ]]; then
  30. diff=$(echo "${final_files[@]}" | xargs ${goimports} -d -e 2>&1)
  31. if [[ -n "${diff}" ]]; then
  32. echo "${diff}"
  33. exit 1
  34. fi
  35. fi