Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
I

interfacer

> 开发工具
Open source

A linter that suggests interface types

690 stars0 likes2 views
WebsiteGitHub

About

A linter that suggests interface types

interfacer

Deprecated: A tool that suggests interfaces is prone to bad suggestions, so its usefulness in real code is limited. This tool will remain available as a proof of concept, and for others to examine and learn from.

A linter that suggests interface types. In other words, it warns about the usage of types that are more specific than necessary.

go get -u mvdan.cc/interfacer

Note that this linter's suggestions tend to be subjective, as interfaces are not always the better option. You should select the proposed changes that make sense in your codebase, instead of following all of them blindly.

Usage

go
func ProcessInput(f *os.File) error {
        b, err := ioutil.ReadAll(f)
        if err != nil {
                return err
        }
        return processBytes(b)
}
bash
$ interfacer ./...
foo.go:10:19: f can be io.Reader

Basic idea

This tool inspects the parameters of your functions to see if they fit an interface type that is less specific than the current type.

The example above illustrates this point. Overly specific interfaces also trigger a warning - if f were an io.ReadCloser, the same message would appear.

It suggests interface types defined both in the func's package and the package's imports (two levels; direct imports and their direct imports).

False positives

To avoid false positives, it never does any suggestions on functions that may be implementing an interface method or a named function type.

It also skips parameters passed by value (excluding pointers and interfaces) on unexported functions, since that would introduce extra allocations where they are usually not worth the tradeoff.

Suppressing warnings

If a suggestion is technically correct but doesn't make sense, you can still suppress the warning by mentioning the type in the function name:

go
func ProcessInputFile(f *os.File) error {
	// use as an io.Reader
}

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Gogointerfacelintertypes

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category开发工具
PricingOpen source

> Related tools

V
VS Code
流行的开源代码编辑器
G
Git
分布式版本控制系统
V
Vite
下一代前端构建工具