GitHub PullRequestReviewCommentEvent at 2014-07-02 12:21:03
Repository: scala-abide
Actor: dragos
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/samarion/scala-abide/pulls/comments/14453484","id":14453484,"diff_hunk":"@@ -0,0 +1,52 @@\n+package scala.tools.abide\n+package traversal\n+\n+class UnusedMember(val analyzer: TraversalAnalyzer) extends ExistentialRule {\n+  import analyzer.global._\n+\n+  val name = \"unused-member\"\n+  type Key = analyzer.global.Symbol\n+\n+  case class Warning(tree: Tree) extends RuleWarning {\n+    val pos = tree.pos\n+    val message = s\"${tree.symbol} is not used.\"\n+  }\n+\n+  private def shouldConsider(sym: Symbol): Boolean = {\n+    val owner = sym.owner\n+    val isValueParameter = owner.isMethod && sym.isValueParameter\n+\n+    val ignore = ((isValueParameter && owner.isDeferred) // abstract method, params are never used\n+      || owner.isConstructor // right after typer constructors are empty, so their params are not used\n+      || sym.isSynthetic\n+      || sym.name.containsChar('$') // synthetic names that are not marked as SYNTHETIC: `(_, _) => ???`\n+      || isValueParameter &&\n+        (owner.hasFlag(Flag.OVERRIDE) || owner.overrides.nonEmpty)) // overriding a method needs to keep all (unused) parameters\n+\n+    def getter(sym: Symbol): Symbol = sym.getter\n+    val privateVal = if (getter(sym) != NoSymbol) getter(sym).isPrivate else sym.isPrivate\n+\n+    !ignore &&\n+      (sym.isLocal ||\n+        (sym.isMethod && sym.isPrivate) ||\n+        ((sym.isVal || sym.isVar) && privateVal))\n+  }\n+\n+  val step = optimize {\n+    case tree @ q\"$mods val $name: $tpt = $rhs\" if shouldConsider(tree.symbol) =>\n+      nok(tree.symbol, Warning(tree))\n+\n+    case tree @ q\"$pre.$name\" =>\n+      ok(tree.symbol)\n+\n+    case tree @ Ident(_) =>\n+      val affectedSymbols =\n+        if (tree.symbol.owner.isConstructor) {\n+          val paramAccessors = tree.symbol.enclClass.constrParamAccessors\n+          paramAccessors.find(tree.symbol.name == _.name).toSeq :+ tree.symbol\n+        } else\n+          Seq(tree.symbol)\n+      affectedSymbols.foldLeft(maintain) { (state, sym) => state and ok(sym) }","path":"abide/src/traversal/UnusedMember.scala","position":49,"original_position":49,"commit_id":"aa95c7f5762ffd98bdac6eb3426af78d48b3ae02","original_commit_id":"aa95c7f5762ffd98bdac6eb3426af78d48b3ae02","user":{"login":"dragos","id":133742,"avatar_url":"https://avatars.githubusercontent.com/u/133742?","gravatar_id":"fbd384e9626d28d1648f023a5e22672f","url":"https://api.github.com/users/dragos","html_url":"https://github.com/dragos","followers_url":"https://api.github.com/users/dragos/followers","following_url":"https://api.github.com/users/dragos/following{/other_user}","gists_url":"https://api.github.com/users/dragos/gists{/gist_id}","starred_url":"https://api.github.com/users/dragos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dragos/subscriptions","organizations_url":"https://api.github.com/users/dragos/orgs","repos_url":"https://api.github.com/users/dragos/repos","events_url":"https://api.github.com/users/dragos/events{/privacy}","received_events_url":"https://api.github.com/users/dragos/received_events","type":"User","site_admin":false},"body":"I'm not thrilled with this way of threading state, it's too easy to do the wrong thing. My first attempt compiled, but ignored everything except the last call to `ok`:\r\n\r\n```\r\nparamAccessors.find(...).foreach(ok)\r\nok(tree.symbol)\r\n```","created_at":"2014-07-02T12:21:03Z","updated_at":"2014-07-02T12:21:03Z","html_url":"https://github.com/samarion/scala-abide/pull/1#discussion_r14453484","pull_request_url":"https://api.github.com/repos/samarion/scala-abide/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/samarion/scala-abide/pulls/comments/14453484"},"html":{"href":"https://github.com/samarion/scala-abide/pull/1#discussion_r14453484"},"pull_request":{"href":"https://api.github.com/repos/samarion/scala-abide/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/samarion/scala-abide/pulls/1","id":17882424,"html_url":"https://github.com/samarion/scala-abide/pull/1","diff_url":"https://github.com/samarion/scala-abide/pull/1.diff","patch_url":"https://github.com/samarion/scala-abide/pull/1.patch","issue_url":"https://api.github.com/repos/samarion/scala-abide/issues/1","number":1,"state":"open","title":"First attempt at finding unused members.","user":{"login":"dragos","id":133742,"avatar_url":"https://avatars.githubusercontent.com/u/133742?","gravatar_id":"fbd384e9626d28d1648f023a5e22672f","url":"https://api.github.com/users/dragos","html_url":"https://github.com/dragos","followers_url":"https://api.github.com/users/dragos/followers","following_url":"https://api.github.com/users/dragos/following{/other_user}","gists_url":"https://api.github.com/users/dragos/gists{/gist_id}","starred_url":"https://api.github.com/users/dragos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dragos/subscriptions","organizations_url":"https://api.github.com/users/dragos/orgs","repos_url":"https://api.github.com/users/dragos/repos","events_url":"https://api.github.com/users/dragos/events{/privacy}","received_events_url":"https://api.github.com/users/dragos/received_events","type":"User","site_admin":false},"body":"This shows the difficulties one has to face when dealing with Scala symbols, in\r\nparticular the fact that one logical entity is represented by multiple symbols. For\r\nexample, a class parameter has a symbol for:\r\n\r\n* a constructor parameter\r\n* a private field to hold that value (might be removed later, but after typer we always have it)\r\n* maybe a getter, if the parameter is public\r\n\r\nA *use* should be marked for any of them. Visibility should be checked on the getter (if there is one).\r\n\r\nThe same happens for vals/vars and their getters. Def-use information is something many rules will need (unused imports, unused members, single-assignment vars, etc) so it’s worthy of a simpler API.","created_at":"2014-07-02T12:19:14Z","updated_at":"2014-07-02T12:21:03Z","closed_at":null,"merged_at":null,"merge_commit_sha":"38285be7cb537b00e52a8122349a3328abb0b9a8","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/samarion/scala-abide/pulls/1/commits","review_comments_url":"https://api.github.com/repos/samarion/scala-abide/pulls/1/comments","review_comment_url":"https://api.github.com/repos/samarion/scala-abide/pulls/comments/{number}","comments_url":"https://api.github.com/repos/samarion/scala-abide/issues/1/comments","statuses_url":"https://api.github.com/repos/samarion/scala-abide/statuses/aa95c7f5762ffd98bdac6eb3426af78d48b3ae02","head":{"label":"dragos:rule/unused-member","ref":"rule/unused-member","sha":"aa95c7f5762ffd98bdac6eb3426af78d48b3ae02","user":{"login":"dragos","id":133742,"avatar_url":"https://avatars.githubusercontent.com/u/133742?","gravatar_id":"fbd384e9626d28d1648f023a5e22672f","url":"https://api.github.com/users/dragos","html_url":"https://github.com/dragos","followers_url":"https://api.github.com/users/dragos/followers","following_url":"https://api.github.com/users/dragos/following{/other_user}","gists_url":"https://api.github.com/users/dragos/gists{/gist_id}","starred_url":"https://api.github.com/users/dragos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dragos/subscriptions","organizations_url":"https://api.github.com/users/dragos/orgs","repos_url":"https://api.github.com/users/dragos/repos","events_url":"https://api.github.com/users/dragos/events{/privacy}","received_events_url":"https://api.github.com/users/dragos/received_events","type":"User","site_admin":false},"repo":{"id":21422378,"name":"scala-abide","full_name":"dragos/scala-abide","owner":{"login":"dragos","id":133742,"avatar_url":"https://avatars.githubusercontent.com/u/133742?","gravatar_id":"fbd384e9626d28d1648f023a5e22672f","url":"https://api.github.com/users/dragos","html_url":"https://github.com/dragos","followers_url":"https://api.github.com/users/dragos/followers","following_url":"https://api.github.com/users/dragos/following{/other_user}","gists_url":"https://api.github.com/users/dragos/gists{/gist_id}","starred_url":"https://api.github.com/users/dragos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dragos/subscriptions","organizations_url":"https://api.github.com/users/dragos/orgs","repos_url":"https://api.github.com/users/dragos/repos","events_url":"https://api.github.com/users/dragos/events{/privacy}","received_events_url":"https://api.github.com/users/dragos/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/dragos/scala-abide","description":"Library for quick scala code checking and validation.","fork":true,"url":"https://api.github.com/repos/dragos/scala-abide","forks_url":"https://api.github.com/repos/dragos/scala-abide/forks","keys_url":"https://api.github.com/repos/dragos/scala-abide/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dragos/scala-abide/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dragos/scala-abide/teams","hooks_url":"https://api.github.com/repos/dragos/scala-abide/hooks","issue_events_url":"https://api.github.com/repos/dragos/scala-abide/issues/events{/number}","events_url":"https://api.github.com/repos/dragos/scala-abide/events","assignees_url":"https://api.github.com/repos/dragos/scala-abide/assignees{/user}","branches_url":"https://api.github.com/repos/dragos/scala-abide/branches{/branch}","tags_url":"https://api.github.com/repos/dragos/scala-abide/tags","blobs_url":"https://api.github.com/repos/dragos/scala-abide/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dragos/scala-abide/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dragos/scala-abide/git/refs{/sha}","trees_url":"https://api.github.com/repos/dragos/scala-abide/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dragos/scala-abide/statuses/{sha}","languages_url":"https://api.github.com/repos/dragos/scala-abide/languages","stargazers_url":"https://api.github.com/repos/dragos/scala-abide/stargazers","contributors_url":"https://api.github.com/repos/dragos/scala-abide/contributors","subscribers_url":"https://api.github.com/repos/dragos/scala-abide/subscribers","subscription_url":"https://api.github.com/repos/dragos/scala-abide/subscription","commits_url":"https://api.github.com/repos/dragos/scala-abide/commits{/sha}","git_commits_url":"https://api.github.com/repos/dragos/scala-abide/git/commits{/sha}","comments_url":"https://api.github.com/repos/dragos/scala-abide/comments{/number}","issue_comment_url":"https://api.github.com/repos/dragos/scala-abide/issues/comments/{number}","contents_url":"https://api.github.com/repos/dragos/scala-abide/contents/{+path}","compare_url":"https://api.github.com/repos/dragos/scala-abide/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dragos/scala-abide/merges","archive_url":"https://api.github.com/repos/dragos/scala-abide/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dragos/scala-abide/downloads","issues_url":"https://api.github.com/repos/dragos/scala-abide/issues{/number}","pulls_url":"https://api.github.com/repos/dragos/scala-abide/pulls{/number}","milestones_url":"https://api.github.com/repos/dragos/scala-abide/milestones{/number}","notifications_url":"https://api.github.com/repos/dragos/scala-abide/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dragos/scala-abide/labels{/name}","releases_url":"https://api.github.com/repos/dragos/scala-abide/releases{/id}","created_at":"2014-07-02T11:56:05Z","updated_at":"2014-07-02T12:16:51Z","pushed_at":"2014-07-02T12:18:46Z","git_url":"git://github.com/dragos/scala-abide.git","ssh_url":"git@github.com:dragos/scala-abide.git","clone_url":"https://github.com/dragos/scala-abide.git","svn_url":"https://github.com/dragos/scala-abide","homepage":null,"size":288,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"samarion:master","ref":"master","sha":"f7db19d5989eab13335c95b0987d24973911b1e3","user":{"login":"samarion","id":3322756,"avatar_url":"https://avatars.githubusercontent.com/u/3322756?","gravatar_id":"8329325d6accd52f595437655a0f5f13","url":"https://api.github.com/users/samarion","html_url":"https://github.com/samarion","followers_url":"https://api.github.com/users/samarion/followers","following_url":"https://api.github.com/users/samarion/following{/other_user}","gists_url":"https://api.github.com/users/samarion/gists{/gist_id}","starred_url":"https://api.github.com/users/samarion/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/samarion/subscriptions","organizations_url":"https://api.github.com/users/samarion/orgs","repos_url":"https://api.github.com/users/samarion/repos","events_url":"https://api.github.com/users/samarion/events{/privacy}","received_events_url":"https://api.github.com/users/samarion/received_events","type":"User","site_admin":false},"repo":{"id":20215392,"name":"scala-abide","full_name":"samarion/scala-abide","owner":{"login":"samarion","id":3322756,"avatar_url":"https://avatars.githubusercontent.com/u/3322756?","gravatar_id":"8329325d6accd52f595437655a0f5f13","url":"https://api.github.com/users/samarion","html_url":"https://github.com/samarion","followers_url":"https://api.github.com/users/samarion/followers","following_url":"https://api.github.com/users/samarion/following{/other_user}","gists_url":"https://api.github.com/users/samarion/gists{/gist_id}","starred_url":"https://api.github.com/users/samarion/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/samarion/subscriptions","organizations_url":"https://api.github.com/users/samarion/orgs","repos_url":"https://api.github.com/users/samarion/repos","events_url":"https://api.github.com/users/samarion/events{/privacy}","received_events_url":"https://api.github.com/users/samarion/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/samarion/scala-abide","description":"Library for quick scala code checking and validation.","fork":false,"url":"https://api.github.com/repos/samarion/scala-abide","forks_url":"https://api.github.com/repos/samarion/scala-abide/forks","keys_url":"https://api.github.com/repos/samarion/scala-abide/keys{/key_id}","collaborators_url":"https://api.github.com/repos/samarion/scala-abide/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/samarion/scala-abide/teams","hooks_url":"https://api.github.com/repos/samarion/scala-abide/hooks","issue_events_url":"https://api.github.com/repos/samarion/scala-abide/issues/events{/number}","events_url":"https://api.github.com/repos/samarion/scala-abide/events","assignees_url":"https://api.github.com/repos/samarion/scala-abide/assignees{/user}","branches_url":"https://api.github.com/repos/samarion/scala-abide/branches{/branch}","tags_url":"https://api.github.com/repos/samarion/scala-abide/tags","blobs_url":"https://api.github.com/repos/samarion/scala-abide/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/samarion/scala-abide/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/samarion/scala-abide/git/refs{/sha}","trees_url":"https://api.github.com/repos/samarion/scala-abide/git/trees{/sha}","statuses_url":"https://api.github.com/repos/samarion/scala-abide/statuses/{sha}","languages_url":"https://api.github.com/repos/samarion/scala-abide/languages","stargazers_url":"https://api.github.com/repos/samarion/scala-abide/stargazers","contributors_url":"https://api.github.com/repos/samarion/scala-abide/contributors","subscribers_url":"https://api.github.com/repos/samarion/scala-abide/subscribers","subscription_url":"https://api.github.com/repos/samarion/scala-abide/subscription","commits_url":"https://api.github.com/repos/samarion/scala-abide/commits{/sha}","git_commits_url":"https://api.github.com/repos/samarion/scala-abide/git/commits{/sha}","comments_url":"https://api.github.com/repos/samarion/scala-abide/comments{/number}","issue_comment_url":"https://api.github.com/repos/samarion/scala-abide/issues/comments/{number}","contents_url":"https://api.github.com/repos/samarion/scala-abide/contents/{+path}","compare_url":"https://api.github.com/repos/samarion/scala-abide/compare/{base}...{head}","merges_url":"https://api.github.com/repos/samarion/scala-abide/merges","archive_url":"https://api.github.com/repos/samarion/scala-abide/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/samarion/scala-abide/downloads","issues_url":"https://api.github.com/repos/samarion/scala-abide/issues{/number}","pulls_url":"https://api.github.com/repos/samarion/scala-abide/pulls{/number}","milestones_url":"https://api.github.com/repos/samarion/scala-abide/milestones{/number}","notifications_url":"https://api.github.com/repos/samarion/scala-abide/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/samarion/scala-abide/labels{/name}","releases_url":"https://api.github.com/repos/samarion/scala-abide/releases{/id}","created_at":"2014-05-27T10:01:07Z","updated_at":"2014-06-25T16:33:29Z","pushed_at":"2014-06-27T12:42:45Z","git_url":"git://github.com/samarion/scala-abide.git","ssh_url":"git@github.com:samarion/scala-abide.git","clone_url":"https://github.com/samarion/scala-abide.git","svn_url":"https://github.com/samarion/scala-abide","homepage":null,"size":288,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":true,"forks_count":1,"mirror_url":null,"open_issues_count":1,"forks":1,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/samarion/scala-abide/pulls/1"},"html":{"href":"https://github.com/samarion/scala-abide/pull/1"},"issue":{"href":"https://api.github.com/repos/samarion/scala-abide/issues/1"},"comments":{"href":"https://api.github.com/repos/samarion/scala-abide/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/samarion/scala-abide/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/samarion/scala-abide/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/samarion/scala-abide/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/samarion/scala-abide/statuses/aa95c7f5762ffd98bdac6eb3426af78d48b3ae02"}}}}