File tree Expand file tree Collapse file tree 6 files changed +102
-13
lines changed Expand file tree Collapse file tree 6 files changed +102
-13
lines changed Original file line number Diff line number Diff line change @@ -41,6 +41,10 @@ var defaultLintersSettings = LintersSettings{
41
41
Forbidigo : ForbidigoSettings {
42
42
ExcludeGodocExamples : true ,
43
43
},
44
+ FuncOrder : FuncOrderSettings {
45
+ Constructor : true ,
46
+ StructMethod : true ,
47
+ },
44
48
Funlen : FunlenSettings {
45
49
IgnoreComments : true ,
46
50
},
@@ -422,8 +426,8 @@ type ForbidigoPattern struct {
422
426
}
423
427
424
428
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"`
427
431
}
428
432
429
433
type FunlenSettings struct {
Original file line number Diff line number Diff line change @@ -14,18 +14,9 @@ func New(settings *config.FuncOrderSettings) *goanalysis.Linter {
14
14
cfg := map [string ]map [string ]any {}
15
15
16
16
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
-
26
17
cfg [a .Name ] = map [string ]any {
27
- analyzer .ConstructorCheckName : constructor ,
28
- analyzer .StructMethodCheckName : structMethod ,
18
+ analyzer .ConstructorCheckName : settings . Constructor ,
19
+ analyzer .StructMethodCheckName : settings . StructMethod ,
29
20
}
30
21
}
31
22
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
1
+ version : " 2"
2
+
3
+ linters :
4
+ settings :
5
+ funcorder :
6
+ constructor : false
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
1
+ version : " 2"
2
+
3
+ linters :
4
+ settings :
5
+ funcorder :
6
+ struct-method : false
You can’t perform that action at this time.
0 commit comments