forked from golangci/golangci-lint
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgofumpt.go
41 lines (30 loc) · 764 Bytes
/
gofumpt.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
package gofumpt
import (
"strings"
gofumpt "mvdan.cc/gofumpt/format"
"github.com/golangci/golangci-lint/pkg/config"
)
const Name = "gofumpt"
type Formatter struct {
options gofumpt.Options
}
func New(settings *config.GoFumptSettings, goVersion string) *Formatter {
var options gofumpt.Options
if settings != nil {
options = gofumpt.Options{
LangVersion: getLangVersion(goVersion),
ModulePath: settings.ModulePath,
ExtraRules: settings.ExtraRules,
}
}
return &Formatter{options: options}
}
func (*Formatter) Name() string {
return Name
}
func (f *Formatter) Format(_ string, src []byte) ([]byte, error) {
return gofumpt.Source(src, f.options)
}
func getLangVersion(v string) string {
return "go" + strings.TrimPrefix(v, "go")
}