Skip to content

Commit

Permalink
Fix comment issue (#136)
Browse files Browse the repository at this point in the history
* README: update isolated comment blocks

Signed-off-by: Loong <[email protected]>

* fix the top comment

Signed-off-by: Loong <[email protected]>

---------

Signed-off-by: Loong <[email protected]>
  • Loading branch information
daixiang0 authored Feb 7, 2023
1 parent 33a14c3 commit 7f0d0bc
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 1 deletion.
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,20 @@ GCI considers a import block based on AST as below:
Doc
Name Path Comment
```
All comments will keep as they were, except the independent comment blocks(line breaks before and after).
All comments will keep as they were, except the isolated comment blocks.

The isolated comment blocks like below:
```
import (
"fmt"
// this line is isolated comment
// those lines belong to one
// isolated comment blocks
"github.com/daixiang0/gci"
)
```

GCI splits all import blocks into different sections, now support five section type:
- standard: Golang official imports, like "fmt"
Expand Down
1 change: 1 addition & 0 deletions pkg/gci/gci.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ func LoadFormatGoFile(file io.FileObj, cfg config.Config) (src, dist []byte, err

// add beginning of import block
head = append(head, `import (`...)
head = append(head, utils.Linebreak)
// add end of import block
body = append(body, []byte{utils.RightParenthesis, utils.Linebreak}...)

Expand Down
1 change: 1 addition & 0 deletions pkg/gci/internal/testdata/comment-top.cfg.yaml
7 changes: 7 additions & 0 deletions pkg/gci/internal/testdata/comment-top.in.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

import (
"os" // https://pkg.go.dev/os
// https://pkg.go.dev/fmt
"fmt"
)
7 changes: 7 additions & 0 deletions pkg/gci/internal/testdata/comment-top.out.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

import (
// https://pkg.go.dev/fmt
"fmt"
"os" // https://pkg.go.dev/os
)

0 comments on commit 7f0d0bc

Please sign in to comment.