{"id":16915024,"url":"https://github.com/butuzov/ireturn","last_synced_at":"2025-05-15T15:02:13.954Z","repository":{"id":45331136,"uuid":"397688707","full_name":"butuzov/ireturn","owner":"butuzov","description":"Accept Interfaces, Return Concrete Types","archived":false,"fork":false,"pushed_at":"2025-05-05T00:32:17.000Z","size":145,"stargazers_count":66,"open_issues_count":7,"forks_count":4,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-05-15T15:01:58.388Z","etag":null,"topics":["go","golangci-lint","interfaces","linter"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/butuzov.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-08-18T17:47:53.000Z","updated_at":"2025-05-06T11:22:16.000Z","dependencies_parsed_at":"2023-01-11T17:22:47.975Z","dependency_job_id":"c2d56ad2-ee8e-4063-8f33-9dc696cf1587","html_url":"https://github.com/butuzov/ireturn","commit_stats":{"total_commits":104,"total_committers":8,"mean_commits":13.0,"dds":0.2692307692307693,"last_synced_commit":"242cbbaf9b6e51ce80cc7976c4a09a2672dc60e4"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/butuzov%2Fireturn","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/butuzov%2Fireturn/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/butuzov%2Fireturn/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/butuzov%2Fireturn/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/butuzov","download_url":"https://codeload.github.com/butuzov/ireturn/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254364267,"owners_count":22058877,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","golangci-lint","interfaces","linter"],"created_at":"2024-10-13T19:16:06.053Z","updated_at":"2025-05-15T15:02:13.948Z","avatar_url":"https://github.com/butuzov.png","language":"Go","readme":"# `ireturn` [![Stand with Ukraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/badges/StandWithUkraine.svg)](https://u24.gov.ua/) [![Code Coverage](https://coveralls.io/repos/github/butuzov/ireturn/badge.svg?branch=main)](https://coveralls.io/github/butuzov/ireturn?branch=main) [![build status](https://github.com/butuzov/ireturn/actions/workflows/main.yaml/badge.svg?branch=main)]() [![MIT License](http://img.shields.io/badge/license-MIT-blue.svg)](http://www.opensource.org/licenses/MIT)\n\nAccept Interfaces, Return Concrete Types\n\n---\n\n[![United 24](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/banner-personal-page.svg)](https://u24.gov.ua/)\n\n---\n\n## Install\n\nYou can get `ireturn` with `go install` command. Go1.23+ required.\n\n```shell\ngo install github.com/butuzov/ireturn/cmd/ireturn@latest\n```\n\n### Compiled Binary\n\nOr you can download the suitable binary from the [releases](https://github.com/butuzov/ireturn/releases) section.\n\n## Usage\n\n`ireturn` work with two arguments (but allow to use of only one of them in the same moment):\n\n- `accept` - accept-list of the comma-separated interfaces.\n- `reject` - reject-list of the comma-separated interfaces.\n\nBy default, `ireturn` will accept all errors (`error`), empty interfaces (`interfaces{}`), anonymous interfaces declarations ( `interface { methodName() }` ) and interfaces from standard library as a valid ones.\n\nInterfaces in the list can be provided as regexps or keywords (\"error\" for \"error\", \"empty\" for `interface{}`, `anon` for anonymous interfaces):\n\n```bash\n# allow usage of empty interfaces, errors and Doer interface from any package.\nireturn --accept=\"\\\\.Doer,error,empty\" ./...\n# reject standard library interfaces and plinko.Payload as valid ones\nireturn --reject=\"std,github.com/shipt/plinko.Payload\" ./...\n# default settings allows errors, empty interfaces, anonymous declarations and standard library\nireturn ./...\n# checkfor non idiomatic interface names\nireturn -allow=\"error,generic,anon,stdlib,.*(or|er)$\" ./...\n```\n\n### Keywords\n\nYou can use shorthand for some types of interfaces:\n\n- `empty` for `interface{}` type\n- `anon` for anonymous declarations `interface{ someMethod() }`\n- `error` for `error` type\n- `stdlib` for all interfaces from standard library.\n- `generic` for generic interfaces (added in go1.18)\n\n### Disable directive\n\n`golangci-lint` compliant disable directive `//nolint:ireturn` can be used with `ireturn`\n\n### GitHub Action\n\n```\n- uses: butuzov/ireturn-linter@main\n  with:\n    allow: \"error,empty\"\n```\n\n## Examples\n\n```go\n// Bad.\ntype Doer interface { Do() }\ntype IDoer struct{}\nfunc New() Doer { return new(IDoer)}\nfunc (d *IDoer) Do() {/*...*/}\n\n// Good.\ntype Doer interface { Do() }\ntype IDoer struct{}\nfunc New() *IDoer { return new(IDoer)}\nfunc (d *IDoer) Do() {/*...*/}\n\n// Very Good (Verify Interface Compliance in compile time)\nvar _ Doer = (*IDoer)(nil)\n\ntype Doer interface { Do() }\ntype IDoer struct{}\nfunc New() *IDoer { return new(IDoer)}\nfunc (d *IDoer) Do() {/*...*/}\n\n```\n\n## Reading List\n\n- [Rob Pike's comment on \"Accept Interfaces Return Struct in Go\"](https://github.com/go-proverbs/go-proverbs.github.io/issues/37)\n- [Accept Interfaces Return Struct in Go](https://mycodesmells.com/post/accept-interfaces-return-struct-in-go)\n- [Accept Interface Return Struct](https://blog.dlow.me/programming/golang/accept-interface-return-struct/)\n- [What “accept interfaces, return structs” means in Go](https://medium.com/@cep21/what-accept-interfaces-return-structs-means-in-go-2fe879e25ee8)\n","funding_links":[],"categories":["Go"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbutuzov%2Fireturn","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbutuzov%2Fireturn","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbutuzov%2Fireturn/lists"}