forked from golangci/golangci-lint
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgci.go
48 lines (39 loc) · 1.01 KB
/
gci.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package gci
import (
gcicfg "github.com/daixiang0/gci/pkg/config"
"github.com/daixiang0/gci/pkg/gci"
"github.com/ldez/grignotin/gomod"
"github.com/golangci/golangci-lint/pkg/config"
)
const Name = "gci"
type Formatter struct {
config *gcicfg.Config
}
func New(cfg config.GciSettings) (*Formatter, error) {
modPath, err := gomod.GetModulePath()
if err != nil {
return nil, err
}
parsedCfg, err := gcicfg.YamlConfig{
Cfg: gcicfg.BoolConfig{
NoInlineComments: cfg.NoInlineComments,
NoPrefixComments: cfg.NoPrefixComments,
SkipGenerated: cfg.SkipGenerated,
CustomOrder: cfg.CustomOrder,
NoLexOrder: cfg.NoLexOrder,
},
SectionStrings: cfg.Sections,
ModPath: modPath,
}.Parse()
if err != nil {
return nil, err
}
return &Formatter{config: parsedCfg}, nil
}
func (*Formatter) Name() string {
return Name
}
func (f *Formatter) Format(filename string, src []byte) ([]byte, error) {
_, formatted, err := gci.LoadFormat(src, filename, *f.config)
return formatted, err
}