Skip to content

Commit

Permalink
Use gofmt to format and lint (#1788)
Browse files Browse the repository at this point in the history
  • Loading branch information
pakrym-stripe authored Dec 19, 2023
1 parent d295abd commit e2b1456
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ check-api-clients:
go run scripts/check_api_clients/main.go

check-gofmt:
scripts/check_gofmt.sh
scripts/gofmt.sh check

lint:
staticcheck
Expand Down Expand Up @@ -39,7 +39,7 @@ update-version:
$(MAKE) normalize-imports

codegen-format: normalize-imports
go fmt ./...
scripts/gofmt.sh
go install golang.org/x/tools/cmd/goimports@latest && goimports -w example/generated_examples_test.go

CURRENT_MAJOR_VERSION := $(shell cat VERSION | sed 's/\..*//')
Expand Down
16 changes: 0 additions & 16 deletions scripts/check_gofmt.sh

This file was deleted.

20 changes: 20 additions & 0 deletions scripts/gofmt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

find_files() {
find . -name '*.go' -not -path "./vendor/*" -not -path "./.git/*"
}

bad_files=$(find_files | xargs gofmt -s -l)

if [[ "$1" == "check" ]]; then
if [[ -n "${bad_files}" ]]; then
echo "!!! gofmt -s needs to be run on the following files: "
echo "${bad_files}"
exit 1
fi
fi

for file in ${bad_files}; do
gofmt -s -w "${file}"
done
exit 0

0 comments on commit e2b1456

Please sign in to comment.