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

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

Open
maranqz wants to merge19 commits intogolangci:master
base:master
Choose a base branch
Loading
frommaranqz:go-factory-lint
Open
Show file tree
Hide file tree
Changes from9 commits
Commits
Show all changes
19 commits
Select commitHold shift + click to select a range
bbe0eb9
1. Added reference
maranqzNov 12, 2023
70cd3e5
1. Update version after type fixes
maranqzNov 15, 2023
5a86fb8
1. Added tests in subdir
maranqzNov 15, 2023
2a31b53
1. Bump golangci-lint version
maranqzNov 15, 2023
22e29b7
1. Fixed settings name
maranqzNov 15, 2023
faecc6b
1. Fixed test with config file
maranqzNov 15, 2023
2fde9ce
1. Update config after linter fixing
maranqzNov 19, 2023
bb4065b
1. Remove slog to pass go1.20 test
maranqzNov 20, 2023
419bf43
Merge branch 'master' into go-factory-lint
maranqzNov 20, 2023
e40eddf
Merge branch 'master' into go-factory-lint
maranqzNov 26, 2023
930e2b2
1. Added casting function
maranqzNov 26, 2023
c1195cf
1. renamed linter
maranqzDec 15, 2023
ba1ed19
Merge branch 'master' into go-factory-lint
maranqzDec 15, 2023
2b59b9d
1. fixed tests
maranqzDec 15, 2023
eb43dd5
1. moved gofactory test from dedicated to common directory
maranqzDec 17, 2023
df588bc
Merge branch 'master' into go-factory-lint
maranqzDec 17, 2023
a1dbfe1
Merge branch 'master' into go-factory-lint
maranqzDec 18, 2023
985e045
Merge branch 'master' into go-factory-lint
maranqzDec 19, 2023
111f638
Merge branch 'master' into go-factory-lint
maranqzJan 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions.golangci.reference.yml
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -665,6 +665,15 @@ linters-settings:
- OPTIMIZE # marks code that should be optimized before merging
- HACK # marks hack-around that should be removed before merging

gofactory:
# List of glob packages, which can create structures without factories inside the glob package.
# Default: []
packageGlobs:
- github.com/author/repository/path/to/package/**
# Use a factory to initiate a structure for glob packages only.
# Default: false
onlyPackageGlobs: true

gofmt:
# Simplify code: gofmt with `-s` option.
# Default: true
Expand DownExpand Up@@ -2355,6 +2364,7 @@ linters:
- godot
- godox
- goerr113
- gofactory
- gofmt
- gofumpt
- goheader
Expand DownExpand Up@@ -2475,6 +2485,7 @@ linters:
- godot
- godox
- goerr113
- gofactory
- gofmt
- gofumpt
- goheader
Expand Down
1 change: 1 addition & 0 deletionsgo.mod
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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
github.com/maratori/testableexamples v1.0.0
github.com/maratori/testpackage v1.1.1
github.com/matoous/godox v0.0.0-20230222163458-006bad1f9d26
Expand Down
2 changes: 2 additions & 0 deletionsgo.sum
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

6 changes: 6 additions & 0 deletionspkg/config/linters_settings.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -199,6 +199,7 @@ type LintersSettings struct {
Gocyclo GoCycloSettings
Godot GodotSettings
Godox GodoxSettings
Gofactory GoFactoryLintSettings
Gofmt GoFmtSettings
Gofumpt GofumptSettings
Goheader GoHeaderSettings
Expand DownExpand Up@@ -479,6 +480,11 @@ type GodoxSettings struct {
Keywords []string
}

type GoFactoryLintSettings struct {
PackageGlobs []string `mapstructure:"packageGlobs"`
OnlyPackageGlobs bool `mapstructure:"onlyPackageGlobs"`
}

type GoFmtSettings struct {
Simplify bool
RewriteRules []GoFmtRewriteRule `mapstructure:"rewrite-rules"`
Expand Down
30 changes: 30 additions & 0 deletionspkg/golinters/gofactorylint.go
View file
Open in desktop
Original file line numberDiff line numberDiff 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)
}
8 changes: 8 additions & 0 deletionspkg/lint/lintersdb/manager.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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
Expand DownExpand Up@@ -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
Expand DownExpand Up@@ -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).
WithLoadForGoAnalysis().
WithURL("https://github.com/maranqz/go-factory-lint"),

linter.NewConfig(golinters.NewGofmt(gofmtCfg)).
WithSince("v1.0.0").
WithPresets(linter.PresetFormatting).
Expand Down
1 change: 1 addition & 0 deletionstest/linters_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -33,6 +33,7 @@ func TestSourcesFromTestdataSubDir(t *testing.T) {
"ginkgolinter",
"zerologlint",
"protogetter",
"gofactory",
}

for _, dir := range subDirs {
Expand Down
24 changes: 24 additions & 0 deletionstest/testdata/gofactory/blocked.go
View file
Open in desktop
Original file line numberDiff line numberDiff 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`
}
3 changes: 3 additions & 0 deletionstest/testdata/gofactory/blocked/blocked.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
package blocked

type Struct struct{}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
linters-settings:
gofactory:
packageGlobs:
- gofactory/blocked/**
onlyPackageGlobs: true
32 changes: 32 additions & 0 deletionstest/testdata/gofactory/default.go
View file
Open in desktop
Original file line numberDiff line numberDiff 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`
}
4 changes: 4 additions & 0 deletionstest/testdata/gofactory/go.mod
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
module gofactory

go 1.18

3 changes: 3 additions & 0 deletionstest/testdata/gofactory/nested/nested.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
package nested

type Struct struct{}

[8]ページ先頭

©2009-2025 Movatter.jp