Skip to content

Commit 41996e4

Browse files
authored
experiment: add gci to golangci-linters to order/group imports (#247)
Instructions to bring existing repos to this standard: 1. Install gci: `go install github.com/daixiang0/gci@v0.11.2` 2. Run in the repo root `gci write -s standard -s default -s "prefix(github.com/abcxyz)" -s blank -s dot --custom-order --skip-generated .`
1 parent 02cb2ca commit 41996e4

File tree

17 files changed

+43
-19
lines changed

17 files changed

+43
-19
lines changed

.golangci.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ linters:
5252
- 'exhaustive'
5353
- 'exportloopref'
5454
- 'forcetypeassert'
55+
- 'gci'
5556
- 'gocheckcompilerdirectives'
5657
- 'godot'
5758
- 'gofmt'
@@ -126,6 +127,17 @@ linters-settings:
126127
- pkg: 'github.com/stretchr/testify'
127128
desc: 'use the standard library for tests'
128129

130+
gci:
131+
sections:
132+
- 'standard'
133+
- 'default'
134+
- 'prefix(github.com/abcxyz)'
135+
- 'blank'
136+
- 'dot'
137+
138+
skip-generated: true
139+
custom-order: true
140+
129141
gofumpt:
130142
# default: false
131143
extra-rules: true

bqutil/query.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ import (
2121
"fmt"
2222

2323
"cloud.google.com/go/bigquery"
24-
"github.com/abcxyz/pkg/logging"
2524
"github.com/sethvargo/go-retry"
2625
"google.golang.org/api/iterator"
26+
27+
"github.com/abcxyz/pkg/logging"
2728
)
2829

2930
// Query is the interface to execute a query.

bqutil/query_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ import (
2020
"testing"
2121
"time"
2222

23-
"github.com/abcxyz/pkg/logging"
24-
"github.com/abcxyz/pkg/testutil"
2523
"github.com/google/go-cmp/cmp"
2624
"github.com/sethvargo/go-retry"
25+
26+
"github.com/abcxyz/pkg/logging"
27+
"github.com/abcxyz/pkg/testutil"
2728
)
2829

2930
type fakeQuery[T any] struct {

cfgloader/cfgloader_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ import (
1919
"fmt"
2020
"testing"
2121

22-
"github.com/abcxyz/pkg/testutil"
2322
"github.com/google/go-cmp/cmp"
2423
"github.com/sethvargo/go-envconfig"
24+
25+
"github.com/abcxyz/pkg/testutil"
2526
)
2627

2728
type fakeCfg struct {

cli/command_doc_completions_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ import (
1919
"strconv"
2020
"time"
2121

22-
"github.com/abcxyz/pkg/cli"
2322
"github.com/posener/complete/v2"
2423
"github.com/posener/complete/v2/predict"
24+
25+
"github.com/abcxyz/pkg/cli"
2526
)
2627

2728
type SingCommand struct {

cli/flags.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ import (
2727
"strings"
2828
"time"
2929

30-
"github.com/abcxyz/pkg/logging"
31-
"github.com/abcxyz/pkg/timeutil"
32-
3330
"github.com/kr/text"
3431
"github.com/posener/complete/v2"
3532
"github.com/posener/complete/v2/predict"
33+
34+
"github.com/abcxyz/pkg/logging"
35+
"github.com/abcxyz/pkg/timeutil"
3636
)
3737

3838
const maxLineLength = 80

cli/flags_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ import (
2424
"strings"
2525
"testing"
2626

27+
"github.com/google/go-cmp/cmp"
28+
2729
"github.com/abcxyz/pkg/logging"
2830
"github.com/abcxyz/pkg/testutil"
29-
"github.com/google/go-cmp/cmp"
3031
)
3132

3233
func TestNewFlagSet(t *testing.T) {

gcputil/gcputil.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"os"
2121

2222
"cloud.google.com/go/compute/metadata"
23+
2324
"github.com/abcxyz/pkg/logging"
2425
)
2526

githubapp/githubapp.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ import (
2626
"net/http"
2727
"time"
2828

29-
"github.com/abcxyz/pkg/cache"
3029
"github.com/lestrrat-go/jwx/v2/jwa"
3130
"github.com/lestrrat-go/jwx/v2/jwt"
3231
"golang.org/x/oauth2"
32+
33+
"github.com/abcxyz/pkg/cache"
3334
)
3435

3536
// URL used to retrieve access tokens. The pattern must contain a single '%s' which represents where in the url

githubapp/githubapp_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ import (
2525
"testing"
2626
"time"
2727

28-
"github.com/abcxyz/pkg/testutil"
2928
"github.com/google/go-cmp/cmp"
29+
30+
"github.com/abcxyz/pkg/testutil"
3031
)
3132

3233
func TestConfig_NewConfig(t *testing.T) {

0 commit comments

Comments
 (0)