All Projects → mvdan → Interfacer

mvdan / Interfacer

Licence: bsd-3-clause
A linter that suggests interface types

Programming Languages

go
31211 projects - #10 most used programming language
types
53 projects

Projects that are alternatives of or similar to Interfacer

Deal
Design by contract for Python with static checker and tests' generation.
Stars: ✭ 164 (-76.77%)
Mutual labels:  linter, interface
Phplint
🐛 A tool that can speed up linting of php files by running several lint processes at once.
Stars: ✭ 646 (-8.5%)
Mutual labels:  linter
Oas Kit
Convert Swagger 2.0 definitions to OpenAPI 3.0 and resolve/validate/lint
Stars: ✭ 516 (-26.91%)
Mutual labels:  linter
Hadolint
Dockerfile linter, validate inline bash, written in Haskell
Stars: ✭ 6,284 (+790.08%)
Mutual labels:  linter
Pep8speaks
A GitHub app to automatically review Python code style over Pull Requests
Stars: ✭ 546 (-22.66%)
Mutual labels:  linter
Devskim
DevSkim is a set of IDE plugins and rules that provide security "linting" capabilities.
Stars: ✭ 576 (-18.41%)
Mutual labels:  linter
Zally
A minimalistic, simple-to-use API linter
Stars: ✭ 499 (-29.32%)
Mutual labels:  linter
Standard
🌟 JavaScript Style Guide, with linter & automatic code fixer
Stars: ✭ 26,433 (+3644.05%)
Mutual labels:  linter
Stylelint Processor Styled Components
Lint your styled components with stylelint!
Stars: ✭ 639 (-9.49%)
Mutual labels:  linter
Fxtest
接口自动化测试平台——python+flask版,支持http协议,java 版本开发完毕https://github.com/liwanlei/plan
Stars: ✭ 564 (-20.11%)
Mutual labels:  interface
Axiom
An FFmpeg GUI for Windows
Stars: ✭ 560 (-20.68%)
Mutual labels:  interface
Superstruct
A simple and composable way to validate data in JavaScript (and TypeScript).
Stars: ✭ 5,604 (+693.77%)
Mutual labels:  interface
Scalafix
Refactoring and linting tool for Scala
Stars: ✭ 597 (-15.44%)
Mutual labels:  linter
Flake8 Bugbear
A plugin for Flake8 finding likely bugs and design problems in your program. Contains warnings that don't belong in pyflakes and pycodestyle.
Stars: ✭ 518 (-26.63%)
Mutual labels:  linter
Xo
❤️ JavaScript/TypeScript linter (ESLint wrapper) with great defaults
Stars: ✭ 6,277 (+789.09%)
Mutual labels:  linter
Postcss Bem Linter
A BEM linter for postcss
Stars: ✭ 505 (-28.47%)
Mutual labels:  linter
Esprint
Fast eslint runner
Stars: ✭ 556 (-21.25%)
Mutual labels:  linter
Undercover
Actionable code coverage - detects untested code blocks in recent changes
Stars: ✭ 574 (-18.7%)
Mutual labels:  linter
Rapid.js
An ORM-like Interface and a Router For Your API Requests
Stars: ✭ 700 (-0.85%)
Mutual labels:  interface
Pre Commit
A framework for managing and maintaining multi-language pre-commit hooks.
Stars: ✭ 7,024 (+894.9%)
Mutual labels:  linter

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
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].