Skip to content

Commit 59de295

Browse files
committed
newlinter: adding funcorder settings
1 parent 304d72b commit 59de295

File tree

6 files changed

+39
-7
lines changed

6 files changed

+39
-7
lines changed

.golangci.next.reference.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,12 @@ linters:
531531
# Default: false
532532
analyze-types: true
533533

534+
funcorder:
535+
# Enable/disable feature to check constructors are placed after struct declaration
536+
constructor: true
537+
# Enable/disable feature to check whether the exported struct's methods are placed before the non-exported
538+
struct-method: true
539+
534540
funlen:
535541
# Checks the number of lines in a function.
536542
# If lower than 0, disable the check.

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +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/funcorder v0.1.2
76+
github.com/manuelarte/funcorder v0.2.0
7777
github.com/maratori/testableexamples v1.0.0
7878
github.com/maratori/testpackage v1.1.1
7979
github.com/matoous/godox v1.1.0

go.sum

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

pkg/config/linters_settings.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ type LintersSettings struct {
217217
Exhaustruct ExhaustructSettings `mapstructure:"exhaustruct"`
218218
Fatcontext FatcontextSettings `mapstructure:"fatcontext"`
219219
Forbidigo ForbidigoSettings `mapstructure:"forbidigo"`
220+
FuncOrder FuncOrderSettings `mapstructure:"funcorder"`
220221
Funlen FunlenSettings `mapstructure:"funlen"`
221222
GinkgoLinter GinkgoLinterSettings `mapstructure:"ginkgolinter"`
222223
Gocognit GocognitSettings `mapstructure:"gocognit"`
@@ -420,6 +421,11 @@ type ForbidigoPattern struct {
420421
Msg string `yaml:"msg,omitempty" mapstructure:"msg,omitempty"`
421422
}
422423

424+
type FuncOrderSettings struct {
425+
Constructor *bool `mapstructure:"constructor,omitempty"`
426+
StructMethod *bool `mapstructure:"struct-method,omitempty"`
427+
}
428+
423429
type FunlenSettings struct {
424430
Lines int `mapstructure:"lines"`
425431
Statements int `mapstructure:"statements"`

pkg/golinters/funcorder/funcorder.go

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,39 @@
11
package funcorder
22

33
import (
4-
"github.com/manuelarte/funcorder/pkg/analyzer"
4+
"github.com/manuelarte/funcorder/analyzer"
55
"golang.org/x/tools/go/analysis"
66

7+
"github.com/golangci/golangci-lint/v2/pkg/config"
8+
79
"github.com/golangci/golangci-lint/v2/pkg/goanalysis"
810
)
911

10-
func New() *goanalysis.Linter {
12+
func New(settings *config.FuncOrderSettings) *goanalysis.Linter {
1113
a := analyzer.NewAnalyzer()
1214

15+
cfg := map[string]map[string]any{}
16+
17+
if settings != nil {
18+
constructor := true
19+
if settings.Constructor != nil {
20+
constructor = *settings.Constructor
21+
}
22+
structMethod := true
23+
if settings.StructMethod != nil {
24+
structMethod = *settings.StructMethod
25+
}
26+
27+
cfg[a.Name] = map[string]any{
28+
"constructor": constructor,
29+
"struct-method": structMethod,
30+
}
31+
}
32+
1333
return goanalysis.NewLinter(
1434
a.Name,
1535
a.Doc,
1636
[]*analysis.Analyzer{a},
17-
nil,
37+
cfg,
1838
).WithLoadMode(goanalysis.LoadModeSyntax)
1939
}

pkg/lint/lintersdb/builder_linter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) {
255255
WithLoadForGoAnalysis().
256256
WithURL("https://github.com/gostaticanalysis/forcetypeassert"),
257257

258-
linter.NewConfig(funcorder.New()).
258+
linter.NewConfig(funcorder.New(&cfg.Linters.Settings.FuncOrder)).
259259
WithSince("v2.1.0").
260260
WithURL("https://github.com/manuelarte/funcorder"),
261261

0 commit comments

Comments
 (0)