11package gci
22
33import (
4+ "fmt"
5+
46 gcicfg "github.com/daixiang0/gci/pkg/config"
57 "github.com/daixiang0/gci/pkg/gci"
8+ "github.com/daixiang0/gci/pkg/log"
69 "github.com/ldez/grignotin/gomod"
710
811 "github.com/golangci/golangci-lint/pkg/config"
12+ "github.com/golangci/golangci-lint/pkg/goformatters/internal"
913)
1014
1115const Name = "gci"
@@ -14,23 +18,36 @@ type Formatter struct {
1418 config * gcicfg.Config
1519}
1620
17- func New (cfg config.GciSettings ) (* Formatter , error ) {
21+ func New (settings * config.GciSettings ) (* Formatter , error ) {
22+ log .InitLogger ()
23+ _ = log .L ().Sync ()
24+
1825 modPath , err := gomod .GetModulePath ()
1926 if err != nil {
20- return nil , err
27+ internal . FormatterLogger . Errorf ( "gci: %v" , err )
2128 }
2229
23- parsedCfg , err := gcicfg.YamlConfig {
30+ cfg := gcicfg.YamlConfig {
2431 Cfg : gcicfg.BoolConfig {
25- NoInlineComments : cfg .NoInlineComments ,
26- NoPrefixComments : cfg .NoPrefixComments ,
27- SkipGenerated : cfg .SkipGenerated ,
28- CustomOrder : cfg .CustomOrder ,
29- NoLexOrder : cfg .NoLexOrder ,
32+ NoInlineComments : settings .NoInlineComments ,
33+ NoPrefixComments : settings .NoPrefixComments ,
34+ SkipGenerated : settings .SkipGenerated ,
35+ CustomOrder : settings .CustomOrder ,
36+ NoLexOrder : settings .NoLexOrder ,
3037 },
31- SectionStrings : cfg .Sections ,
38+ SectionStrings : settings .Sections ,
3239 ModPath : modPath ,
33- }.Parse ()
40+ }
41+
42+ if settings .LocalPrefixes != "" {
43+ cfg .SectionStrings = []string {
44+ "standard" ,
45+ "default" ,
46+ fmt .Sprintf ("prefix(%s)" , settings .LocalPrefixes ),
47+ }
48+ }
49+
50+ parsedCfg , err := cfg .Parse ()
3451 if err != nil {
3552 return nil , err
3653 }
0 commit comments