Skip to content

Commit 3a48f33

Browse files
committed
review
1 parent ba56a63 commit 3a48f33

File tree

6 files changed

+102
-13
lines changed

6 files changed

+102
-13
lines changed

pkg/config/linters_settings.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ var defaultLintersSettings = LintersSettings{
4141
Forbidigo: ForbidigoSettings{
4242
ExcludeGodocExamples: true,
4343
},
44+
FuncOrder: FuncOrderSettings{
45+
Constructor: true,
46+
StructMethod: true,
47+
},
4448
Funlen: FunlenSettings{
4549
IgnoreComments: true,
4650
},
@@ -422,8 +426,8 @@ type ForbidigoPattern struct {
422426
}
423427

424428
type FuncOrderSettings struct {
425-
Constructor *bool `mapstructure:"constructor,omitempty"`
426-
StructMethod *bool `mapstructure:"struct-method,omitempty"`
429+
Constructor bool `mapstructure:"constructor,omitempty"`
430+
StructMethod bool `mapstructure:"struct-method,omitempty"`
427431
}
428432

429433
type FunlenSettings struct {

pkg/golinters/funcorder/funcorder.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,9 @@ func New(settings *config.FuncOrderSettings) *goanalysis.Linter {
1414
cfg := map[string]map[string]any{}
1515

1616
if settings != nil {
17-
constructor := true
18-
if settings.Constructor != nil {
19-
constructor = *settings.Constructor
20-
}
21-
structMethod := true
22-
if settings.StructMethod != nil {
23-
structMethod = *settings.StructMethod
24-
}
25-
2617
cfg[a.Name] = map[string]any{
27-
analyzer.ConstructorCheckName: constructor,
28-
analyzer.StructMethodCheckName: structMethod,
18+
analyzer.ConstructorCheckName: settings.Constructor,
19+
analyzer.StructMethodCheckName: settings.StructMethod,
2920
}
3021
}
3122

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//golangcitest:args -Efuncorder
2+
//golangcitest:config_path testdata/funcorder_disable_constructor.yml
3+
package testdata
4+
5+
import "time"
6+
7+
type MyStruct struct {
8+
Name string
9+
}
10+
11+
func (m MyStruct) lenName() int { // want `unexported method "lenName" for struct "MyStruct" should be placed after the exported method "SetName"`
12+
return len(m.Name)
13+
}
14+
15+
func (m MyStruct) GetName() string {
16+
return m.Name
17+
}
18+
19+
func (m *MyStruct) SetName(name string) {
20+
m.Name = name
21+
}
22+
23+
type MyStruct2 struct {
24+
Name string
25+
}
26+
27+
func (m MyStruct2) GetName() string {
28+
return m.Name
29+
}
30+
31+
func (m *MyStruct2) SetName(name string) {
32+
m.Name = name
33+
}
34+
35+
func NewMyStruct2() *MyStruct2 {
36+
return &MyStruct2{Name: "John"}
37+
}
38+
39+
func NewTime() time.Time {
40+
return time.Now()
41+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: "2"
2+
3+
linters:
4+
settings:
5+
funcorder:
6+
constructor: false
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//golangcitest:args -Efuncorder
2+
//golangcitest:config_path testdata/funcorder_struct_method.yml
3+
package testdata
4+
5+
import "time"
6+
7+
type MyStruct struct {
8+
Name string
9+
}
10+
11+
func (m MyStruct) lenName() int {
12+
return len(m.Name)
13+
}
14+
15+
func (m MyStruct) GetName() string {
16+
return m.Name
17+
}
18+
19+
func (m *MyStruct) SetName(name string) {
20+
m.Name = name
21+
}
22+
23+
type MyStruct2 struct {
24+
Name string
25+
}
26+
27+
func (m MyStruct2) GetName() string {
28+
return m.Name
29+
}
30+
31+
func (m *MyStruct2) SetName(name string) {
32+
m.Name = name
33+
}
34+
35+
func NewMyStruct2() *MyStruct2 { // want `constructor "NewMyStruct2" for struct "MyStruct2" should be placed before struct method "GetName"`
36+
return &MyStruct2{Name: "John"}
37+
}
38+
39+
func NewTime() time.Time {
40+
return time.Now()
41+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: "2"
2+
3+
linters:
4+
settings:
5+
funcorder:
6+
struct-method: false

0 commit comments

Comments
 (0)