Skip to content

Commit 5fd2f78

Browse files
committed
add gci and usetesting linters
1 parent 128407a commit 5fd2f78

33 files changed

+126
-93
lines changed

.golangci.yaml

+12
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@ linters:
44
enable:
55
- "bidichk"
66
- "bodyclose"
7+
- "errcheck"
78
- "errname"
89
- "errorlint"
910
- "goprintffuncname"
1011
- "gosec"
12+
- "govet"
1113
- "importas"
14+
- "ineffassign"
1215
- "makezero"
1316
- "prealloc"
1417
- "predeclared"
@@ -17,6 +20,8 @@ linters:
1720
- "rowserrcheck"
1821
- "staticcheck"
1922
- "unconvert"
23+
- "unused"
24+
- "usetesting"
2025
- "wastedassign"
2126
- "whitespace"
2227
exclusions:
@@ -32,9 +37,16 @@ linters:
3237
- "examples$"
3338
formatters:
3439
enable:
40+
- "gci"
3541
- "gofumpt"
3642
- "goimports"
3743
settings:
44+
gci:
45+
sections:
46+
- "standard"
47+
- "default"
48+
- "prefix(github.com/authzed)"
49+
- "localmodule"
3850
goimports:
3951
local-prefixes:
4052
- "github.com/authzed/zed"

internal/client/client.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@ import (
99
"path/filepath"
1010
"strings"
1111

12-
"golang.org/x/net/proxy"
13-
14-
v1 "github.com/authzed/authzed-go/proto/authzed/api/v1"
15-
"github.com/authzed/authzed-go/v1"
16-
"github.com/authzed/grpcutil"
1712
"github.com/jzelinskie/cobrautil/v2"
1813
"github.com/mitchellh/go-homedir"
1914
"github.com/rs/zerolog/log"
2015
"github.com/spf13/cobra"
16+
"golang.org/x/net/proxy"
2117
"google.golang.org/grpc"
2218
"google.golang.org/grpc/credentials/insecure"
2319

20+
v1 "github.com/authzed/authzed-go/proto/authzed/api/v1"
21+
"github.com/authzed/authzed-go/v1"
22+
"github.com/authzed/grpcutil"
23+
2424
zgrpcutil "github.com/authzed/zed/internal/grpcutil"
2525
"github.com/authzed/zed/internal/storage"
2626
)

internal/client/client_test.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ import (
55
"path"
66
"testing"
77

8+
"github.com/stretchr/testify/require"
9+
810
"github.com/authzed/zed/internal/client"
911
"github.com/authzed/zed/internal/storage"
1012
zedtesting "github.com/authzed/zed/internal/testing"
11-
12-
"github.com/stretchr/testify/require"
1313
)
1414

1515
func TestGetTokenWithCLIOverride(t *testing.T) {
1616
require := require.New(t)
17-
testCert, err := os.CreateTemp("", "")
17+
testCert, err := os.CreateTemp(t.TempDir(), "")
1818
require.NoError(err)
1919
_, err = testCert.Write([]byte("hi"))
2020
require.NoError(err)
@@ -100,10 +100,9 @@ func TestGetCurrentTokenWithCLIOverrideWithoutSecretFile(t *testing.T) {
100100

101101
bTrue := true
102102

103-
tmpDir, err := os.MkdirTemp("", "")
104-
require.NoError(err)
103+
tmpDir := t.TempDir()
105104
configPath := path.Join(tmpDir, "config.json")
106-
err = os.WriteFile(configPath, []byte("{}"), 0o600)
105+
err := os.WriteFile(configPath, []byte("{}"), 0o600)
107106
require.NoError(err)
108107

109108
configStore := &storage.JSONConfigStore{ConfigPath: tmpDir}

internal/cmd/backup.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ import (
1111
"strings"
1212
"time"
1313

14-
v1 "github.com/authzed/authzed-go/proto/authzed/api/v1"
15-
"github.com/authzed/spicedb/pkg/schemadsl/compiler"
16-
"github.com/authzed/spicedb/pkg/schemadsl/generator"
17-
"github.com/authzed/spicedb/pkg/tuple"
18-
"github.com/authzed/spicedb/pkg/typesystem"
1914
"github.com/jzelinskie/cobrautil/v2"
2015
"github.com/mattn/go-isatty"
2116
"github.com/rodaine/table"
@@ -26,6 +21,12 @@ import (
2621
"google.golang.org/grpc/codes"
2722
"google.golang.org/grpc/status"
2823

24+
v1 "github.com/authzed/authzed-go/proto/authzed/api/v1"
25+
"github.com/authzed/spicedb/pkg/schemadsl/compiler"
26+
"github.com/authzed/spicedb/pkg/schemadsl/generator"
27+
"github.com/authzed/spicedb/pkg/tuple"
28+
"github.com/authzed/spicedb/pkg/typesystem"
29+
2930
"github.com/authzed/zed/internal/client"
3031
"github.com/authzed/zed/internal/commands"
3132
"github.com/authzed/zed/internal/console"

internal/cmd/backup_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ import (
88
"strings"
99
"testing"
1010

11+
"github.com/google/uuid"
12+
"github.com/rs/zerolog"
13+
"github.com/stretchr/testify/require"
1114
"google.golang.org/grpc/codes"
1215
"google.golang.org/grpc/status"
1316

1417
v1 "github.com/authzed/authzed-go/proto/authzed/api/v1"
1518
"github.com/authzed/spicedb/pkg/tuple"
16-
"github.com/google/uuid"
17-
"github.com/rs/zerolog"
18-
"github.com/stretchr/testify/require"
1919

2020
"github.com/authzed/zed/internal/client"
2121
zedtesting "github.com/authzed/zed/internal/testing"
@@ -168,7 +168,7 @@ func TestBackupParseRelsCmdFunc(t *testing.T) {
168168

169169
cmd := zedtesting.CreateTestCobraCommandWithFlagValue(t, zedtesting.StringFlag{FlagName: "prefix-filter", FlagValue: tt.filter})
170170
backupName := createTestBackup(t, tt.schema, tt.relationships)
171-
f, err := os.CreateTemp("", "parse-output")
171+
f, err := os.CreateTemp(t.TempDir(), "parse-output")
172172
require.NoError(t, err)
173173
defer func() {
174174
_ = f.Close()
@@ -189,7 +189,7 @@ func TestBackupParseRelsCmdFunc(t *testing.T) {
189189
func TestBackupParseRevisionCmdFunc(t *testing.T) {
190190
cmd := zedtesting.CreateTestCobraCommandWithFlagValue(t, zedtesting.StringFlag{FlagName: "prefix-filter", FlagValue: "test"})
191191
backupName := createTestBackup(t, testSchema, testRelationships)
192-
f, err := os.CreateTemp("", "parse-output")
192+
f, err := os.CreateTemp(t.TempDir(), "parse-output")
193193
require.NoError(t, err)
194194
defer func() {
195195
_ = f.Close()
@@ -249,7 +249,7 @@ func TestBackupParseSchemaCmdFunc(t *testing.T) {
249249
zedtesting.StringFlag{FlagName: "prefix-filter", FlagValue: tt.filter},
250250
zedtesting.BoolFlag{FlagName: "rewrite-legacy", FlagValue: tt.rewriteLegacy})
251251
backupName := createTestBackup(t, tt.schema, nil)
252-
f, err := os.CreateTemp("", "parse-output")
252+
f, err := os.CreateTemp(t.TempDir(), "parse-output")
253253
require.NoError(t, err)
254254
defer func() {
255255
_ = f.Close()

internal/cmd/helpers_test.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ import (
55
"os"
66
"testing"
77

8-
v1 "github.com/authzed/authzed-go/proto/authzed/api/v1"
9-
"github.com/authzed/spicedb/pkg/tuple"
108
"github.com/samber/lo"
119
"github.com/stretchr/testify/require"
1210

11+
v1 "github.com/authzed/authzed-go/proto/authzed/api/v1"
12+
"github.com/authzed/spicedb/pkg/tuple"
13+
1314
"github.com/authzed/zed/pkg/backupformat"
1415
)
1516

@@ -42,7 +43,7 @@ func readLines(t *testing.T, fileName string) []string {
4243
func createTestBackup(t *testing.T, schema string, relationships []string) string {
4344
t.Helper()
4445

45-
f, err := os.CreateTemp("", "test-backup")
46+
f, err := os.CreateTemp(t.TempDir(), "test-backup")
4647
require.NoError(t, err)
4748
defer f.Close()
4849
t.Cleanup(func() {

internal/cmd/import.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ import (
77
"net/url"
88
"strings"
99

10-
v1 "github.com/authzed/authzed-go/proto/authzed/api/v1"
11-
"github.com/authzed/spicedb/pkg/tuple"
12-
"github.com/authzed/spicedb/pkg/validationfile"
1310
"github.com/jzelinskie/cobrautil/v2"
1411
"github.com/rs/zerolog/log"
1512
"github.com/spf13/cobra"
1613

14+
v1 "github.com/authzed/authzed-go/proto/authzed/api/v1"
15+
"github.com/authzed/spicedb/pkg/tuple"
16+
"github.com/authzed/spicedb/pkg/validationfile"
17+
1718
"github.com/authzed/zed/internal/client"
1819
"github.com/authzed/zed/internal/decode"
1920
"github.com/authzed/zed/internal/grpcutil"

internal/cmd/import_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import (
55
"path/filepath"
66
"testing"
77

8-
v1 "github.com/authzed/authzed-go/proto/authzed/api/v1"
98
"github.com/stretchr/testify/require"
109

10+
v1 "github.com/authzed/authzed-go/proto/authzed/api/v1"
11+
1112
"github.com/authzed/zed/internal/client"
1213
zedtesting "github.com/authzed/zed/internal/testing"
1314
)

internal/cmd/preview.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@ import (
66
"os"
77
"path/filepath"
88

9-
newcompiler "github.com/authzed/spicedb/pkg/composableschemadsl/compiler"
10-
newinput "github.com/authzed/spicedb/pkg/composableschemadsl/input"
11-
"github.com/authzed/spicedb/pkg/schemadsl/compiler"
12-
"github.com/authzed/spicedb/pkg/schemadsl/generator"
139
"github.com/ccoveille/go-safecast"
1410
"github.com/jzelinskie/cobrautil/v2"
1511
"github.com/rs/zerolog/log"
1612
"github.com/spf13/cobra"
1713
"golang.org/x/term"
1814

15+
newcompiler "github.com/authzed/spicedb/pkg/composableschemadsl/compiler"
16+
newinput "github.com/authzed/spicedb/pkg/composableschemadsl/input"
17+
"github.com/authzed/spicedb/pkg/schemadsl/compiler"
18+
"github.com/authzed/spicedb/pkg/schemadsl/generator"
19+
1920
"github.com/authzed/zed/internal/commands"
2021
)
2122

internal/cmd/restorer.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import (
88
"strings"
99
"time"
1010

11-
v1 "github.com/authzed/authzed-go/proto/authzed/api/v1"
12-
"github.com/authzed/spicedb/pkg/spiceerrors"
1311
"github.com/ccoveille/go-safecast"
1412
"github.com/cenkalti/backoff/v4"
1513
"github.com/mattn/go-isatty"
@@ -19,6 +17,9 @@ import (
1917
"google.golang.org/grpc/codes"
2018
"google.golang.org/grpc/status"
2119

20+
v1 "github.com/authzed/authzed-go/proto/authzed/api/v1"
21+
"github.com/authzed/spicedb/pkg/spiceerrors"
22+
2223
"github.com/authzed/zed/internal/client"
2324
"github.com/authzed/zed/internal/console"
2425
"github.com/authzed/zed/pkg/backupformat"

internal/cmd/restorer_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@ import (
66
"testing"
77
"time"
88

9-
v1 "github.com/authzed/authzed-go/proto/authzed/api/v1"
10-
"github.com/authzed/spicedb/pkg/tuple"
119
"github.com/ccoveille/go-safecast"
1210
"github.com/stretchr/testify/require"
1311
"google.golang.org/grpc"
1412
"google.golang.org/grpc/codes"
1513
"google.golang.org/grpc/status"
1614
"google.golang.org/protobuf/proto"
1715

16+
v1 "github.com/authzed/authzed-go/proto/authzed/api/v1"
17+
"github.com/authzed/spicedb/pkg/tuple"
18+
1819
"github.com/authzed/zed/internal/client"
1920
)
2021

internal/cmd/schema.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,19 @@ import (
88
"os"
99
"strings"
1010

11-
v1 "github.com/authzed/authzed-go/proto/authzed/api/v1"
12-
"github.com/authzed/spicedb/pkg/diff"
13-
"github.com/authzed/spicedb/pkg/schemadsl/compiler"
14-
"github.com/authzed/spicedb/pkg/schemadsl/generator"
15-
"github.com/authzed/spicedb/pkg/schemadsl/input"
1611
"github.com/ccoveille/go-safecast"
1712
"github.com/jzelinskie/cobrautil/v2"
1813
"github.com/jzelinskie/stringz"
1914
"github.com/rs/zerolog/log"
2015
"github.com/spf13/cobra"
2116
"golang.org/x/term"
2217

18+
v1 "github.com/authzed/authzed-go/proto/authzed/api/v1"
19+
"github.com/authzed/spicedb/pkg/diff"
20+
"github.com/authzed/spicedb/pkg/schemadsl/compiler"
21+
"github.com/authzed/spicedb/pkg/schemadsl/generator"
22+
"github.com/authzed/spicedb/pkg/schemadsl/input"
23+
2324
"github.com/authzed/zed/internal/client"
2425
"github.com/authzed/zed/internal/commands"
2526
"github.com/authzed/zed/internal/console"

internal/cmd/validate.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ import (
88
"strings"
99

1010
"github.com/ccoveille/go-safecast"
11+
"github.com/charmbracelet/lipgloss"
12+
"github.com/jzelinskie/cobrautil/v2"
13+
"github.com/muesli/termenv"
1114
"github.com/spf13/cobra"
1215

1316
"github.com/authzed/spicedb/pkg/development"
1417
core "github.com/authzed/spicedb/pkg/proto/core/v1"
1518
devinterface "github.com/authzed/spicedb/pkg/proto/developer/v1"
1619
"github.com/authzed/spicedb/pkg/spiceerrors"
1720
"github.com/authzed/spicedb/pkg/validationfile"
18-
"github.com/charmbracelet/lipgloss"
19-
"github.com/jzelinskie/cobrautil/v2"
20-
"github.com/muesli/termenv"
2121

2222
"github.com/authzed/zed/internal/commands"
2323
"github.com/authzed/zed/internal/console"

internal/cmd/version.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@ import (
44
"fmt"
55
"os"
66

7-
"github.com/authzed/authzed-go/pkg/responsemeta"
8-
v1 "github.com/authzed/authzed-go/proto/authzed/api/v1"
97
"github.com/gookit/color"
108
"github.com/jzelinskie/cobrautil/v2"
119
"github.com/mattn/go-isatty"
1210
"github.com/spf13/cobra"
1311
"google.golang.org/grpc"
1412
"google.golang.org/grpc/metadata"
1513

14+
"github.com/authzed/authzed-go/pkg/responsemeta"
15+
v1 "github.com/authzed/authzed-go/proto/authzed/api/v1"
16+
1617
"github.com/authzed/zed/internal/client"
1718
"github.com/authzed/zed/internal/console"
1819
)

internal/commands/completion.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import (
44
"errors"
55
"strings"
66

7+
"github.com/spf13/cobra"
8+
79
v1 "github.com/authzed/authzed-go/proto/authzed/api/v1"
810
"github.com/authzed/spicedb/pkg/schemadsl/compiler"
9-
"github.com/spf13/cobra"
1011

1112
"github.com/authzed/zed/internal/client"
1213
)

internal/commands/permission.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@ import (
77
"os"
88
"strings"
99

10-
"github.com/authzed/spicedb/pkg/tuple"
11-
12-
"github.com/authzed/authzed-go/pkg/requestmeta"
13-
"github.com/authzed/authzed-go/pkg/responsemeta"
14-
v1 "github.com/authzed/authzed-go/proto/authzed/api/v1"
1510
"github.com/jzelinskie/cobrautil/v2"
1611
"github.com/jzelinskie/stringz"
1712
"github.com/rs/zerolog/log"
@@ -22,6 +17,11 @@ import (
2217
"google.golang.org/protobuf/encoding/protojson"
2318
"google.golang.org/protobuf/encoding/prototext"
2419

20+
"github.com/authzed/authzed-go/pkg/requestmeta"
21+
"github.com/authzed/authzed-go/pkg/responsemeta"
22+
v1 "github.com/authzed/authzed-go/proto/authzed/api/v1"
23+
"github.com/authzed/spicedb/pkg/tuple"
24+
2525
"github.com/authzed/zed/internal/client"
2626
"github.com/authzed/zed/internal/console"
2727
"github.com/authzed/zed/internal/printers"

0 commit comments

Comments
 (0)