Skip to content

Commit cb206ae

Browse files
authored
fix same custom sections (#77)
Signed-off-by: Loong Dai <[email protected]>
1 parent c0bd0a2 commit cb206ae

7 files changed

+55
-3
lines changed

pkg/gci/gci.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,13 @@ func LoadFormatGoFile(file io.FileObj, cfg config.Config) (src, dist []byte, err
174174
}
175175

176176
if len(customKeys) > 0 {
177-
sort.Sort(sort.Reverse(sort.StringSlice(customKeys)))
178-
for _, k := range customKeys {
177+
sort.Sort(sort.StringSlice(customKeys))
178+
for i, k := range customKeys {
179179
for _, d := range result[k] {
180180
AddIndent(&body, &firstWithIndex)
181181
body = append(body, src[d.Start:d.End]...)
182182
}
183-
if body[len(body)-1] != utils.Linebreak {
183+
if i+1 < len(customKeys) {
184184
body = append(body, utils.Linebreak)
185185
}
186186
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
sections:
2+
- Standard
3+
- Default
4+
- Prefix(github.com/daixiang0)
5+
- Prefix(github.com/daixiang0/gci)
6+
- Prefix(github.com/daixiang0/gci/subtest)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package main
2+
import (
3+
"fmt"
4+
5+
g "github.com/golang"
6+
7+
"github.com/daixiang0/a"
8+
"github.com/daixiang0/gci"
9+
"github.com/daixiang0/gci/subtest"
10+
)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package main
2+
import (
3+
"fmt"
4+
5+
g "github.com/golang"
6+
7+
"github.com/daixiang0/a"
8+
9+
"github.com/daixiang0/gci"
10+
11+
"github.com/daixiang0/gci/subtest"
12+
)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
sections:
2+
- Standard
3+
- Default
4+
- Prefix(github.com/daixiang0/gci)
5+
- Prefix(github.com/daixiang0/gci/subtest)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package main
2+
import (
3+
"fmt"
4+
5+
g "github.com/golang"
6+
7+
"github.com/daixiang0/gci"
8+
"github.com/daixiang0/gci/subtest"
9+
)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package main
2+
import (
3+
"fmt"
4+
5+
g "github.com/golang"
6+
7+
"github.com/daixiang0/gci"
8+
9+
"github.com/daixiang0/gci/subtest"
10+
)

0 commit comments

Comments
 (0)