-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add gofactory
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
maranqz
wants to merge
19
commits into
golangci:master
Choose a base branch
from
maranqz:go-factory-lint
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add gofactory
linter
#4196
Changes from 9 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
bbe0eb9
1. Added reference
maranqz 70cd3e5
1. Update version after type fixes
maranqz 5a86fb8
1. Added tests in subdir
maranqz 2a31b53
1. Bump golangci-lint version
maranqz 22e29b7
1. Fixed settings name
maranqz faecc6b
1. Fixed test with config file
maranqz 2fde9ce
1. Update config after linter fixing
maranqz bb4065b
1. Remove slog to pass go1.20 test
maranqz 419bf43
Merge branch 'master' into go-factory-lint
maranqz e40eddf
Merge branch 'master' into go-factory-lint
maranqz 930e2b2
1. Added casting function
maranqz c1195cf
1. renamed linter
maranqz ba1ed19
Merge branch 'master' into go-factory-lint
maranqz 2b59b9d
1. fixed tests
maranqz eb43dd5
1. moved gofactory test from dedicated to common directory
maranqz df588bc
Merge branch 'master' into go-factory-lint
maranqz a1dbfe1
Merge branch 'master' into go-factory-lint
maranqz 985e045
Merge branch 'master' into go-factory-lint
maranqz 111f638
Merge branch 'master' into go-factory-lint
maranqz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package blocked | ||
|
||
type Struct struct{} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
linters-settings: | ||
gofactory: | ||
packageGlobs: | ||
- gofactory/blocked/** | ||
onlyPackageGlobs: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module gofactory | ||
|
||
go 1.18 | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package nested | ||
|
||
type Struct struct{} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.