Repository: supabase/gotrue
Pull request #510 (2022-06-23 13:32:31)

Add Formatting Checks to CI
## What kind of change does this PR introduce?

Add formatting checks

## What is the current behavior?

No checks

## What is the new behavior?

Feel free to include screenshots if it includes visual changes.

## Additional context

Add any other context or screenshots.



Patch:
diff --git a/Makefile b/Makefile
index 9ff09419..6033ff3b 100644
--- a/Makefile
+++ b/Makefile
@@ -53,3 +53,6 @@ docker-build: ## Force a full rebuild of the development containers
 
 docker-clean: ## Remove the development containers and volumes
 	docker-compose -f $(DEV_DOCKER_COMPOSE) rm -fsv
+
+format:
+	go fmt -s -w .
diff --git a/api/admin.go b/api/admin.go
index 8c9c620f..2134ce2d 100644
--- a/api/admin.go
+++ b/api/admin.go
@@ -68,7 +68,7 @@ func (a *API) adminUsers(w http.ResponseWriter, r *http.Request) error {
 		return badRequestError("Bad Pagination Parameters: %v", err)
 	}
 
-	sortParams, err := sort(r, map[string]bool{models.CreatedAt: true}, []models.SortField{models.SortField{Name: models.CreatedAt, Dir: models.Descending}})
+	sortParams, err := sort(r, map[string]bool{models.CreatedAt: true}, []models.SortField{{Name: models.CreatedAt, Dir: models.Descending}})
 	if err != nil {
 		return badRequestError("Bad Sort Parameters: %v", err)
 	}
@@ -175,7 +175,7 @@ func (a *API) adminUserUpdate(w http.ResponseWriter, r *http.Request) error {
 			}
 		}
 
-		if terr := models.NewAuditLogEntry(tx, instanceID, adminUser, models.UserModifiedAction, "",  map[string]interface{}{
+		if terr := models.NewAuditLogEntry(tx, instanceID, adminUser, models.UserModifiedAction, "", map[string]interface{}{
 			"user_id":    user.ID,
 			"user_email": user.Email,
 			"user_phone": user.Phone,
diff --git a/api/audit.go b/api/audit.go
index 13218bbe..b7b95451 100644
--- a/api/audit.go
+++ b/api/audit.go
@@ -8,9 +8,9 @@ import (
 )
 
 var filterColumnMap = map[string][]string{
-	"author": []string{"actor_username", "actor_name"},
-	"action": []string{"action"},
-	"type":   []string{"log_type"},
+	"author": {"actor_username", "actor_name"},
+	"action": {"action"},
+	"type":   {"log_type"},
 }
 
 func (a *API) adminAuditLog(w http.ResponseWriter, r *http.Request) error {
diff --git a/models/audit_log_entry.go b/models/audit_log_entry.go
index ffa942a7..7187a694 100644
--- a/models/audit_log_entry.go
+++ b/models/audit_log_entry.go
@@ -54,9 +54,9 @@ var actionLogTypeMap = map[AuditAction]auditLogType{
 type AuditLogEntry struct {
 	InstanceID uuid.UUID `json:"-" db:"instance_id"`
 	ID         uuid.UUID `json:"id" db:"id"`
-	Payload JSONMap `json:"payload" db:"payload"`
-	CreatedAt time.Time `json:"created_at" db:"created_at"`
-	IPAddress string `json:"ip_address" db:"ip_address"`
+	Payload    JSONMap   `json:"payload" db:"payload"`
+	CreatedAt  time.Time `json:"created_at" db:"created_at"`
+	IPAddress  string    `json:"ip_address" db:"ip_address"`
 }
 
 func (AuditLogEntry) TableName() string {
diff --git a/models/instance.go b/models/instance.go
index 009c456a..4cd2ba7f 100644
--- a/models/instance.go
+++ b/models/instance.go
@@ -74,8 +74,8 @@ func GetInstanceByUUID(tx *storage.Connection, uuid uuid.UUID) (*Instance, error
 func DeleteInstance(conn *storage.Connection, instance *Instance) error {
 	return conn.Transaction(func(tx *storage.Connection) error {
 		delModels := map[string]*pop.Model{
-			"user":          &pop.Model{Value: &User{}},
-			"refresh token": &pop.Model{Value: &RefreshToken{}},
+			"user":          {Value: &User{}},
+			"refresh token": {Value: &RefreshToken{}},
 		}
 
 		for name, dm := range delModels {


Test patch:
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index bcdc7830..e445886c 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -33,6 +33,8 @@ jobs:
           go-version: ${{ matrix.go-version }}
       - name: Checkout code
         uses: actions/checkout@v2
+      - name: Formatting checks
+        run: if [ ! -z $(gofmt -l .) ]; then echo 'Make sure to run "gofmt -s -w ." before commit!' && exit 1; fi
       - name: Init Database
         run: psql -f hack/init_postgres.sql postgresql://postgres:root@localhost:5432/postgres
       - name: Run migrations
diff --git a/api/hook_test.go b/api/hook_test.go
index 26a6e7ce..fb6a3593 100644
--- a/api/hook_test.go
+++ b/api/hook_test.go
@@ -99,7 +99,7 @@ func TestSignupHookFromClaims(t *testing.T) {
 
 	ctx := context.Background()
 	ctx = withFunctionHooks(ctx, map[string][]string{
-		"signup": []string{svr.URL},
+		"signup": {svr.URL},
 	})
 
 	require.NoError(t, triggerEventHooks(ctx, conn, SignupEvent, user, iid, config))
diff --git a/models/user_test.go b/models/user_test.go
index 28771df4..c15b40f7 100644
--- a/models/user_test.go
+++ b/models/user_test.go
@@ -113,7 +113,7 @@ func (ts *UserTestSuite) TestFindUsersInAudience() {
 
 	sp := &SortParams{
 		Fields: []SortField{
-			SortField{Name: "created_at", Dir: Descending},
+			{Name: "created_at", Dir: Descending},
 		},
 	}
 	n, err = FindUsersInAudience(ts.db, u.InstanceID, u.Aud, nil, sp, "")