Skip to content

Commit db7f62b

Browse files
authored
fix: formats consistently the code with gci (#5893)
1 parent 223ff51 commit db7f62b

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

pkg/goformatters/gci/gci.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package gci
22

33
import (
44
"context"
5+
"go/format"
56

67
gcicfg "github.com/daixiang0/gci/pkg/config"
78
"github.com/daixiang0/gci/pkg/gci"
@@ -60,5 +61,14 @@ func (*Formatter) Name() string {
6061

6162
func (f *Formatter) Format(filename string, src []byte) ([]byte, error) {
6263
_, formatted, err := gci.LoadFormat(src, filename, *f.config)
63-
return formatted, err
64+
if err != nil {
65+
return nil, err
66+
}
67+
68+
// gci format the code only when the imports are modified,
69+
// this produced inconsistencies.
70+
// To be always consistent, the code should always be formatted.
71+
// https://github.com/daixiang0/gci/blob/c4f689991095c0e54843dca76fb9c3bad58ec5c7/pkg/gci/gci.go#L148-L151
72+
// https://github.com/daixiang0/gci/blob/c4f689991095c0e54843dca76fb9c3bad58ec5c7/pkg/gci/gci.go#L215
73+
return format.Source(formatted)
6474
}

0 commit comments

Comments
 (0)