Skip to content

Commit 033e7be

Browse files
committed
adding gofuncor linter
1 parent df67079 commit 033e7be

File tree

8 files changed

+101
-0
lines changed

8 files changed

+101
-0
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ require (
7373
github.com/ldez/usetesting v0.4.2
7474
github.com/leonklingele/grouper v1.1.2
7575
github.com/macabu/inamedparam v0.2.0
76+
github.com/manuelarte/gofuncor v0.0.3
7677
github.com/maratori/testableexamples v1.0.0
7778
github.com/maratori/testpackage v1.1.1
7879
github.com/matoous/godox v1.1.0

go.sum

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/config/formatters_settings.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type FormatterSettings struct {
1919
Gci GciSettings `mapstructure:"gci"`
2020
GoFmt GoFmtSettings `mapstructure:"gofmt"`
2121
GoFumpt GoFumptSettings `mapstructure:"gofumpt"`
22+
GoFuncOr GoFuncOrSettings `mapstructure:"gofuncor"`
2223
GoImports GoImportsSettings `mapstructure:"goimports"`
2324
GoLines GoLinesSettings `mapstructure:"golines"`
2425
}
@@ -48,6 +49,8 @@ type GoFumptSettings struct {
4849
LangVersion string `mapstructure:"-"`
4950
}
5051

52+
type GoFuncOrSettings struct{}
53+
5154
type GoImportsSettings struct {
5255
LocalPrefixes []string `mapstructure:"local-prefixes"`
5356
}

pkg/golinters/gofuncor/gofuncor.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package gofuncor
2+
3+
import (
4+
"github.com/golangci/golangci-lint/v2/pkg/config"
5+
"github.com/golangci/golangci-lint/v2/pkg/goanalysis"
6+
"github.com/manuelarte/gofuncor/pkg/analyzer"
7+
"golang.org/x/tools/go/analysis"
8+
)
9+
10+
func New(_ *config.GoFuncOrSettings) *goanalysis.Linter {
11+
a := analyzer.NewAnalyzer()
12+
13+
return goanalysis.NewLinter(
14+
a.Name,
15+
a.Doc,
16+
[]*analysis.Analyzer{a},
17+
nil,
18+
).WithLoadMode(goanalysis.LoadModeSyntax)
19+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package simple
2+
3+
//nolint:recvcheck // testing linter
4+
type MyStruct2 struct {
5+
Name string
6+
}
7+
8+
func (m MyStruct2) GetName() string {
9+
return m.Name
10+
}
11+
12+
func (m *MyStruct2) SetName(name string) {
13+
m.Name = name
14+
}
15+
16+
//nolint:nonamedreturns // testing linter
17+
func NewOtherMyStruct2() (m *MyStruct2) { // want `constructor 'NewOtherMyStruct2' for struct 'MyStruct2' should be placed before struct method 'GetName'`
18+
m = &MyStruct2{Name: "John"}
19+
return
20+
}
21+
22+
func NewMyStruct2() *MyStruct2 { // want `constructor \"NewMyStruct2\" for struct \"MyStruct2\" should be placed before struct method \"GetName\"`
23+
return &MyStruct2{Name: "John"}
24+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package simple
2+
3+
//nolint:nonamedreturns // testing linter
4+
func NewOtherMyStruct() (m *MyStruct) { // want "should be placed after the struct declaration"
5+
m = &MyStruct{Name: "John"}
6+
return
7+
}
8+
9+
func NewMyStruct() *MyStruct { // want "should be placed after the struct declaration"
10+
return &MyStruct{Name: "John"}
11+
}
12+
13+
func MustMyStruct() *MyStruct { // want `function \"MustMyStruct\" for struct \"MyStruct\" should be placed after the struct declaration`
14+
return NewMyStruct()
15+
}
16+
17+
//nolint:recvcheck // testing linter
18+
type MyStruct struct {
19+
Name string
20+
}
21+
22+
//nolint:unused // testing linter
23+
func (m MyStruct) lenName() int { // want `unexported method "lenName" for struct "MyStruct" should be placed after the exported method "GetName"`
24+
return len(m.Name)
25+
}
26+
27+
func (m MyStruct) GetName() string {
28+
return m.Name
29+
}
30+
31+
func (m *MyStruct) SetName(name string) {
32+
m.Name = name
33+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package simple
2+
3+
import (
4+
"time"
5+
)
6+
7+
func NewOtherWayMyStruct() MyStruct {
8+
return MyStruct{Name: "John"}
9+
}
10+
11+
func NewTimeStruct() time.Time {
12+
return time.Now()
13+
}

pkg/lint/lintersdb/builder_linter.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import (
4444
"github.com/golangci/golangci-lint/v2/pkg/golinters/godox"
4545
"github.com/golangci/golangci-lint/v2/pkg/golinters/gofmt"
4646
"github.com/golangci/golangci-lint/v2/pkg/golinters/gofumpt"
47+
"github.com/golangci/golangci-lint/v2/pkg/golinters/gofuncor"
4748
"github.com/golangci/golangci-lint/v2/pkg/golinters/goheader"
4849
"github.com/golangci/golangci-lint/v2/pkg/golinters/goimports"
4950
"github.com/golangci/golangci-lint/v2/pkg/golinters/golines"
@@ -335,6 +336,11 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) {
335336
WithAutoFix().
336337
WithURL("https://github.com/mvdan/gofumpt"),
337338

339+
linter.NewConfig(gofuncor.New(&cfg.Linters.Settings.GoFuncOr)).
340+
WithSince("v1.65.0").
341+
WithAutoFix().
342+
WithURL("https://github.com/manuelarte/gofuncor"),
343+
338344
linter.NewConfig(golines.New(&cfg.Linters.Settings.GoLines)).
339345
WithSince("v2.0.0").
340346
WithAutoFix().

0 commit comments

Comments
 (0)