new-linter: ireturn (checks for function return type) (#2219)

This commit is contained in:
Oleg Butuzov 2021-09-16 12:47:56 +03:00 committed by GitHub
parent 813ba7d953
commit 2ea496f22b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 130 additions and 0 deletions

4
test/testdata/configs/ireturn.yml vendored Normal file
View file

@ -0,0 +1,4 @@
linters-settings:
ireturn:
allow:
- IreturnAllowDoer

View file

@ -0,0 +1,4 @@
linters-settings:
ireturn:
reject:
- stdlib

13
test/testdata/ireturn_allow.go vendored Normal file
View file

@ -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) }

12
test/testdata/ireturn_default.go vendored Normal file
View file

@ -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) }

28
test/testdata/ireturn_reject_stdlib.go vendored Normal file
View file

@ -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)
}