Skip to content

Commit

Permalink
fix one import case (#78)
Browse files Browse the repository at this point in the history
Signed-off-by: Loong Dai <loong.dai@intel.com>
  • Loading branch information
daixiang0 committed Jul 15, 2022
1 parent cb206ae commit 6f5cb16
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/gci/gci.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ func LoadFormatGoFile(file io.FileObj, cfg config.Config) (src, dist []byte, err
return nil, nil, err
}

// do not do format if only one import
if len(imports) == 1 {
return src, src, nil
}

result, err := format.Format(imports, &cfg)
if err != nil {
return nil, nil, err
Expand Down
1 change: 1 addition & 0 deletions pkg/gci/internal/testdata/one-import-one-line.cfg.yaml
6 changes: 6 additions & 0 deletions pkg/gci/internal/testdata/one-import-one-line.in.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package main

import "fmt"

func main() {
}
6 changes: 6 additions & 0 deletions pkg/gci/internal/testdata/one-import-one-line.out.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package main

import "fmt"

func main() {
}
1 change: 1 addition & 0 deletions pkg/gci/internal/testdata/one-import.cfg.yaml
7 changes: 7 additions & 0 deletions pkg/gci/internal/testdata/one-import.in.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main
import (
"fmt"
)

func main() {
}
7 changes: 7 additions & 0 deletions pkg/gci/internal/testdata/one-import.out.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main
import (
"fmt"
)

func main() {
}

0 comments on commit 6f5cb16

Please sign in to comment.