Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7799b5c

Browse files
committed
1. Added reference
2. Added tests3. Added config4. Added linter
1 parent467d563 commit7799b5c

File tree

9 files changed

+93
-7
lines changed

9 files changed

+93
-7
lines changed

‎.golangci.reference.yml‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,13 @@ linters-settings:
655655
-OPTIMIZE# marks code that should be optimized before merging
656656
-HACK# marks hack-around that should be removed before merging
657657

658+
gofactory:
659+
# Default: []
660+
blockedPkgs:
661+
-github.com/author/repository/path/to/package
662+
# Default: false
663+
onlyBlockedPkgs:true
664+
658665
gofmt:
659666
# Simplify code: gofmt with `-s` option.
660667
# Default: true
@@ -2336,6 +2343,7 @@ linters:
23362343
-godot
23372344
-godox
23382345
-goerr113
2346+
-gofactory
23392347
-gofmt
23402348
-gofumpt
23412349
-goheader
@@ -2456,6 +2464,7 @@ linters:
24562464
-godot
24572465
-godox
24582466
-goerr113
2467+
-gofactory
24592468
-gofmt
24602469
-gofumpt
24612470
-goheader

‎go.mod‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ require (
6969
github.com/leonklingele/grouperv1.1.1
7070
github.com/lufeee/execinqueryv1.2.1
7171
github.com/macabu/inamedparamv0.1.2
72+
github.com/maranqz/go-factory-lintv1.0.3
7273
github.com/maratori/testableexamplesv1.0.0
7374
github.com/maratori/testpackagev1.1.1
7475
github.com/matoous/godoxv0.0.0-20230222163458-006bad1f9d26
@@ -123,7 +124,7 @@ require (
123124
go-simpler.org/sloglintv0.3.0
124125
go.tmz.dev/musttagv0.7.2
125126
golang.org/x/expv0.0.0-20230510235704-dd950f8aeaea
126-
golang.org/x/toolsv0.14.0
127+
golang.org/x/toolsv0.15.0
127128
gopkg.in/yaml.v3v3.0.1
128129
honnef.co/go/toolsv0.4.6
129130
mvdan.cc/gofumptv0.5.0
@@ -192,7 +193,7 @@ require (
192193
go.uber.org/zapv1.24.0// indirect
193194
golang.org/x/exp/typeparamsv0.0.0-20230307190834-24139beb5833// indirect
194195
golang.org/x/modv0.14.0// indirect
195-
golang.org/x/syncv0.4.0// indirect
196+
golang.org/x/syncv0.5.0// indirect
196197
golang.org/x/sysv0.14.0// indirect
197198
golang.org/x/textv0.13.0// indirect
198199
google.golang.org/protobufv1.28.0// indirect

‎go.sum‎

Lines changed: 7 additions & 5 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing 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
@@ -196,6 +196,7 @@ type LintersSettings struct {
196196
GocycloGoCycloSettings
197197
GodotGodotSettings
198198
GodoxGodoxSettings
199+
GofactoryGoFactoryLintSettings
199200
GofmtGoFmtSettings
200201
GofumptGofumptSettings
201202
GoheaderGoHeaderSettings
@@ -473,6 +474,11 @@ type GodoxSettings struct {
473474
Keywords []string
474475
}
475476

477+
typeGoFactoryLintSettingsstruct {
478+
BlockedPkgsmap[string]map[string]string`mapstructure:"BlockedPkgs"`
479+
OnlyBlockedPkgsstring`mapstructure:"OnlyBlockedPkgs"`
480+
}
481+
476482
typeGoFmtSettingsstruct {
477483
Simplifybool
478484
RewriteRules []GoFmtRewriteRule`mapstructure:"rewrite-rules"`

‎pkg/golinters/gofactorylint.go‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package golinters
2+
3+
import (
4+
"github.com/maranqz/go-factory-lint"
5+
"golang.org/x/tools/go/analysis"
6+
7+
"github.com/golangci/golangci-lint/pkg/config"
8+
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
9+
)
10+
11+
funcNewGoFactoryLint(settings*config.GoFactoryLintSettings)*goanalysis.Linter {
12+
a:=factory.NewAnalyzer()
13+
14+
cfg:=make(map[string]map[string]any)
15+
ifsettings!=nil {
16+
cfg[a.Name]=map[string]any{}
17+
18+
iflen(settings.BlockedPkgs)>0 {
19+
cfg[a.Name]["blockedPkgs"]=settings.BlockedPkgs
20+
cfg[a.Name]["onlyBlockedPkgs"]=settings.OnlyBlockedPkgs
21+
}
22+
}
23+
24+
returngoanalysis.NewLinter(
25+
a.Name,
26+
a.Doc,
27+
[]*analysis.Analyzer{a},
28+
cfg,
29+
).WithLoadMode(goanalysis.LoadModeTypesInfo)
30+
}

‎pkg/lint/lintersdb/manager.go‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
9090
gocycloCfg*config.GoCycloSettings
9191
godotCfg*config.GodotSettings
9292
godoxCfg*config.GodoxSettings
93+
goFactoryCfg*config.GoFactoryLintSettings
9394
gofmtCfg*config.GoFmtSettings
9495
gofumptCfg*config.GofumptSettings
9596
goheaderCfg*config.GoHeaderSettings
@@ -174,6 +175,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
174175
gocycloCfg=&m.cfg.LintersSettings.Gocyclo
175176
godotCfg=&m.cfg.LintersSettings.Godot
176177
godoxCfg=&m.cfg.LintersSettings.Godox
178+
goFactoryCfg=&m.cfg.LintersSettings.Gofactory
177179
gofmtCfg=&m.cfg.LintersSettings.Gofmt
178180
gofumptCfg=&m.cfg.LintersSettings.Gofumpt
179181
goheaderCfg=&m.cfg.LintersSettings.Goheader
@@ -488,6 +490,11 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
488490
WithLoadForGoAnalysis().
489491
WithURL("https://github.com/Djarvur/go-err113"),
490492

493+
linter.NewConfig(golinters.NewGoFactoryLint(goFactoryCfg)).
494+
WithSince("next_version").
495+
WithPresets(linter.PresetStyle).
496+
WithURL("https://github.com/maranqz/go-factory-lint"),
497+
491498
linter.NewConfig(golinters.NewGofmt(gofmtCfg)).
492499
WithSince("v1.0.0").
493500
WithPresets(linter.PresetFormatting).
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
linters-settings:
2+
gofactory:
3+
blockedPkgs:[]
4+
onlyBlockedPkgs:false

‎test/testdata/gofactory/app.go‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package gofactory
2+
3+
import"github.com/golangci/golangci-lint/test/testdata/gofactory/nested"
4+
5+
typeStructstruct{}
6+
7+
var (
8+
globalStruct= nested.Struct{}// want `Use factory for nested.Struct`
9+
globalStructPtr=&nested.Struct{}// want `Use factory for nested.Struct`
10+
)
11+
12+
funcfn() {
13+
_= nested.Struct{}// want `Use factory for nested.Struct`
14+
_=&nested.Struct{}// want `Use factory for nested.Struct`
15+
16+
_= []nested.Struct{{}, nested.Struct{}}// want `Use factory for nested.Struct`
17+
_= []*nested.Struct{{},&nested.Struct{}}// want `Use factory for nested.Struct`
18+
19+
call(nested.Struct{})// want `Use factory for nested.Struct`
20+
21+
_= []Struct{{}, {}}
22+
}
23+
24+
funccall(_ nested.Struct) {}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package nested
2+
3+
typeStructstruct{}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp