mirror of
https://github.com/scratchfoundation/golangci-lint.git
synced 2025-08-28 22:28:43 -04:00
new-linter: ireturn (checks for function return type) (#2219)
This commit is contained in:
parent
813ba7d953
commit
2ea496f22b
11 changed files with 130 additions and 0 deletions
4
test/testdata/configs/ireturn.yml
vendored
Normal file
4
test/testdata/configs/ireturn.yml
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
linters-settings:
|
||||
ireturn:
|
||||
allow:
|
||||
- IreturnAllowDoer
|
4
test/testdata/configs/ireturn_stdlib_reject.yml
vendored
Normal file
4
test/testdata/configs/ireturn_stdlib_reject.yml
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
linters-settings:
|
||||
ireturn:
|
||||
reject:
|
||||
- stdlib
|
13
test/testdata/ireturn_allow.go
vendored
Normal file
13
test/testdata/ireturn_allow.go
vendored
Normal 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
12
test/testdata/ireturn_default.go
vendored
Normal 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
28
test/testdata/ireturn_reject_stdlib.go
vendored
Normal 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)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue