MCPcopy Index your code
hub / github.com/butuzov/ireturn

github.com/butuzov/ireturn @v0.4.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.4.1 ↗ · + Follow
105 symbols 184 edges 26 files 20 documented · 19% 63 cross-repo links
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

ireturn Stand with Ukraine Code Coverage build status MIT License

Accept Interfaces, Return Concrete Types


United 24


Install

You can get ireturn with go install command. Go1.25+ required.

go install github.com/butuzov/ireturn/cmd/ireturn@latest

Compiled Binary

Or you can download the suitable binary from the releases section.

Usage

ireturn work with two arguments (but allow to use of only one of them in the same moment):

  • accept - accept-list of the comma-separated interfaces.
  • reject - reject-list of the comma-separated interfaces.

By default, ireturn will accept all errors (error), empty interfaces (interfaces{}), anonymous interfaces declarations ( interface { methodName() } ) and interfaces from standard library as a valid ones.

Interfaces in the list can be provided as regexps or keywords ("error" for "error", "empty" for interface{}, anon for anonymous interfaces):

# allow usage of empty interfaces, errors and Doer interface from any package.
ireturn --accept="\\.Doer,error,empty" ./...
# reject standard library interfaces and plinko.Payload as valid ones
ireturn --reject="std,github.com/shipt/plinko.Payload" ./...
# default settings allows errors, empty interfaces, anonymous declarations and standard library
ireturn ./...
# checkfor non idiomatic interface names
ireturn -allow="error,generic,anon,stdlib,.*(or|er)$" ./...

Keywords

You can use shorthand for some types of interfaces:

  • empty for interface{} type
  • anon for anonymous declarations interface{ someMethod() }
  • error for error type
  • stdlib for all interfaces from standard library.
  • generic for generic interfaces (added in go1.18)

Disable directive

golangci-lint compliant disable directive //nolint:ireturn can be used with ireturn

GitHub Action

- uses: butuzov/ireturn-linter@main
  with:
    allow: "error,empty"

Examples

// Bad.
type Doer interface { Do() }
type IDoer struct{}
func New() Doer { return new(IDoer)}
func (d *IDoer) Do() {/*...*/}

// Good.
type Doer interface { Do() }
type IDoer struct{}
func New() *IDoer { return new(IDoer)}
func (d *IDoer) Do() {/*...*/}

// Very Good (Verify Interface Compliance in compile time)
var _ Doer = (*IDoer)(nil)

type Doer interface { Do() }
type IDoer struct{}
func New() *IDoer { return new(IDoer)}
func (d *IDoer) Do() {/*...*/}

Reading List

Extension points exported contracts — how you extend this code

Validator (Interface)
(no doc) [2 implementers]
analyzer/internal/config/new.go
Fooer (Interface)
(no doc) [1 implementers]
analyzer/testdata/named_interfaces_simple.go
Barer (Interface)
(no doc) [1 implementers]
analyzer/testdata/named_interfaces_simple.go
Buzzer (Interface)
(no doc) [1 implementers]
analyzer/testdata/github.com/foo/bar/buzzer.go
FooerBarer (Interface)
(no doc)
analyzer/testdata/named_interfaces_simple.go
Doer (Interface)
(no doc)
analyzer/testdata/internal/sample/example.go

Core symbols most depended-on inside this repo

String
called by 10
analyzer/internal/types/iface.go
NewIssue
called by 8
analyzer/internal/types/iface.go
Error
called by 4
analyzer/testdata/errors.go
NewAnalyzer
called by 2
analyzer/analyzer.go
stdPkgInterface
called by 2
analyzer/analyzer.go
isStdPkgInterface
called by 2
analyzer/analyzer.go
Do
called by 2
analyzer/testdata/internal/sample/example.go
toSlice
called by 2
analyzer/internal/config/new.go

Shape

Function 52
Method 27
Struct 10
Interface 9
TypeAlias 7

Languages

Go100%

Modules by API surface

analyzer/testdata/named_interfaces_simple.go14 symbols
analyzer/testdata/generics.go14 symbols
analyzer/analyzer.go9 symbols
analyzer/testdata/errors.go8 symbols
analyzer/analyzer_test.go8 symbols
analyzer/testdata/disallow_directive_ok.go6 symbols
analyzer/internal/types/iface.go6 symbols
analyzer/internal/config/new.go6 symbols
analyzer/testdata/named_interfaces_3rdparty.go4 symbols
analyzer/testdata/internal/io/writer.go4 symbols
analyzer/testdata/named_interfaces_std.go3 symbols
analyzer/testdata/anonymous_interface.go3 symbols

For agents

$ claude mcp add ireturn \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact