{"action":"created","comment":{"url":"https://api.github.com/repos/JetBrains/kotlin/pulls/comments/193064178","pull_request_review_id":125959402,"id":193064178,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDE5MzA2NDE3OA==","diff_hunk":"@@ -10,39 +10,54 @@ import com.intellij.codeInspection.ProblemDescriptor\n import com.intellij.codeInspection.ProblemHighlightType\n import com.intellij.codeInspection.ProblemsHolder\n import com.intellij.openapi.project.Project\n-import com.intellij.openapi.util.TextRange\n import com.intellij.psi.PsiElementVisitor\n import org.jetbrains.kotlin.builtins.KotlinBuiltIns\n import org.jetbrains.kotlin.descriptors.FunctionDescriptor\n import org.jetbrains.kotlin.idea.MainFunctionDetector\n+import org.jetbrains.kotlin.idea.caches.resolve.analyze\n import org.jetbrains.kotlin.idea.core.setType\n import org.jetbrains.kotlin.idea.search.usagesSearch.descriptor\n+import org.jetbrains.kotlin.name.FqName\n+import org.jetbrains.kotlin.psi.KtAnnotationEntry\n import org.jetbrains.kotlin.psi.KtNamedFunction\n import org.jetbrains.kotlin.psi.namedFunctionVisitor\n-import org.jetbrains.kotlin.psi.psiUtil.endOffset\n import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType\n-import org.jetbrains.kotlin.psi.psiUtil.getParentOfType\n-import org.jetbrains.kotlin.psi.psiUtil.startOffset\n+import org.jetbrains.kotlin.resolve.BindingContext\n+import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe\n+import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode\n \n class MainFunctionReturnUnitInspection : AbstractKotlinInspection() {\n     override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor {\n         return namedFunctionVisitor(fun(function: KtNamedFunction) {\n-            if (function.name != \"main\") return\n+            val isMain = function.name == \"main\"\n+            val testAnnotations = function.annotationEntries.filter { \"Test\" in it.text }\n+            if (!isMain && testAnnotations.isEmpty()) return\n \n             val descriptor = function.descriptor as? FunctionDescriptor ?: return\n-            if (!MainFunctionDetector.isMain(descriptor, checkReturnType = false)) return\n-            if (MainFunctionDetector.isMainReturnType(descriptor)) return\n+            if (isMain) {\n+                if (!MainFunctionDetector.isMain(descriptor, checkReturnType = false)) return\n+            } else {\n+                val junitTestFqNames = listOf(FqName(\"org.junit.Test\"), FqName(\"org.junit.jupiter.api.Test\"))\n+                if (testAnnotations.none { it.fqName() in junitTestFqNames }) return\n+            }\n+            if (descriptor.returnType?.let { KotlinBuiltIns.isUnit(it) } == true) return\n \n             holder.registerProblem(\n                 function.nameIdentifier ?: function,\n-                \"main should return Unit\",\n+                \"${if (isMain) \"main\" else \"test\"} should return Unit\",","path":"idea/src/org/jetbrains/kotlin/idea/inspections/MainFunctionReturnUnitInspection.kt","position":46,"original_position":46,"commit_id":"77841cd64687c9cf62a5b4b7ca8c3b07a03fc5f1","original_commit_id":"77841cd64687c9cf62a5b4b7ca8c3b07a03fc5f1","user":{"login":"mglukhikh","id":1127631,"node_id":"MDQ6VXNlcjExMjc2MzE=","avatar_url":"https://avatars2.githubusercontent.com/u/1127631?v=4","gravatar_id":"","url":"https://api.github.com/users/mglukhikh","html_url":"https://github.com/mglukhikh","followers_url":"https://api.github.com/users/mglukhikh/followers","following_url":"https://api.github.com/users/mglukhikh/following{/other_user}","gists_url":"https://api.github.com/users/mglukhikh/gists{/gist_id}","starred_url":"https://api.github.com/users/mglukhikh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mglukhikh/subscriptions","organizations_url":"https://api.github.com/users/mglukhikh/orgs","repos_url":"https://api.github.com/users/mglukhikh/repos","events_url":"https://api.github.com/users/mglukhikh/events{/privacy}","received_events_url":"https://api.github.com/users/mglukhikh/received_events","type":"User","site_admin":false},"body":"I'd suggest to report \"JUnit test should return Unit\" or \"Test function should return Unit\" or something like. \"test should return Unit\" looks not very pretty","created_at":"2018-06-05T13:07:58Z","updated_at":"2018-06-05T13:10:14Z","html_url":"https://github.com/JetBrains/kotlin/pull/1696#discussion_r193064178","pull_request_url":"https://api.github.com/repos/JetBrains/kotlin/pulls/1696","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/JetBrains/kotlin/pulls/comments/193064178"},"html":{"href":"https://github.com/JetBrains/kotlin/pull/1696#discussion_r193064178"},"pull_request":{"href":"https://api.github.com/repos/JetBrains/kotlin/pulls/1696"}}},"pull_request":{"url":"https://api.github.com/repos/JetBrains/kotlin/pulls/1696","id":191903850,"node_id":"MDExOlB1bGxSZXF1ZXN0MTkxOTAzODUw","html_url":"https://github.com/JetBrains/kotlin/pull/1696","diff_url":"https://github.com/JetBrains/kotlin/pull/1696.diff","patch_url":"https://github.com/JetBrains/kotlin/pull/1696.patch","issue_url":"https://api.github.com/repos/JetBrains/kotlin/issues/1696","number":1696,"state":"open","locked":false,"title":"KT-24509 Inspection \"JUnit tests should return Unit\"","user":{"login":"t-kameyama","id":1121855,"node_id":"MDQ6VXNlcjExMjE4NTU=","avatar_url":"https://avatars1.githubusercontent.com/u/1121855?v=4","gravatar_id":"","url":"https://api.github.com/users/t-kameyama","html_url":"https://github.com/t-kameyama","followers_url":"https://api.github.com/users/t-kameyama/followers","following_url":"https://api.github.com/users/t-kameyama/following{/other_user}","gists_url":"https://api.github.com/users/t-kameyama/gists{/gist_id}","starred_url":"https://api.github.com/users/t-kameyama/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/t-kameyama/subscriptions","organizations_url":"https://api.github.com/users/t-kameyama/orgs","repos_url":"https://api.github.com/users/t-kameyama/repos","events_url":"https://api.github.com/users/t-kameyama/events{/privacy}","received_events_url":"https://api.github.com/users/t-kameyama/received_events","type":"User","site_admin":false},"body":"https://youtrack.jetbrains.com/issue/KT-24509","created_at":"2018-06-01T00:04:58Z","updated_at":"2018-06-05T13:10:14Z","closed_at":null,"merged_at":null,"merge_commit_sha":"adc0fe4ab08981edc36080bce162cf81cbf2de71","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/JetBrains/kotlin/pulls/1696/commits","review_comments_url":"https://api.github.com/repos/JetBrains/kotlin/pulls/1696/comments","review_comment_url":"https://api.github.com/repos/JetBrains/kotlin/pulls/comments{/number}","comments_url":"https://api.github.com/repos/JetBrains/kotlin/issues/1696/comments","statuses_url":"https://api.github.com/repos/JetBrains/kotlin/statuses/77841cd64687c9cf62a5b4b7ca8c3b07a03fc5f1","head":{"label":"t-kameyama:KT-24509","ref":"KT-24509","sha":"77841cd64687c9cf62a5b4b7ca8c3b07a03fc5f1","user":{"login":"t-kameyama","id":1121855,"node_id":"MDQ6VXNlcjExMjE4NTU=","avatar_url":"https://avatars1.githubusercontent.com/u/1121855?v=4","gravatar_id":"","url":"https://api.github.com/users/t-kameyama","html_url":"https://github.com/t-kameyama","followers_url":"https://api.github.com/users/t-kameyama/followers","following_url":"https://api.github.com/users/t-kameyama/following{/other_user}","gists_url":"https://api.github.com/users/t-kameyama/gists{/gist_id}","starred_url":"https://api.github.com/users/t-kameyama/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/t-kameyama/subscriptions","organizations_url":"https://api.github.com/users/t-kameyama/orgs","repos_url":"https://api.github.com/users/t-kameyama/repos","events_url":"https://api.github.com/users/t-kameyama/events{/privacy}","received_events_url":"https://api.github.com/users/t-kameyama/received_events","type":"User","site_admin":false},"repo":{"id":93002825,"node_id":"MDEwOlJlcG9zaXRvcnk5MzAwMjgyNQ==","name":"kotlin","full_name":"t-kameyama/kotlin","owner":{"login":"t-kameyama","id":1121855,"node_id":"MDQ6VXNlcjExMjE4NTU=","avatar_url":"https://avatars1.githubusercontent.com/u/1121855?v=4","gravatar_id":"","url":"https://api.github.com/users/t-kameyama","html_url":"https://github.com/t-kameyama","followers_url":"https://api.github.com/users/t-kameyama/followers","following_url":"https://api.github.com/users/t-kameyama/following{/other_user}","gists_url":"https://api.github.com/users/t-kameyama/gists{/gist_id}","starred_url":"https://api.github.com/users/t-kameyama/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/t-kameyama/subscriptions","organizations_url":"https://api.github.com/users/t-kameyama/orgs","repos_url":"https://api.github.com/users/t-kameyama/repos","events_url":"https://api.github.com/users/t-kameyama/events{/privacy}","received_events_url":"https://api.github.com/users/t-kameyama/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/t-kameyama/kotlin","description":"The Kotlin Programming Language","fork":true,"url":"https://api.github.com/repos/t-kameyama/kotlin","forks_url":"https://api.github.com/repos/t-kameyama/kotlin/forks","keys_url":"https://api.github.com/repos/t-kameyama/kotlin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/t-kameyama/kotlin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/t-kameyama/kotlin/teams","hooks_url":"https://api.github.com/repos/t-kameyama/kotlin/hooks","issue_events_url":"https://api.github.com/repos/t-kameyama/kotlin/issues/events{/number}","events_url":"https://api.github.com/repos/t-kameyama/kotlin/events","assignees_url":"https://api.github.com/repos/t-kameyama/kotlin/assignees{/user}","branches_url":"https://api.github.com/repos/t-kameyama/kotlin/branches{/branch}","tags_url":"https://api.github.com/repos/t-kameyama/kotlin/tags","blobs_url":"https://api.github.com/repos/t-kameyama/kotlin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/t-kameyama/kotlin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/t-kameyama/kotlin/git/refs{/sha}","trees_url":"https://api.github.com/repos/t-kameyama/kotlin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/t-kameyama/kotlin/statuses/{sha}","languages_url":"https://api.github.com/repos/t-kameyama/kotlin/languages","stargazers_url":"https://api.github.com/repos/t-kameyama/kotlin/stargazers","contributors_url":"https://api.github.com/repos/t-kameyama/kotlin/contributors","subscribers_url":"https://api.github.com/repos/t-kameyama/kotlin/subscribers","subscription_url":"https://api.github.com/repos/t-kameyama/kotlin/subscription","commits_url":"https://api.github.com/repos/t-kameyama/kotlin/commits{/sha}","git_commits_url":"https://api.github.com/repos/t-kameyama/kotlin/git/commits{/sha}","comments_url":"https://api.github.com/repos/t-kameyama/kotlin/comments{/number}","issue_comment_url":"https://api.github.com/repos/t-kameyama/kotlin/issues/comments{/number}","contents_url":"https://api.github.com/repos/t-kameyama/kotlin/contents/{+path}","compare_url":"https://api.github.com/repos/t-kameyama/kotlin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/t-kameyama/kotlin/merges","archive_url":"https://api.github.com/repos/t-kameyama/kotlin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/t-kameyama/kotlin/downloads","issues_url":"https://api.github.com/repos/t-kameyama/kotlin/issues{/number}","pulls_url":"https://api.github.com/repos/t-kameyama/kotlin/pulls{/number}","milestones_url":"https://api.github.com/repos/t-kameyama/kotlin/milestones{/number}","notifications_url":"https://api.github.com/repos/t-kameyama/kotlin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/t-kameyama/kotlin/labels{/name}","releases_url":"https://api.github.com/repos/t-kameyama/kotlin/releases{/id}","deployments_url":"https://api.github.com/repos/t-kameyama/kotlin/deployments","created_at":"2017-06-01T01:12:25Z","updated_at":"2018-06-04T23:52:27Z","pushed_at":"2018-06-05T00:24:13Z","git_url":"git://github.com/t-kameyama/kotlin.git","ssh_url":"git@github.com:t-kameyama/kotlin.git","clone_url":"https://github.com/t-kameyama/kotlin.git","svn_url":"https://github.com/t-kameyama/kotlin","homepage":"http://kotlinlang.org/","size":416422,"stargazers_count":0,"watchers_count":0,"language":"Kotlin","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1,"mirror_url":null,"archived":false,"open_issues_count":0,"license":null,"forks":1,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"JetBrains:master","ref":"master","sha":"fbb4914bfb6830d61ee76a6136effbdfcca4fe24","user":{"login":"JetBrains","id":878437,"node_id":"MDEyOk9yZ2FuaXphdGlvbjg3ODQzNw==","avatar_url":"https://avatars2.githubusercontent.com/u/878437?v=4","gravatar_id":"","url":"https://api.github.com/users/JetBrains","html_url":"https://github.com/JetBrains","followers_url":"https://api.github.com/users/JetBrains/followers","following_url":"https://api.github.com/users/JetBrains/following{/other_user}","gists_url":"https://api.github.com/users/JetBrains/gists{/gist_id}","starred_url":"https://api.github.com/users/JetBrains/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JetBrains/subscriptions","organizations_url":"https://api.github.com/users/JetBrains/orgs","repos_url":"https://api.github.com/users/JetBrains/repos","events_url":"https://api.github.com/users/JetBrains/events{/privacy}","received_events_url":"https://api.github.com/users/JetBrains/received_events","type":"Organization","site_admin":false},"repo":{"id":3432266,"node_id":"MDEwOlJlcG9zaXRvcnkzNDMyMjY2","name":"kotlin","full_name":"JetBrains/kotlin","owner":{"login":"JetBrains","id":878437,"node_id":"MDEyOk9yZ2FuaXphdGlvbjg3ODQzNw==","avatar_url":"https://avatars2.githubusercontent.com/u/878437?v=4","gravatar_id":"","url":"https://api.github.com/users/JetBrains","html_url":"https://github.com/JetBrains","followers_url":"https://api.github.com/users/JetBrains/followers","following_url":"https://api.github.com/users/JetBrains/following{/other_user}","gists_url":"https://api.github.com/users/JetBrains/gists{/gist_id}","starred_url":"https://api.github.com/users/JetBrains/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JetBrains/subscriptions","organizations_url":"https://api.github.com/users/JetBrains/orgs","repos_url":"https://api.github.com/users/JetBrains/repos","events_url":"https://api.github.com/users/JetBrains/events{/privacy}","received_events_url":"https://api.github.com/users/JetBrains/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/JetBrains/kotlin","description":"The Kotlin Programming Language","fork":false,"url":"https://api.github.com/repos/JetBrains/kotlin","forks_url":"https://api.github.com/repos/JetBrains/kotlin/forks","keys_url":"https://api.github.com/repos/JetBrains/kotlin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/JetBrains/kotlin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/JetBrains/kotlin/teams","hooks_url":"https://api.github.com/repos/JetBrains/kotlin/hooks","issue_events_url":"https://api.github.com/repos/JetBrains/kotlin/issues/events{/number}","events_url":"https://api.github.com/repos/JetBrains/kotlin/events","assignees_url":"https://api.github.com/repos/JetBrains/kotlin/assignees{/user}","branches_url":"https://api.github.com/repos/JetBrains/kotlin/branches{/branch}","tags_url":"https://api.github.com/repos/JetBrains/kotlin/tags","blobs_url":"https://api.github.com/repos/JetBrains/kotlin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/JetBrains/kotlin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/JetBrains/kotlin/git/refs{/sha}","trees_url":"https://api.github.com/repos/JetBrains/kotlin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/JetBrains/kotlin/statuses/{sha}","languages_url":"https://api.github.com/repos/JetBrains/kotlin/languages","stargazers_url":"https://api.github.com/repos/JetBrains/kotlin/stargazers","contributors_url":"https://api.github.com/repos/JetBrains/kotlin/contributors","subscribers_url":"https://api.github.com/repos/JetBrains/kotlin/subscribers","subscription_url":"https://api.github.com/repos/JetBrains/kotlin/subscription","commits_url":"https://api.github.com/repos/JetBrains/kotlin/commits{/sha}","git_commits_url":"https://api.github.com/repos/JetBrains/kotlin/git/commits{/sha}","comments_url":"https://api.github.com/repos/JetBrains/kotlin/comments{/number}","issue_comment_url":"https://api.github.com/repos/JetBrains/kotlin/issues/comments{/number}","contents_url":"https://api.github.com/repos/JetBrains/kotlin/contents/{+path}","compare_url":"https://api.github.com/repos/JetBrains/kotlin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/JetBrains/kotlin/merges","archive_url":"https://api.github.com/repos/JetBrains/kotlin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/JetBrains/kotlin/downloads","issues_url":"https://api.github.com/repos/JetBrains/kotlin/issues{/number}","pulls_url":"https://api.github.com/repos/JetBrains/kotlin/pulls{/number}","milestones_url":"https://api.github.com/repos/JetBrains/kotlin/milestones{/number}","notifications_url":"https://api.github.com/repos/JetBrains/kotlin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/JetBrains/kotlin/labels{/name}","releases_url":"https://api.github.com/repos/JetBrains/kotlin/releases{/id}","deployments_url":"https://api.github.com/repos/JetBrains/kotlin/deployments","created_at":"2012-02-13T17:29:58Z","updated_at":"2018-06-05T13:04:43Z","pushed_at":"2018-06-05T13:04:14Z","git_url":"git://github.com/JetBrains/kotlin.git","ssh_url":"git@github.com:JetBrains/kotlin.git","clone_url":"https://github.com/JetBrains/kotlin.git","svn_url":"https://github.com/JetBrains/kotlin","homepage":"http://kotlinlang.org/","size":460087,"stargazers_count":22706,"watchers_count":22706,"language":"Kotlin","has_issues":false,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":2555,"mirror_url":null,"archived":false,"open_issues_count":92,"license":null,"forks":2555,"open_issues":92,"watchers":22706,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/JetBrains/kotlin/pulls/1696"},"html":{"href":"https://github.com/JetBrains/kotlin/pull/1696"},"issue":{"href":"https://api.github.com/repos/JetBrains/kotlin/issues/1696"},"comments":{"href":"https://api.github.com/repos/JetBrains/kotlin/issues/1696/comments"},"review_comments":{"href":"https://api.github.com/repos/JetBrains/kotlin/pulls/1696/comments"},"review_comment":{"href":"https://api.github.com/repos/JetBrains/kotlin/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/JetBrains/kotlin/pulls/1696/commits"},"statuses":{"href":"https://api.github.com/repos/JetBrains/kotlin/statuses/77841cd64687c9cf62a5b4b7ca8c3b07a03fc5f1"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"mglukhikh"}}