You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Support grouping dot and blank imports at the end (#88)
* feat: Support grouping dot and blank imports at the end
Signed-off-by: Marco Nenciarini <[email protected]>
* doc: Document blank and dot groups
Signed-off-by: Marco Nenciarini <[email protected]>
Copy file name to clipboardExpand all lines: README.md
+53-9
Original file line number
Diff line number
Diff line change
@@ -11,12 +11,15 @@ Name Path Comment
11
11
```
12
12
All comments will keep as they were, except the independent comment blocks(line breaks before and after).
13
13
14
-
GCI splits all import blocks into different sections, now support three section type:
14
+
GCI splits all import blocks into different sections, now support five section type:
15
15
- standard: Golang official imports, like "fmt"
16
-
- custom: Custom section, use full and the longest match(match full string first, if multiple matches, use the longest one)
16
+
- custom: Custom section, use full and the longest match(match full string first, if multiple matches, use the longest one)
17
17
- default: All rest import blocks
18
+
- blank: Put blank imports together in a separate group
19
+
- dot: Put dot imports together in a separate group
18
20
19
-
The priority is standard > default > custom, all sections sort alphabetically inside.
21
+
The priority is standard > default > custom > blank > dot, all sections sort alphabetically inside.
22
+
By default, blank and dot sections are not used and the corresponding lines end up in the other groups.
20
23
21
24
All import blocks use one TAB(`\t`) as Indent.
22
25
@@ -50,11 +53,13 @@ Aliases:
50
53
Flags:
51
54
-d, --debug Enables debug output from the formatter
52
55
-h, --help helpfor write
53
-
-s, --section strings Sections define how inputs will be processed. Section names are case-insensitive and may contain parameters in (). The section order is standard > default > custom. The default value is [standard,default].
56
+
-s, --section strings Sections define how inputs will be processed. Section names are case-insensitive and may contain parameters in (). The section order is standard > default > custom> blank > dot. The default value is [standard,default].
54
57
standard - standard section that Golang provides officially, like "fmt"
55
58
Prefix(github.com/daixiang0) - custom section, groups all imports with the specified Prefix. Imports will be matched to the longest Prefix.
56
-
default - default section, contains all rest imports (default [standard,default])
59
+
default - default section, contains all rest imports
60
+
blank - blank section, contains all blank imports. This section is not presed unless explicitly enabled. (default [standard,default])
57
61
--skip-generated Skip generated files
62
+
58
63
```
59
64
60
65
```shell
@@ -70,11 +75,14 @@ Aliases:
70
75
Flags:
71
76
-d, --debug Enables debug output from the formatter
72
77
-h, --help helpfor write
73
-
-s, --section strings Sections define how inputs will be processed. Section names are case-insensitive and may contain parameters in (). The section order is standard > default > custom. The default value is [standard,default].
78
+
-s, --section strings Sections define how inputs will be processed. Section names are case-insensitive and may contain parameters in (). The section order is standard > default > custom> blank > dot. The default value is [standard,default].
74
79
standard - standard section thatolang provides officially, like "fmt"
75
80
Prefix(github.com/daixiang0) - custom section, groups all imports with the specified Prefix. Imports will be matched to the longest Prefix.
76
-
default - default section, contains all rest imports (default [standard,default])
81
+
default - default section, contains all rest imports
82
+
blank - blank section, contains all blank imports. This section is not presed unless explicitly enabled.
83
+
dot - dot section, contains all dot imports. This section is not presed unless explicitly enabled. (default [standard,default])
77
84
--skip-generated Skip generated files
85
+
78
86
```
79
87
80
88
```shell
@@ -87,10 +95,12 @@ Usage:
87
95
Flags:
88
96
-d, --debug Enables debug output from the formatter
89
97
-h, --help helpfor write
90
-
-s, --section strings Sections define how inputs will be processed. Section names are case-insensitive and may contain parameters in (). The section order is standard > default > custom. The default value is [standard,default].
98
+
-s, --section strings Sections define how inputs will be processed. Section names are case-insensitive and may contain parameters in (). The section order is standard > default > custom> blank > dot. The default value is [standard,default].
91
99
standard - standard section thatolang provides officially, like "fmt"
92
100
Prefix(github.com/daixiang0) - custom section, groups all imports with the specified Prefix. Imports will be matched to the longest Prefix.
93
-
default - default section, contains all rest imports (default [standard,default])
101
+
default - default section, contains all rest imports
102
+
blank - blank section, contains all blank imports. This section is not presed unless explicitly enabled.
103
+
dot - dot section, contains all dot imports. This section is not presed unless explicitly enabled. (default [standard,default])
94
104
--skip-generated Skip generated files
95
105
96
106
```
@@ -168,6 +178,40 @@ import (
168
178
)
169
179
```
170
180
181
+
### with blank and dot grouping enabled
182
+
183
+
```go
184
+
package main
185
+
import (
186
+
"fmt"
187
+
go"github.com/golang"
188
+
_ "github.com/golang/blank"
189
+
. "github.com/golang/dot"
190
+
"github.com/daixiang0/gci"
191
+
_ "github.com/daixiang0/gci/blank"
192
+
. "github.com/daixiang0/gci/dot"
193
+
)
194
+
```
195
+
196
+
to
197
+
198
+
```go
199
+
package main
200
+
import (
201
+
"fmt"
202
+
203
+
go"github.com/golang"
204
+
205
+
"github.com/daixiang0/gci"
206
+
207
+
_ "github.com/daixiang0/gci/blank"
208
+
_ "github.com/golang/blank"
209
+
210
+
. "github.com/daixiang0/gci/dot"
211
+
. "github.com/golang/dot"
212
+
)
213
+
```
214
+
171
215
## TODO
172
216
173
217
- Ensure only one blank between `Name` and `Path` in an import block
Copy file name to clipboardExpand all lines: cmd/gci/gcicommand.go
+4-2
Original file line number
Diff line number
Diff line change
@@ -46,10 +46,12 @@ func (e *Executor) newGciCommand(use, short, long string, aliases []string, stdI
46
46
47
47
debug=cmd.Flags().BoolP("debug", "d", false, "Enables debug output from the formatter")
48
48
49
-
sectionHelp:=`Sections define how inputs will be processed. Section names are case-insensitive and may contain parameters in (). The section order is standard > default > custom. The default value is [standard,default].
49
+
sectionHelp:=`Sections define how inputs will be processed. Section names are case-insensitive and may contain parameters in (). The section order is standard > default > custom > blank > dot. The default value is [standard,default].
50
50
standard - standard section that Golang provides officially, like "fmt"
51
51
Prefix(github.com/daixiang0) - custom section, groups all imports with the specified Prefix. Imports will be matched to the longest Prefix.
52
-
default - default section, contains all rest imports`
52
+
default - default section, contains all rest imports
53
+
blank - blank section, contains all blank imports. This section is not presed unless explicitly enabled.
54
+
dot - dot section, contains all dot imports. This section is not presed unless explicitly enabled.`
0 commit comments