forked from golangci/golangci-lint
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new-linter: ireturn (checks for function return type) (golangci#2219)
- Loading branch information
Showing
11 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 ( | ||
"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() | ||
|
||
cfg := map[string]map[string]interface{}{} | ||
if settings != nil { | ||
cfg[a.Name] = map[string]interface{}{ | ||
"allow": strings.Join(settings.Allow, ","), | ||
"reject": strings.Join(settings.Reject, ","), | ||
} | ||
} | ||
|
||
return goanalysis.NewLinter( | ||
a.Name, | ||
a.Doc, | ||
[]*analysis.Analyzer{a}, | ||
cfg, | ||
).WithLoadMode(goanalysis.LoadModeTypesInfo) | ||
} |
This file contains 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 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 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: | ||
reject: | ||
- stdlib |
This file contains 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 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) } |
This file contains 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,28 @@ | ||
// args: -Eireturn | ||
// config_path: testdata/configs/ireturn_stdlib_reject.yml | ||
package testdata | ||
|
||
import ( | ||
"bytes" | ||
"io" | ||
) | ||
|
||
func NewWriter() io.Writer { // ERROR `NewWriter returns interface \(io.Writer\)` | ||
var buf bytes.Buffer | ||
return &buf | ||
} | ||
|
||
func TestError() error { | ||
return nil | ||
} | ||
|
||
type Foo interface { | ||
Foo() | ||
} | ||
type foo int | ||
|
||
func (f foo) Foo() {} | ||
|
||
func NewFoo() Foo { | ||
return foo(1) | ||
} |