{"action":"created","comment":{"url":"https://api.github.com/repos/alexeykudinkin/intellij-rust/pulls/comments/44813390","id":44813390,"diff_hunk":"@@ -0,0 +1,72 @@\n+package org.rust.lang.inspections\n+\n+import com.intellij.codeInspection.LocalInspectionTool\n+import com.intellij.codeInspection.ProblemsHolder\n+import com.intellij.psi.PsiElement\n+import com.intellij.psi.PsiElementVisitor\n+import org.rust.lang.core.psi.RustImplMethod\n+import org.rust.lang.core.psi.RustVisitor\n+\n+class SelfConventionInspection : LocalInspectionTool() {\n+\n+    override fun getGroupDisplayName() = \"Rust\"\n+    override fun getDisplayName() = \"Self Convention\"\n+\n+    override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor {\n+        return object : RustVisitor() {\n+            override fun visitImplMethod(o: RustImplMethod) {\n+                val convention = SELF_CONVENTIONS.find { o.identifier.text.startsWith(it.prefix) } ?: return\n+                val selfType = SelfType.from(o.and, o.mut, o.self)\n+                if (selfType !in convention.selfTypes) {\n+                    holder.registerProblem(o.self ?: o.identifier, convention)\n+                }\n+            }\n+        }\n+    }\n+\n+    companion object {\n+        val SELF_CONVENTIONS = listOf(\n+            SelfConvention(\"as_\", listOf(SelfType.REF_SELF, SelfType.REF_MUT_SELF)),\n+            SelfConvention(\"from_\", listOf(SelfType.NO_SELF)),\n+            SelfConvention(\"into_\", listOf(SelfType.SELF)),\n+            SelfConvention(\"is_\", listOf(SelfType.REF_SELF, SelfType.NO_SELF)),\n+            SelfConvention(\"to_\", listOf(SelfType.REF_SELF))\n+        )\n+    }\n+}\n+\n+enum class SelfType {\n+    NO_SELF,\n+    SELF,\n+    REF_SELF,\n+    REF_MUT_SELF;\n+\n+    val description: String\n+        get() = when (this) {\n+            NO_SELF      -> \"no self\"\n+            SELF         -> \"self by value\"\n+            REF_SELF     -> \"self by reference\"\n+            REF_MUT_SELF -> \"self by mutable reference\"\n+        }","path":"src/org/rust/lang/inspections/SelfConventionInspection.kt","position":50,"original_position":50,"commit_id":"076f00e8f9c56a391524d99115d9de7c4c100ade","original_commit_id":"076f00e8f9c56a391524d99115d9de7c4c100ade","user":{"login":"Turbo87","id":141300,"avatar_url":"https://avatars.githubusercontent.com/u/141300?v=3","gravatar_id":"","url":"https://api.github.com/users/Turbo87","html_url":"https://github.com/Turbo87","followers_url":"https://api.github.com/users/Turbo87/followers","following_url":"https://api.github.com/users/Turbo87/following{/other_user}","gists_url":"https://api.github.com/users/Turbo87/gists{/gist_id}","starred_url":"https://api.github.com/users/Turbo87/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Turbo87/subscriptions","organizations_url":"https://api.github.com/users/Turbo87/orgs","repos_url":"https://api.github.com/users/Turbo87/repos","events_url":"https://api.github.com/users/Turbo87/events{/privacy}","received_events_url":"https://api.github.com/users/Turbo87/received_events","type":"User","site_admin":false},"body":"ah yes, good idea. still getting used to Kotlin :wink: ","created_at":"2015-11-13T18:05:30Z","updated_at":"2015-11-13T18:05:30Z","html_url":"https://github.com/alexeykudinkin/intellij-rust/pull/129#discussion_r44813390","pull_request_url":"https://api.github.com/repos/alexeykudinkin/intellij-rust/pulls/129","_links":{"self":{"href":"https://api.github.com/repos/alexeykudinkin/intellij-rust/pulls/comments/44813390"},"html":{"href":"https://github.com/alexeykudinkin/intellij-rust/pull/129#discussion_r44813390"},"pull_request":{"href":"https://api.github.com/repos/alexeykudinkin/intellij-rust/pulls/129"}}},"pull_request":{"url":"https://api.github.com/repos/alexeykudinkin/intellij-rust/pulls/129","id":50660044,"html_url":"https://github.com/alexeykudinkin/intellij-rust/pull/129","diff_url":"https://github.com/alexeykudinkin/intellij-rust/pull/129.diff","patch_url":"https://github.com/alexeykudinkin/intellij-rust/pull/129.patch","issue_url":"https://api.github.com/repos/alexeykudinkin/intellij-rust/issues/129","number":129,"state":"open","locked":false,"title":"Inspections: Add \"Self Convention\" inspection","user":{"login":"Turbo87","id":141300,"avatar_url":"https://avatars.githubusercontent.com/u/141300?v=3","gravatar_id":"","url":"https://api.github.com/users/Turbo87","html_url":"https://github.com/Turbo87","followers_url":"https://api.github.com/users/Turbo87/followers","following_url":"https://api.github.com/users/Turbo87/following{/other_user}","gists_url":"https://api.github.com/users/Turbo87/gists{/gist_id}","starred_url":"https://api.github.com/users/Turbo87/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Turbo87/subscriptions","organizations_url":"https://api.github.com/users/Turbo87/orgs","repos_url":"https://api.github.com/users/Turbo87/repos","events_url":"https://api.github.com/users/Turbo87/events{/privacy}","received_events_url":"https://api.github.com/users/Turbo87/received_events","type":"User","site_admin":false},"body":"inspired by https://github.com/Manishearth/rust-clippy/wiki#wrong_self_convention","created_at":"2015-11-13T16:22:32Z","updated_at":"2015-11-13T18:05:30Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2de779a11cea25c10893e63c4712e3bb3d8fca60","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/alexeykudinkin/intellij-rust/pulls/129/commits","review_comments_url":"https://api.github.com/repos/alexeykudinkin/intellij-rust/pulls/129/comments","review_comment_url":"https://api.github.com/repos/alexeykudinkin/intellij-rust/pulls/comments{/number}","comments_url":"https://api.github.com/repos/alexeykudinkin/intellij-rust/issues/129/comments","statuses_url":"https://api.github.com/repos/alexeykudinkin/intellij-rust/statuses/076f00e8f9c56a391524d99115d9de7c4c100ade","head":{"label":"Turbo87:self-inspection","ref":"self-inspection","sha":"076f00e8f9c56a391524d99115d9de7c4c100ade","user":{"login":"Turbo87","id":141300,"avatar_url":"https://avatars.githubusercontent.com/u/141300?v=3","gravatar_id":"","url":"https://api.github.com/users/Turbo87","html_url":"https://github.com/Turbo87","followers_url":"https://api.github.com/users/Turbo87/followers","following_url":"https://api.github.com/users/Turbo87/following{/other_user}","gists_url":"https://api.github.com/users/Turbo87/gists{/gist_id}","starred_url":"https://api.github.com/users/Turbo87/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Turbo87/subscriptions","organizations_url":"https://api.github.com/users/Turbo87/orgs","repos_url":"https://api.github.com/users/Turbo87/repos","events_url":"https://api.github.com/users/Turbo87/events{/privacy}","received_events_url":"https://api.github.com/users/Turbo87/received_events","type":"User","site_admin":false},"repo":{"id":45285649,"name":"intellij-rust","full_name":"Turbo87/intellij-rust","owner":{"login":"Turbo87","id":141300,"avatar_url":"https://avatars.githubusercontent.com/u/141300?v=3","gravatar_id":"","url":"https://api.github.com/users/Turbo87","html_url":"https://github.com/Turbo87","followers_url":"https://api.github.com/users/Turbo87/followers","following_url":"https://api.github.com/users/Turbo87/following{/other_user}","gists_url":"https://api.github.com/users/Turbo87/gists{/gist_id}","starred_url":"https://api.github.com/users/Turbo87/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Turbo87/subscriptions","organizations_url":"https://api.github.com/users/Turbo87/orgs","repos_url":"https://api.github.com/users/Turbo87/repos","events_url":"https://api.github.com/users/Turbo87/events{/privacy}","received_events_url":"https://api.github.com/users/Turbo87/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Turbo87/intellij-rust","description":"Rust IDE built using the IntelliJ Platform","fork":true,"url":"https://api.github.com/repos/Turbo87/intellij-rust","forks_url":"https://api.github.com/repos/Turbo87/intellij-rust/forks","keys_url":"https://api.github.com/repos/Turbo87/intellij-rust/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Turbo87/intellij-rust/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Turbo87/intellij-rust/teams","hooks_url":"https://api.github.com/repos/Turbo87/intellij-rust/hooks","issue_events_url":"https://api.github.com/repos/Turbo87/intellij-rust/issues/events{/number}","events_url":"https://api.github.com/repos/Turbo87/intellij-rust/events","assignees_url":"https://api.github.com/repos/Turbo87/intellij-rust/assignees{/user}","branches_url":"https://api.github.com/repos/Turbo87/intellij-rust/branches{/branch}","tags_url":"https://api.github.com/repos/Turbo87/intellij-rust/tags","blobs_url":"https://api.github.com/repos/Turbo87/intellij-rust/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Turbo87/intellij-rust/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Turbo87/intellij-rust/git/refs{/sha}","trees_url":"https://api.github.com/repos/Turbo87/intellij-rust/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Turbo87/intellij-rust/statuses/{sha}","languages_url":"https://api.github.com/repos/Turbo87/intellij-rust/languages","stargazers_url":"https://api.github.com/repos/Turbo87/intellij-rust/stargazers","contributors_url":"https://api.github.com/repos/Turbo87/intellij-rust/contributors","subscribers_url":"https://api.github.com/repos/Turbo87/intellij-rust/subscribers","subscription_url":"https://api.github.com/repos/Turbo87/intellij-rust/subscription","commits_url":"https://api.github.com/repos/Turbo87/intellij-rust/commits{/sha}","git_commits_url":"https://api.github.com/repos/Turbo87/intellij-rust/git/commits{/sha}","comments_url":"https://api.github.com/repos/Turbo87/intellij-rust/comments{/number}","issue_comment_url":"https://api.github.com/repos/Turbo87/intellij-rust/issues/comments{/number}","contents_url":"https://api.github.com/repos/Turbo87/intellij-rust/contents/{+path}","compare_url":"https://api.github.com/repos/Turbo87/intellij-rust/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Turbo87/intellij-rust/merges","archive_url":"https://api.github.com/repos/Turbo87/intellij-rust/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Turbo87/intellij-rust/downloads","issues_url":"https://api.github.com/repos/Turbo87/intellij-rust/issues{/number}","pulls_url":"https://api.github.com/repos/Turbo87/intellij-rust/pulls{/number}","milestones_url":"https://api.github.com/repos/Turbo87/intellij-rust/milestones{/number}","notifications_url":"https://api.github.com/repos/Turbo87/intellij-rust/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Turbo87/intellij-rust/labels{/name}","releases_url":"https://api.github.com/repos/Turbo87/intellij-rust/releases{/id}","created_at":"2015-10-31T02:18:58Z","updated_at":"2015-10-31T02:18:59Z","pushed_at":"2015-11-13T16:36:34Z","git_url":"git://github.com/Turbo87/intellij-rust.git","ssh_url":"git@github.com:Turbo87/intellij-rust.git","clone_url":"https://github.com/Turbo87/intellij-rust.git","svn_url":"https://github.com/Turbo87/intellij-rust","homepage":null,"size":4843,"stargazers_count":0,"watchers_count":0,"language":"Kotlin","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"alexeykudinkin:master","ref":"master","sha":"e0a6fc0e17872468f60d7035d310f37d45230709","user":{"login":"alexeykudinkin","id":428277,"avatar_url":"https://avatars.githubusercontent.com/u/428277?v=3","gravatar_id":"","url":"https://api.github.com/users/alexeykudinkin","html_url":"https://github.com/alexeykudinkin","followers_url":"https://api.github.com/users/alexeykudinkin/followers","following_url":"https://api.github.com/users/alexeykudinkin/following{/other_user}","gists_url":"https://api.github.com/users/alexeykudinkin/gists{/gist_id}","starred_url":"https://api.github.com/users/alexeykudinkin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexeykudinkin/subscriptions","organizations_url":"https://api.github.com/users/alexeykudinkin/orgs","repos_url":"https://api.github.com/users/alexeykudinkin/repos","events_url":"https://api.github.com/users/alexeykudinkin/events{/privacy}","received_events_url":"https://api.github.com/users/alexeykudinkin/received_events","type":"User","site_admin":false},"repo":{"id":42619487,"name":"intellij-rust","full_name":"alexeykudinkin/intellij-rust","owner":{"login":"alexeykudinkin","id":428277,"avatar_url":"https://avatars.githubusercontent.com/u/428277?v=3","gravatar_id":"","url":"https://api.github.com/users/alexeykudinkin","html_url":"https://github.com/alexeykudinkin","followers_url":"https://api.github.com/users/alexeykudinkin/followers","following_url":"https://api.github.com/users/alexeykudinkin/following{/other_user}","gists_url":"https://api.github.com/users/alexeykudinkin/gists{/gist_id}","starred_url":"https://api.github.com/users/alexeykudinkin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexeykudinkin/subscriptions","organizations_url":"https://api.github.com/users/alexeykudinkin/orgs","repos_url":"https://api.github.com/users/alexeykudinkin/repos","events_url":"https://api.github.com/users/alexeykudinkin/events{/privacy}","received_events_url":"https://api.github.com/users/alexeykudinkin/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/alexeykudinkin/intellij-rust","description":"Rust IDE built using the IntelliJ Platform","fork":false,"url":"https://api.github.com/repos/alexeykudinkin/intellij-rust","forks_url":"https://api.github.com/repos/alexeykudinkin/intellij-rust/forks","keys_url":"https://api.github.com/repos/alexeykudinkin/intellij-rust/keys{/key_id}","collaborators_url":"https://api.github.com/repos/alexeykudinkin/intellij-rust/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/alexeykudinkin/intellij-rust/teams","hooks_url":"https://api.github.com/repos/alexeykudinkin/intellij-rust/hooks","issue_events_url":"https://api.github.com/repos/alexeykudinkin/intellij-rust/issues/events{/number}","events_url":"https://api.github.com/repos/alexeykudinkin/intellij-rust/events","assignees_url":"https://api.github.com/repos/alexeykudinkin/intellij-rust/assignees{/user}","branches_url":"https://api.github.com/repos/alexeykudinkin/intellij-rust/branches{/branch}","tags_url":"https://api.github.com/repos/alexeykudinkin/intellij-rust/tags","blobs_url":"https://api.github.com/repos/alexeykudinkin/intellij-rust/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/alexeykudinkin/intellij-rust/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/alexeykudinkin/intellij-rust/git/refs{/sha}","trees_url":"https://api.github.com/repos/alexeykudinkin/intellij-rust/git/trees{/sha}","statuses_url":"https://api.github.com/repos/alexeykudinkin/intellij-rust/statuses/{sha}","languages_url":"https://api.github.com/repos/alexeykudinkin/intellij-rust/languages","stargazers_url":"https://api.github.com/repos/alexeykudinkin/intellij-rust/stargazers","contributors_url":"https://api.github.com/repos/alexeykudinkin/intellij-rust/contributors","subscribers_url":"https://api.github.com/repos/alexeykudinkin/intellij-rust/subscribers","subscription_url":"https://api.github.com/repos/alexeykudinkin/intellij-rust/subscription","commits_url":"https://api.github.com/repos/alexeykudinkin/intellij-rust/commits{/sha}","git_commits_url":"https://api.github.com/repos/alexeykudinkin/intellij-rust/git/commits{/sha}","comments_url":"https://api.github.com/repos/alexeykudinkin/intellij-rust/comments{/number}","issue_comment_url":"https://api.github.com/repos/alexeykudinkin/intellij-rust/issues/comments{/number}","contents_url":"https://api.github.com/repos/alexeykudinkin/intellij-rust/contents/{+path}","compare_url":"https://api.github.com/repos/alexeykudinkin/intellij-rust/compare/{base}...{head}","merges_url":"https://api.github.com/repos/alexeykudinkin/intellij-rust/merges","archive_url":"https://api.github.com/repos/alexeykudinkin/intellij-rust/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/alexeykudinkin/intellij-rust/downloads","issues_url":"https://api.github.com/repos/alexeykudinkin/intellij-rust/issues{/number}","pulls_url":"https://api.github.com/repos/alexeykudinkin/intellij-rust/pulls{/number}","milestones_url":"https://api.github.com/repos/alexeykudinkin/intellij-rust/milestones{/number}","notifications_url":"https://api.github.com/repos/alexeykudinkin/intellij-rust/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/alexeykudinkin/intellij-rust/labels{/name}","releases_url":"https://api.github.com/repos/alexeykudinkin/intellij-rust/releases{/id}","created_at":"2015-09-16T23:44:57Z","updated_at":"2015-11-13T07:03:32Z","pushed_at":"2015-11-13T17:40:30Z","git_url":"git://github.com/alexeykudinkin/intellij-rust.git","ssh_url":"git@github.com:alexeykudinkin/intellij-rust.git","clone_url":"https://github.com/alexeykudinkin/intellij-rust.git","svn_url":"https://github.com/alexeykudinkin/intellij-rust","homepage":null,"size":6115,"stargazers_count":113,"watchers_count":113,"language":"Kotlin","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":8,"mirror_url":null,"open_issues_count":16,"forks":8,"open_issues":16,"watchers":113,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/alexeykudinkin/intellij-rust/pulls/129"},"html":{"href":"https://github.com/alexeykudinkin/intellij-rust/pull/129"},"issue":{"href":"https://api.github.com/repos/alexeykudinkin/intellij-rust/issues/129"},"comments":{"href":"https://api.github.com/repos/alexeykudinkin/intellij-rust/issues/129/comments"},"review_comments":{"href":"https://api.github.com/repos/alexeykudinkin/intellij-rust/pulls/129/comments"},"review_comment":{"href":"https://api.github.com/repos/alexeykudinkin/intellij-rust/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/alexeykudinkin/intellij-rust/pulls/129/commits"},"statuses":{"href":"https://api.github.com/repos/alexeykudinkin/intellij-rust/statuses/076f00e8f9c56a391524d99115d9de7c4c100ade"}}}}