-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
new-linter: ireturn (checks for function return type) #2219
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f647e90
new-linter: ireturn (checks for function return type)
butuzov ab0f00b
fix: removed local replace directive
butuzov b8541fd
fix: ran `go mod tidy`
butuzov 4f5ed30
fix: moving linter to the end of the list
butuzov fa4d2e0
fixed: moved config to external file
butuzov 1938673
docs: Apply suggestions from code review
butuzov ccafd04
chores: version bump for `ireturn`
butuzov 0b69514
Update pkg/config/linters_settings.go
butuzov 381e9e5
fix: added `WithLoadForGoAnalysis()` to support standard library + test
butuzov 286471f
test: added stdlib test
butuzov 0620021
review
ldez 0f1cd16
review
ldez 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,35 @@ | ||
package golinters | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/golangci/golangci-lint/pkg/config" | ||
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis" | ||
|
||
"github.com/butuzov/ireturn/analyzer" | ||
"golang.org/x/tools/go/analysis" | ||
) | ||
|
||
func NewIreturn(settings *config.IreturnSettings) *goanalysis.Linter { | ||
a := analyzer.NewAnalyzer() | ||
|
||
return goanalysis.NewLinter( | ||
a.Name, | ||
a.Doc, | ||
[]*analysis.Analyzer{a}, | ||
ireturnSettings(a.Name, settings), | ||
).WithLoadMode(goanalysis.LoadModeTypesInfo) | ||
} | ||
|
||
func ireturnSettings(name string, s *config.IreturnSettings) map[string]map[string]interface{} { | ||
if s == nil { | ||
return nil | ||
} | ||
|
||
return map[string]map[string]interface{}{ | ||
name: { | ||
"allow": strings.Join(s.Allow, ","), | ||
"reject": strings.Join(s.Reject, ","), | ||
}, | ||
} | ||
} |
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,4 @@ | ||
linters-settings: | ||
ireturn: | ||
allow: | ||
- IreturnAllowDoer |
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,13 @@ | ||
// args: -Eireturn | ||
// config_path: testdata/configs/ireturn.yml | ||
package testdata | ||
|
||
type ( | ||
IreturnAllowDoer interface{ Do() } | ||
ireturnAllowDoer struct{} | ||
) | ||
|
||
func NewAllowDoer() IreturnAllowDoer { return new(ireturnAllowDoer) } | ||
func (d *ireturnAllowDoer) Do() { /*...*/ } | ||
|
||
func NewerAllowDoer() *ireturnAllowDoer { return new(ireturnAllowDoer) } |
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,12 @@ | ||
// args: -Eireturn | ||
package testdata | ||
|
||
type ( | ||
IreturnDoer interface{ Do() } | ||
ireturnDoer struct{} | ||
) | ||
|
||
func New() IreturnDoer { return new(ireturnDoer) } // ERROR `New returns interface \(command-line-arguments.IreturnDoer\)` | ||
func (d *ireturnDoer) Do() { /*...*/ } | ||
|
||
func Newer() *ireturnDoer { return new(ireturnDoer) } |
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.