interfacer

一个提示接口类型的 linter。(A linter that suggests interface types)

  • 所有者: mvdan/interfacer
  • 平台: Linux, Mac, Windows
  • 許可證: BSD 3-Clause "New" or "Revised" License
  • 分類:
  • 主題:
  • 喜歡:
    0
      比較:

Github星跟蹤圖

interfacer

GoDoc
Build Status

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

func ProcessInput(f *os.File) error {
        b, err := ioutil.ReadAll(f)
        if err != nil {
                return err
        }
        return processBytes(b)
}
$ 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:

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

主要指標

概覽
名稱與所有者mvdan/interfacer
主編程語言Go
編程語言Go (語言數: 1)
平台Linux, Mac, Windows
許可證BSD 3-Clause "New" or "Revised" License
所有者活动
創建於2015-12-06 02:27:57
推送於2018-09-01 00:41:13
最后一次提交2018-08-31 18:38:55
發布數0
用户参与
星數688
關注者數12
派生數13
提交數489
已啟用問題?
問題數35
打開的問題數0
拉請求數1
打開的拉請求數0
關閉的拉請求數2
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?