{"action":"created","comment":{"url":"https://api.github.com/repos/go-critic/go-critic/pulls/comments/195909870","pull_request_review_id":129370434,"id":195909870,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDE5NTkwOTg3MA==","diff_hunk":"@@ -0,0 +1,62 @@\n+package lint\n+\n+import (\n+\t\"go/ast\"\n+\t\"go/token\"\n+\t\"go/types\"\n+\t\"strings\"\n+)\n+\n+func init() {\n+\taddChecker(implAssertChecker{}, &ruleInfo{})\n+}\n+\n+type implAssertChecker struct {\n+\tctx *context\n+}\n+\n+func (c implAssertChecker) New(ctx *context) func(*ast.File) {\n+\tc.ctx = ctx\n+\treturn c.CheckFile\n+}\n+\n+func (c implAssertChecker) CheckFile(f *ast.File) {\n+\tif strings.HasSuffix(c.ctx.Filename, \"_test.go\") ||\n+\t\tstrings.HasSuffix(f.Name.Name, \"_test\") {\n+\t\treturn\n+\t}\n+\tfor _, decl := range f.Decls {\n+\t\tdecl, ok := decl.(*ast.GenDecl)\n+\t\tif !ok {\n+\t\t\tcontinue\n+\t\t}\n+\t\tif decl.Tok != token.VAR {\n+\t\t\tcontinue\n+\t\t}\n+\t\t// TODO(cristaloleg): we might want to support multiple assertion in the future.\n+\t\tif len(decl.Specs) != 1 {\n+\t\t\treturn\n+\t\t}\n+\t\tvalueSpec, ok := decl.Specs[0].(*ast.ValueSpec)\n+\t\tif !ok {\n+\t\t\treturn\n+\t\t}\n+\t\tif len(valueSpec.Names) != 1 || valueSpec.Names[0].Name != \"_\" {\n+\t\t\treturn\n+\t\t}\n+\t\tif _, ok := c.ctx.TypesInfo.TypeOf(valueSpec.Type).(*types.Interface); !ok {\n+\t\t\treturn\n+\t\t}\n+\t\tif len(valueSpec.Values) != 1 {\n+\t\t\treturn\n+\t\t}\n+\t\tif _, ok := c.ctx.TypesInfo.TypeOf(valueSpec.Values[0]).(*types.Struct); !ok {\n+\t\t\treturn\n+\t\t}","path":"lint/implAssert_checker.go","position":55,"original_position":55,"commit_id":"98ae3424410d5533e221f4b7e456af4d0bab1cb4","original_commit_id":"98ae3424410d5533e221f4b7e456af4d0bab1cb4","user":{"login":"Quasilyte","id":6286655,"node_id":"MDQ6VXNlcjYyODY2NTU=","avatar_url":"https://avatars3.githubusercontent.com/u/6286655?v=4","gravatar_id":"","url":"https://api.github.com/users/Quasilyte","html_url":"https://github.com/Quasilyte","followers_url":"https://api.github.com/users/Quasilyte/followers","following_url":"https://api.github.com/users/Quasilyte/following{/other_user}","gists_url":"https://api.github.com/users/Quasilyte/gists{/gist_id}","starred_url":"https://api.github.com/users/Quasilyte/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Quasilyte/subscriptions","organizations_url":"https://api.github.com/users/Quasilyte/orgs","repos_url":"https://api.github.com/users/Quasilyte/repos","events_url":"https://api.github.com/users/Quasilyte/events{/privacy}","received_events_url":"https://api.github.com/users/Quasilyte/received_events","type":"User","site_admin":false},"body":"For this kind of early return sequences, we sometimes use this idiom:\r\n```diff\r\n- \tif !ok {\r\n- \t\treturn\r\n- \t}\r\n- \tif len(valueSpec.Names) != 1 || valueSpec.Names[0].Name != \"_\" {\r\n- \t\treturn\r\n- \t}\r\n- \tif _, ok := c.ctx.TypesInfo.TypeOf(valueSpec.Type).(*types.Interface); !ok {\r\n- \t\treturn\r\n- \t}\r\n- \tif len(valueSpec.Values) != 1 {\r\n- \t\treturn\r\n- \t}\r\n- \tif _, ok := c.ctx.TypesInfo.TypeOf(valueSpec.Values[0]).(*types.Struct); !ok {\r\n- \t\treturn\r\n- \t}\r\n+ cond := ok &&\r\n+ \tlen(valueSpec.Names) == 1 &&\r\n+ \tlen(valueSpec.Values) == 1 &&\r\n+ \tvalueSpec.Names[0].Name == \"_\"\r\n+ if !cond {\r\n+ \treturn\r\n+ }\r\n+ if _, ok := c.ctx.TypesInfo.TypeOf(valueSpec.Type).(*types.Interface); !ok {\r\n+ \treturn\r\n+ }\r\n+ if _, ok := c.ctx.TypesInfo.TypeOf(valueSpec.Values[0]).(*types.Struct); !ok {\r\n+ \treturn\r\n+ }\r\n```\r\n\r\nIf we had `typep`:\r\n```go\r\ncond := ok &&\r\n\tlen(valueSpec.Names) == 1 &&\r\n\tlen(valueSpec.Values) == 1 &&\r\n\tvalueSpec.Names[0].Name == \"_\" &&\r\n\ttypep.IsInterface(c.ctx.TypesInfo.TypeOf(valueSpec.Type)) &&\r\n\ttypep.IsStruct(c.ctx.TypesInfo.TypeOf(valueSpec.Values[0]))\r\nif !cond {\r\n\treturn\r\n}\r\n```\r\n","created_at":"2018-06-16T18:58:13Z","updated_at":"2018-06-16T18:58:13Z","html_url":"https://github.com/go-critic/go-critic/pull/236#discussion_r195909870","pull_request_url":"https://api.github.com/repos/go-critic/go-critic/pulls/236","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/go-critic/go-critic/pulls/comments/195909870"},"html":{"href":"https://github.com/go-critic/go-critic/pull/236#discussion_r195909870"},"pull_request":{"href":"https://api.github.com/repos/go-critic/go-critic/pulls/236"}}},"pull_request":{"url":"https://api.github.com/repos/go-critic/go-critic/pulls/236","id":195342498,"node_id":"MDExOlB1bGxSZXF1ZXN0MTk1MzQyNDk4","html_url":"https://github.com/go-critic/go-critic/pull/236","diff_url":"https://github.com/go-critic/go-critic/pull/236.diff","patch_url":"https://github.com/go-critic/go-critic/pull/236.patch","issue_url":"https://api.github.com/repos/go-critic/go-critic/issues/236","number":236,"state":"open","locked":false,"title":"[WIP] lint: implementation assert in code files","user":{"login":"cristaloleg","id":366002,"node_id":"MDQ6VXNlcjM2NjAwMg==","avatar_url":"https://avatars1.githubusercontent.com/u/366002?v=4","gravatar_id":"","url":"https://api.github.com/users/cristaloleg","html_url":"https://github.com/cristaloleg","followers_url":"https://api.github.com/users/cristaloleg/followers","following_url":"https://api.github.com/users/cristaloleg/following{/other_user}","gists_url":"https://api.github.com/users/cristaloleg/gists{/gist_id}","starred_url":"https://api.github.com/users/cristaloleg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cristaloleg/subscriptions","organizations_url":"https://api.github.com/users/cristaloleg/orgs","repos_url":"https://api.github.com/users/cristaloleg/repos","events_url":"https://api.github.com/users/cristaloleg/events{/privacy}","received_events_url":"https://api.github.com/users/cristaloleg/received_events","type":"User","site_admin":false},"body":"Fixes #206 ","created_at":"2018-06-16T18:02:31Z","updated_at":"2018-06-16T18:58:13Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0ff9761e13e3b1e742e1b4adb8f9f0250c064e5a","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":923832696,"node_id":"MDU6TGFiZWw5MjM4MzI2OTY=","url":"https://api.github.com/repos/go-critic/go-critic/labels/Don't%20merge","name":"Don't merge","color":"a30d03","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/go-critic/go-critic/pulls/236/commits","review_comments_url":"https://api.github.com/repos/go-critic/go-critic/pulls/236/comments","review_comment_url":"https://api.github.com/repos/go-critic/go-critic/pulls/comments{/number}","comments_url":"https://api.github.com/repos/go-critic/go-critic/issues/236/comments","statuses_url":"https://api.github.com/repos/go-critic/go-critic/statuses/98ae3424410d5533e221f4b7e456af4d0bab1cb4","head":{"label":"go-critic:feature/implAssert","ref":"feature/implAssert","sha":"98ae3424410d5533e221f4b7e456af4d0bab1cb4","user":{"login":"go-critic","id":40007520,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQwMDA3NTIw","avatar_url":"https://avatars2.githubusercontent.com/u/40007520?v=4","gravatar_id":"","url":"https://api.github.com/users/go-critic","html_url":"https://github.com/go-critic","followers_url":"https://api.github.com/users/go-critic/followers","following_url":"https://api.github.com/users/go-critic/following{/other_user}","gists_url":"https://api.github.com/users/go-critic/gists{/gist_id}","starred_url":"https://api.github.com/users/go-critic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/go-critic/subscriptions","organizations_url":"https://api.github.com/users/go-critic/orgs","repos_url":"https://api.github.com/users/go-critic/repos","events_url":"https://api.github.com/users/go-critic/events{/privacy}","received_events_url":"https://api.github.com/users/go-critic/received_events","type":"Organization","site_admin":false},"repo":{"id":132232698,"node_id":"MDEwOlJlcG9zaXRvcnkxMzIyMzI2OTg=","name":"go-critic","full_name":"go-critic/go-critic","owner":{"login":"go-critic","id":40007520,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQwMDA3NTIw","avatar_url":"https://avatars2.githubusercontent.com/u/40007520?v=4","gravatar_id":"","url":"https://api.github.com/users/go-critic","html_url":"https://github.com/go-critic","followers_url":"https://api.github.com/users/go-critic/followers","following_url":"https://api.github.com/users/go-critic/following{/other_user}","gists_url":"https://api.github.com/users/go-critic/gists{/gist_id}","starred_url":"https://api.github.com/users/go-critic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/go-critic/subscriptions","organizations_url":"https://api.github.com/users/go-critic/orgs","repos_url":"https://api.github.com/users/go-critic/repos","events_url":"https://api.github.com/users/go-critic/events{/privacy}","received_events_url":"https://api.github.com/users/go-critic/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/go-critic/go-critic","description":"The most opinionated Go source code linter","fork":false,"url":"https://api.github.com/repos/go-critic/go-critic","forks_url":"https://api.github.com/repos/go-critic/go-critic/forks","keys_url":"https://api.github.com/repos/go-critic/go-critic/keys{/key_id}","collaborators_url":"https://api.github.com/repos/go-critic/go-critic/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/go-critic/go-critic/teams","hooks_url":"https://api.github.com/repos/go-critic/go-critic/hooks","issue_events_url":"https://api.github.com/repos/go-critic/go-critic/issues/events{/number}","events_url":"https://api.github.com/repos/go-critic/go-critic/events","assignees_url":"https://api.github.com/repos/go-critic/go-critic/assignees{/user}","branches_url":"https://api.github.com/repos/go-critic/go-critic/branches{/branch}","tags_url":"https://api.github.com/repos/go-critic/go-critic/tags","blobs_url":"https://api.github.com/repos/go-critic/go-critic/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/go-critic/go-critic/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/go-critic/go-critic/git/refs{/sha}","trees_url":"https://api.github.com/repos/go-critic/go-critic/git/trees{/sha}","statuses_url":"https://api.github.com/repos/go-critic/go-critic/statuses/{sha}","languages_url":"https://api.github.com/repos/go-critic/go-critic/languages","stargazers_url":"https://api.github.com/repos/go-critic/go-critic/stargazers","contributors_url":"https://api.github.com/repos/go-critic/go-critic/contributors","subscribers_url":"https://api.github.com/repos/go-critic/go-critic/subscribers","subscription_url":"https://api.github.com/repos/go-critic/go-critic/subscription","commits_url":"https://api.github.com/repos/go-critic/go-critic/commits{/sha}","git_commits_url":"https://api.github.com/repos/go-critic/go-critic/git/commits{/sha}","comments_url":"https://api.github.com/repos/go-critic/go-critic/comments{/number}","issue_comment_url":"https://api.github.com/repos/go-critic/go-critic/issues/comments{/number}","contents_url":"https://api.github.com/repos/go-critic/go-critic/contents/{+path}","compare_url":"https://api.github.com/repos/go-critic/go-critic/compare/{base}...{head}","merges_url":"https://api.github.com/repos/go-critic/go-critic/merges","archive_url":"https://api.github.com/repos/go-critic/go-critic/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/go-critic/go-critic/downloads","issues_url":"https://api.github.com/repos/go-critic/go-critic/issues{/number}","pulls_url":"https://api.github.com/repos/go-critic/go-critic/pulls{/number}","milestones_url":"https://api.github.com/repos/go-critic/go-critic/milestones{/number}","notifications_url":"https://api.github.com/repos/go-critic/go-critic/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/go-critic/go-critic/labels{/name}","releases_url":"https://api.github.com/repos/go-critic/go-critic/releases{/id}","deployments_url":"https://api.github.com/repos/go-critic/go-critic/deployments","created_at":"2018-05-05T09:17:26Z","updated_at":"2018-06-16T17:38:58Z","pushed_at":"2018-06-16T18:40:16Z","git_url":"git://github.com/go-critic/go-critic.git","ssh_url":"git@github.com:go-critic/go-critic.git","clone_url":"https://github.com/go-critic/go-critic.git","svn_url":"https://github.com/go-critic/go-critic","homepage":"","size":2234,"stargazers_count":11,"watchers_count":11,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"archived":false,"open_issues_count":35,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":1,"open_issues":35,"watchers":11,"default_branch":"master"}},"base":{"label":"go-critic:master","ref":"master","sha":"fc553db503168a9bfdafadd95d603d1af5870f1d","user":{"login":"go-critic","id":40007520,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQwMDA3NTIw","avatar_url":"https://avatars2.githubusercontent.com/u/40007520?v=4","gravatar_id":"","url":"https://api.github.com/users/go-critic","html_url":"https://github.com/go-critic","followers_url":"https://api.github.com/users/go-critic/followers","following_url":"https://api.github.com/users/go-critic/following{/other_user}","gists_url":"https://api.github.com/users/go-critic/gists{/gist_id}","starred_url":"https://api.github.com/users/go-critic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/go-critic/subscriptions","organizations_url":"https://api.github.com/users/go-critic/orgs","repos_url":"https://api.github.com/users/go-critic/repos","events_url":"https://api.github.com/users/go-critic/events{/privacy}","received_events_url":"https://api.github.com/users/go-critic/received_events","type":"Organization","site_admin":false},"repo":{"id":132232698,"node_id":"MDEwOlJlcG9zaXRvcnkxMzIyMzI2OTg=","name":"go-critic","full_name":"go-critic/go-critic","owner":{"login":"go-critic","id":40007520,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQwMDA3NTIw","avatar_url":"https://avatars2.githubusercontent.com/u/40007520?v=4","gravatar_id":"","url":"https://api.github.com/users/go-critic","html_url":"https://github.com/go-critic","followers_url":"https://api.github.com/users/go-critic/followers","following_url":"https://api.github.com/users/go-critic/following{/other_user}","gists_url":"https://api.github.com/users/go-critic/gists{/gist_id}","starred_url":"https://api.github.com/users/go-critic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/go-critic/subscriptions","organizations_url":"https://api.github.com/users/go-critic/orgs","repos_url":"https://api.github.com/users/go-critic/repos","events_url":"https://api.github.com/users/go-critic/events{/privacy}","received_events_url":"https://api.github.com/users/go-critic/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/go-critic/go-critic","description":"The most opinionated Go source code linter","fork":false,"url":"https://api.github.com/repos/go-critic/go-critic","forks_url":"https://api.github.com/repos/go-critic/go-critic/forks","keys_url":"https://api.github.com/repos/go-critic/go-critic/keys{/key_id}","collaborators_url":"https://api.github.com/repos/go-critic/go-critic/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/go-critic/go-critic/teams","hooks_url":"https://api.github.com/repos/go-critic/go-critic/hooks","issue_events_url":"https://api.github.com/repos/go-critic/go-critic/issues/events{/number}","events_url":"https://api.github.com/repos/go-critic/go-critic/events","assignees_url":"https://api.github.com/repos/go-critic/go-critic/assignees{/user}","branches_url":"https://api.github.com/repos/go-critic/go-critic/branches{/branch}","tags_url":"https://api.github.com/repos/go-critic/go-critic/tags","blobs_url":"https://api.github.com/repos/go-critic/go-critic/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/go-critic/go-critic/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/go-critic/go-critic/git/refs{/sha}","trees_url":"https://api.github.com/repos/go-critic/go-critic/git/trees{/sha}","statuses_url":"https://api.github.com/repos/go-critic/go-critic/statuses/{sha}","languages_url":"https://api.github.com/repos/go-critic/go-critic/languages","stargazers_url":"https://api.github.com/repos/go-critic/go-critic/stargazers","contributors_url":"https://api.github.com/repos/go-critic/go-critic/contributors","subscribers_url":"https://api.github.com/repos/go-critic/go-critic/subscribers","subscription_url":"https://api.github.com/repos/go-critic/go-critic/subscription","commits_url":"https://api.github.com/repos/go-critic/go-critic/commits{/sha}","git_commits_url":"https://api.github.com/repos/go-critic/go-critic/git/commits{/sha}","comments_url":"https://api.github.com/repos/go-critic/go-critic/comments{/number}","issue_comment_url":"https://api.github.com/repos/go-critic/go-critic/issues/comments{/number}","contents_url":"https://api.github.com/repos/go-critic/go-critic/contents/{+path}","compare_url":"https://api.github.com/repos/go-critic/go-critic/compare/{base}...{head}","merges_url":"https://api.github.com/repos/go-critic/go-critic/merges","archive_url":"https://api.github.com/repos/go-critic/go-critic/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/go-critic/go-critic/downloads","issues_url":"https://api.github.com/repos/go-critic/go-critic/issues{/number}","pulls_url":"https://api.github.com/repos/go-critic/go-critic/pulls{/number}","milestones_url":"https://api.github.com/repos/go-critic/go-critic/milestones{/number}","notifications_url":"https://api.github.com/repos/go-critic/go-critic/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/go-critic/go-critic/labels{/name}","releases_url":"https://api.github.com/repos/go-critic/go-critic/releases{/id}","deployments_url":"https://api.github.com/repos/go-critic/go-critic/deployments","created_at":"2018-05-05T09:17:26Z","updated_at":"2018-06-16T17:38:58Z","pushed_at":"2018-06-16T18:40:16Z","git_url":"git://github.com/go-critic/go-critic.git","ssh_url":"git@github.com:go-critic/go-critic.git","clone_url":"https://github.com/go-critic/go-critic.git","svn_url":"https://github.com/go-critic/go-critic","homepage":"","size":2234,"stargazers_count":11,"watchers_count":11,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"archived":false,"open_issues_count":35,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":1,"open_issues":35,"watchers":11,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/go-critic/go-critic/pulls/236"},"html":{"href":"https://github.com/go-critic/go-critic/pull/236"},"issue":{"href":"https://api.github.com/repos/go-critic/go-critic/issues/236"},"comments":{"href":"https://api.github.com/repos/go-critic/go-critic/issues/236/comments"},"review_comments":{"href":"https://api.github.com/repos/go-critic/go-critic/pulls/236/comments"},"review_comment":{"href":"https://api.github.com/repos/go-critic/go-critic/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/go-critic/go-critic/pulls/236/commits"},"statuses":{"href":"https://api.github.com/repos/go-critic/go-critic/statuses/98ae3424410d5533e221f4b7e456af4d0bab1cb4"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"Quasilyte"}}