Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork1.5k
Addgofactory linter#4196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:master
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Addgofactory linter#4196
Changes from9 commits
bbe0eb970cd3e55a86fb82a31b5322e29b7faecc6b2fde9cebb4065b419bf43e40eddf930e2b2c1195cfba1ed192b59b9deb43dd5df588bca1dbfe1985e045111f638File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -69,6 +69,7 @@ require ( | ||
| github.com/leonklingele/grouper v1.1.1 | ||
| github.com/lufeee/execinquery v1.2.1 | ||
| github.com/macabu/inamedparam v0.1.2 | ||
| github.com/maranqz/go-factory-lint/v2 v2.0.0-beta.4 | ||
maranqz marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| github.com/maratori/testableexamples v1.0.0 | ||
| github.com/maratori/testpackage v1.1.1 | ||
| github.com/matoous/godox v0.0.0-20230222163458-006bad1f9d26 | ||
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package golinters | ||
| import ( | ||
| "github.com/maranqz/go-factory-lint/v2" | ||
| "golang.org/x/tools/go/analysis" | ||
| "github.com/golangci/golangci-lint/pkg/config" | ||
| "github.com/golangci/golangci-lint/pkg/golinters/goanalysis" | ||
| ) | ||
| func NewGoFactoryLint(settings *config.GoFactoryLintSettings) *goanalysis.Linter { | ||
| analyzer := factory.NewAnalyzer() | ||
| cfg := make(map[string]map[string]any) | ||
| if settings != nil { | ||
| cfg[analyzer.Name] = map[string]any{} | ||
| if len(settings.PackageGlobs) > 0 { | ||
| cfg[analyzer.Name]["packageGlobs"] = settings.PackageGlobs | ||
| cfg[analyzer.Name]["onlyPackageGlobs"] = settings.OnlyPackageGlobs | ||
| } | ||
| } | ||
| return goanalysis.NewLinter( | ||
| analyzer.Name, | ||
| analyzer.Doc, | ||
| []*analysis.Analyzer{analyzer}, | ||
| cfg, | ||
| ).WithLoadMode(goanalysis.LoadModeTypesInfo) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -90,6 +90,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config { | ||
| gocycloCfg *config.GoCycloSettings | ||
| godotCfg *config.GodotSettings | ||
| godoxCfg *config.GodoxSettings | ||
| goFactoryCfg *config.GoFactoryLintSettings | ||
| gofmtCfg *config.GoFmtSettings | ||
| gofumptCfg *config.GofumptSettings | ||
| goheaderCfg *config.GoHeaderSettings | ||
| @@ -174,6 +175,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config { | ||
| gocycloCfg = &m.cfg.LintersSettings.Gocyclo | ||
| godotCfg = &m.cfg.LintersSettings.Godot | ||
| godoxCfg = &m.cfg.LintersSettings.Godox | ||
| goFactoryCfg = &m.cfg.LintersSettings.Gofactory | ||
| gofmtCfg = &m.cfg.LintersSettings.Gofmt | ||
| gofumptCfg = &m.cfg.LintersSettings.Gofumpt | ||
| goheaderCfg = &m.cfg.LintersSettings.Goheader | ||
| @@ -488,6 +490,12 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config { | ||
| WithLoadForGoAnalysis(). | ||
| WithURL("https://github.com/Djarvur/go-err113"), | ||
| linter.NewConfig(golinters.NewGoFactoryLint(goFactoryCfg)). | ||
| WithSince("1.56.0"). | ||
| WithPresets(linter.PresetStyle). | ||
ldez marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| WithLoadForGoAnalysis(). | ||
| WithURL("https://github.com/maranqz/go-factory-lint"), | ||
| linter.NewConfig(golinters.NewGofmt(gofmtCfg)). | ||
| WithSince("v1.0.0"). | ||
| WithPresets(linter.PresetFormatting). | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| //golangcitest:args -Egofactory | ||
| //golangcitest:config_path configs/go_factory_only_blocked.yml | ||
| package gofactory | ||
| import ( | ||
| "gofactory/blocked" | ||
| "gofactory/nested" | ||
| ) | ||
| var ( | ||
| nestedGlobalStruct = nested.Struct{} | ||
| nestedGlobalStructPtr = &nested.Struct{} | ||
| blockedGlobalStruct = blocked.Struct{} // want `Use factory for blocked.Struct` | ||
| blockedGlobalStructPtr = &blocked.Struct{} // want `Use factory for blocked.Struct` | ||
| ) | ||
| func Blocked() { | ||
| _ = nested.Struct{} | ||
| _ = &nested.Struct{} | ||
| _ = blocked.Struct{} // want `Use factory for blocked.Struct` | ||
| _ = &blocked.Struct{} // want `Use factory for blocked.Struct` | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| package blocked | ||
| type Struct struct{} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| linters-settings: | ||
| gofactory: | ||
| packageGlobs: | ||
| - gofactory/blocked/** | ||
| onlyPackageGlobs: true |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| //golangcitest:args -Egofactory | ||
| package gofactory | ||
| import ( | ||
| alias_blocked "gofactory/blocked" | ||
| "gofactory/nested" | ||
| ) | ||
| type Struct struct{} | ||
| var ( | ||
| defaultGlobalStruct = nested.Struct{} // want `Use factory for nested.Struct` | ||
| defaultGlobalStructPtr = &nested.Struct{} // want `Use factory for nested.Struct` | ||
| ) | ||
| func Default() { | ||
| _ = nested.Struct{} // want `Use factory for nested.Struct` | ||
| _ = &nested.Struct{} // want `Use factory for nested.Struct` | ||
| _ = []nested.Struct{{}, nested.Struct{}} // want `Use factory for nested.Struct` | ||
| _ = []*nested.Struct{{}, &nested.Struct{}} // want `Use factory for nested.Struct` | ||
| call(nested.Struct{}) // want `Use factory for nested.Struct` | ||
| _ = []Struct{{}, {}} | ||
| } | ||
| func call(_ nested.Struct) {} | ||
| func alias() { | ||
| _ = alias_blocked.Struct{} // want `Use factory for blocked.Struct` | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| module gofactory | ||
| go 1.18 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| package nested | ||
| type Struct struct{} |