{"action":"created","comment":{"url":"https://api.github.com/repos/SonarSource/SonarTS/pulls/comments/188894380","pull_request_review_id":120962134,"id":188894380,"diff_hunk":"@@ -0,0 +1,69 @@\n+/*\n+ * SonarTS\n+ * Copyright (C) 2017-2018 SonarSource SA\n+ * mailto:info AT sonarsource DOT com\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU Lesser General Public\n+ * License as published by the Free Software Foundation; either\n+ * version 3 of the License, or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n+ * Lesser General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU Lesser General Public License\n+ * along with this program; if not, write to the Free Software Foundation,\n+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.\n+ */\n+import * as tslint from \"tslint\";\n+import * as ts from \"typescript\";\n+import { SonarRuleMetaData } from \"../sonarRule\";\n+import { SonarRuleVisitor } from \"../utils/sonarAnalysis\";\n+import { ancestorsChain } from \"../utils/navigation\";\n+import { is } from \"../utils/nodes\";\n+\n+export class Rule extends tslint.Rules.AbstractRule {\n+  public static metadata: SonarRuleMetaData = {\n+    ruleName: \"max-union-size\",\n+    description: \"Union types should not have too many elements\",\n+    rationale: tslint.Utils.dedent``,\n+    optionsDescription: \"Maximum elements authorized in a union type definition.\",\n+    options: { type: \"number\" },\n+    rspecKey: \"RSPEC-4622\",\n+    type: \"maintainability\",\n+    typescriptOnly: true,\n+    optionExamples: [[true, 5]],\n+  };\n+\n+  private static readonly DEFAULT_MAX = 3;\n+\n+  private get max(): number {\n+    return this.ruleArguments[0] || Rule.DEFAULT_MAX;\n+  }\n+\n+  public static message(max: number) {\n+    return `Refactor this union type to have less than ${max} elements.`;\n+  }\n+\n+  public apply(sourceFile: ts.SourceFile): tslint.RuleFailure[] {\n+    return new Visitor(this.getOptions().ruleName, this.max).visit(sourceFile).getIssues();\n+  }\n+}\n+\n+class Visitor extends SonarRuleVisitor {\n+  constructor(ruleName: string, private readonly max: number) {\n+    super(ruleName);\n+  }\n+  public visitUnionTypeNode(node: ts.UnionTypeNode) {\n+    if (node.types.length > this.max && !this.isFromTypeStatement(node)) {\n+      this.addIssue(node, Rule.message(this.max));\n+    }\n+    super.visitUnionTypeNode(node);\n+  }\n+\n+  private isFromTypeStatement(node: ts.UnionTypeNode) {\n+    return ancestorsChain(node).some(parent => is(parent, ts.SyntaxKind.TypeAliasDeclaration));","path":"sonarts-core/src/rules/maxUnionSizeRule.ts","position":67,"original_position":67,"commit_id":"cc36861f829a1d72670321089ad2f77f6207bac5","original_commit_id":"cc36861f829a1d72670321089ad2f77f6207bac5","user":{"login":"andrea-guarino-sonarsource","id":38876543,"avatar_url":"https://avatars2.githubusercontent.com/u/38876543?v=4","gravatar_id":"","url":"https://api.github.com/users/andrea-guarino-sonarsource","html_url":"https://github.com/andrea-guarino-sonarsource","followers_url":"https://api.github.com/users/andrea-guarino-sonarsource/followers","following_url":"https://api.github.com/users/andrea-guarino-sonarsource/following{/other_user}","gists_url":"https://api.github.com/users/andrea-guarino-sonarsource/gists{/gist_id}","starred_url":"https://api.github.com/users/andrea-guarino-sonarsource/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andrea-guarino-sonarsource/subscriptions","organizations_url":"https://api.github.com/users/andrea-guarino-sonarsource/orgs","repos_url":"https://api.github.com/users/andrea-guarino-sonarsource/repos","events_url":"https://api.github.com/users/andrea-guarino-sonarsource/events{/privacy}","received_events_url":"https://api.github.com/users/andrea-guarino-sonarsource/received_events","type":"User","site_admin":false},"body":"good point, I'm going to add a test for this case","created_at":"2018-05-17T09:30:09Z","updated_at":"2018-05-17T09:30:09Z","html_url":"https://github.com/SonarSource/SonarTS/pull/642#discussion_r188894380","pull_request_url":"https://api.github.com/repos/SonarSource/SonarTS/pulls/642","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/SonarSource/SonarTS/pulls/comments/188894380"},"html":{"href":"https://github.com/SonarSource/SonarTS/pull/642#discussion_r188894380"},"pull_request":{"href":"https://api.github.com/repos/SonarSource/SonarTS/pulls/642"}},"in_reply_to_id":188885410},"pull_request":{"url":"https://api.github.com/repos/SonarSource/SonarTS/pulls/642","id":188426747,"html_url":"https://github.com/SonarSource/SonarTS/pull/642","diff_url":"https://github.com/SonarSource/SonarTS/pull/642.diff","patch_url":"https://github.com/SonarSource/SonarTS/pull/642.patch","issue_url":"https://api.github.com/repos/SonarSource/SonarTS/issues/642","number":642,"state":"open","locked":false,"title":"add rule max-union-size/S4622","user":{"login":"andrea-guarino-sonarsource","id":38876543,"avatar_url":"https://avatars2.githubusercontent.com/u/38876543?v=4","gravatar_id":"","url":"https://api.github.com/users/andrea-guarino-sonarsource","html_url":"https://github.com/andrea-guarino-sonarsource","followers_url":"https://api.github.com/users/andrea-guarino-sonarsource/followers","following_url":"https://api.github.com/users/andrea-guarino-sonarsource/following{/other_user}","gists_url":"https://api.github.com/users/andrea-guarino-sonarsource/gists{/gist_id}","starred_url":"https://api.github.com/users/andrea-guarino-sonarsource/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andrea-guarino-sonarsource/subscriptions","organizations_url":"https://api.github.com/users/andrea-guarino-sonarsource/orgs","repos_url":"https://api.github.com/users/andrea-guarino-sonarsource/repos","events_url":"https://api.github.com/users/andrea-guarino-sonarsource/events{/privacy}","received_events_url":"https://api.github.com/users/andrea-guarino-sonarsource/received_events","type":"User","site_admin":false},"body":"Fixes #582 ","created_at":"2018-05-16T13:08:35Z","updated_at":"2018-05-17T09:30:09Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1613956589f84517f1d9f44714291ef2559889b3","assignee":{"login":"andrea-guarino-sonarsource","id":38876543,"avatar_url":"https://avatars2.githubusercontent.com/u/38876543?v=4","gravatar_id":"","url":"https://api.github.com/users/andrea-guarino-sonarsource","html_url":"https://github.com/andrea-guarino-sonarsource","followers_url":"https://api.github.com/users/andrea-guarino-sonarsource/followers","following_url":"https://api.github.com/users/andrea-guarino-sonarsource/following{/other_user}","gists_url":"https://api.github.com/users/andrea-guarino-sonarsource/gists{/gist_id}","starred_url":"https://api.github.com/users/andrea-guarino-sonarsource/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andrea-guarino-sonarsource/subscriptions","organizations_url":"https://api.github.com/users/andrea-guarino-sonarsource/orgs","repos_url":"https://api.github.com/users/andrea-guarino-sonarsource/repos","events_url":"https://api.github.com/users/andrea-guarino-sonarsource/events{/privacy}","received_events_url":"https://api.github.com/users/andrea-guarino-sonarsource/received_events","type":"User","site_admin":false},"assignees":[{"login":"andrea-guarino-sonarsource","id":38876543,"avatar_url":"https://avatars2.githubusercontent.com/u/38876543?v=4","gravatar_id":"","url":"https://api.github.com/users/andrea-guarino-sonarsource","html_url":"https://github.com/andrea-guarino-sonarsource","followers_url":"https://api.github.com/users/andrea-guarino-sonarsource/followers","following_url":"https://api.github.com/users/andrea-guarino-sonarsource/following{/other_user}","gists_url":"https://api.github.com/users/andrea-guarino-sonarsource/gists{/gist_id}","starred_url":"https://api.github.com/users/andrea-guarino-sonarsource/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andrea-guarino-sonarsource/subscriptions","organizations_url":"https://api.github.com/users/andrea-guarino-sonarsource/orgs","repos_url":"https://api.github.com/users/andrea-guarino-sonarsource/repos","events_url":"https://api.github.com/users/andrea-guarino-sonarsource/events{/privacy}","received_events_url":"https://api.github.com/users/andrea-guarino-sonarsource/received_events","type":"User","site_admin":false}],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":708418924,"url":"https://api.github.com/repos/SonarSource/SonarTS/labels/in%20progress","name":"in progress","color":"ededed","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/SonarSource/SonarTS/pulls/642/commits","review_comments_url":"https://api.github.com/repos/SonarSource/SonarTS/pulls/642/comments","review_comment_url":"https://api.github.com/repos/SonarSource/SonarTS/pulls/comments{/number}","comments_url":"https://api.github.com/repos/SonarSource/SonarTS/issues/642/comments","statuses_url":"https://api.github.com/repos/SonarSource/SonarTS/statuses/cc36861f829a1d72670321089ad2f77f6207bac5","head":{"label":"SonarSource:issue-582","ref":"issue-582","sha":"cc36861f829a1d72670321089ad2f77f6207bac5","user":{"login":"SonarSource","id":545988,"avatar_url":"https://avatars0.githubusercontent.com/u/545988?v=4","gravatar_id":"","url":"https://api.github.com/users/SonarSource","html_url":"https://github.com/SonarSource","followers_url":"https://api.github.com/users/SonarSource/followers","following_url":"https://api.github.com/users/SonarSource/following{/other_user}","gists_url":"https://api.github.com/users/SonarSource/gists{/gist_id}","starred_url":"https://api.github.com/users/SonarSource/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SonarSource/subscriptions","organizations_url":"https://api.github.com/users/SonarSource/orgs","repos_url":"https://api.github.com/users/SonarSource/repos","events_url":"https://api.github.com/users/SonarSource/events{/privacy}","received_events_url":"https://api.github.com/users/SonarSource/received_events","type":"Organization","site_admin":false},"repo":{"id":90955014,"name":"SonarTS","full_name":"SonarSource/SonarTS","owner":{"login":"SonarSource","id":545988,"avatar_url":"https://avatars0.githubusercontent.com/u/545988?v=4","gravatar_id":"","url":"https://api.github.com/users/SonarSource","html_url":"https://github.com/SonarSource","followers_url":"https://api.github.com/users/SonarSource/followers","following_url":"https://api.github.com/users/SonarSource/following{/other_user}","gists_url":"https://api.github.com/users/SonarSource/gists{/gist_id}","starred_url":"https://api.github.com/users/SonarSource/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SonarSource/subscriptions","organizations_url":"https://api.github.com/users/SonarSource/orgs","repos_url":"https://api.github.com/users/SonarSource/repos","events_url":"https://api.github.com/users/SonarSource/events{/privacy}","received_events_url":"https://api.github.com/users/SonarSource/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/SonarSource/SonarTS","description":"Static code analyzer for TypeScript","fork":false,"url":"https://api.github.com/repos/SonarSource/SonarTS","forks_url":"https://api.github.com/repos/SonarSource/SonarTS/forks","keys_url":"https://api.github.com/repos/SonarSource/SonarTS/keys{/key_id}","collaborators_url":"https://api.github.com/repos/SonarSource/SonarTS/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/SonarSource/SonarTS/teams","hooks_url":"https://api.github.com/repos/SonarSource/SonarTS/hooks","issue_events_url":"https://api.github.com/repos/SonarSource/SonarTS/issues/events{/number}","events_url":"https://api.github.com/repos/SonarSource/SonarTS/events","assignees_url":"https://api.github.com/repos/SonarSource/SonarTS/assignees{/user}","branches_url":"https://api.github.com/repos/SonarSource/SonarTS/branches{/branch}","tags_url":"https://api.github.com/repos/SonarSource/SonarTS/tags","blobs_url":"https://api.github.com/repos/SonarSource/SonarTS/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/SonarSource/SonarTS/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/SonarSource/SonarTS/git/refs{/sha}","trees_url":"https://api.github.com/repos/SonarSource/SonarTS/git/trees{/sha}","statuses_url":"https://api.github.com/repos/SonarSource/SonarTS/statuses/{sha}","languages_url":"https://api.github.com/repos/SonarSource/SonarTS/languages","stargazers_url":"https://api.github.com/repos/SonarSource/SonarTS/stargazers","contributors_url":"https://api.github.com/repos/SonarSource/SonarTS/contributors","subscribers_url":"https://api.github.com/repos/SonarSource/SonarTS/subscribers","subscription_url":"https://api.github.com/repos/SonarSource/SonarTS/subscription","commits_url":"https://api.github.com/repos/SonarSource/SonarTS/commits{/sha}","git_commits_url":"https://api.github.com/repos/SonarSource/SonarTS/git/commits{/sha}","comments_url":"https://api.github.com/repos/SonarSource/SonarTS/comments{/number}","issue_comment_url":"https://api.github.com/repos/SonarSource/SonarTS/issues/comments{/number}","contents_url":"https://api.github.com/repos/SonarSource/SonarTS/contents/{+path}","compare_url":"https://api.github.com/repos/SonarSource/SonarTS/compare/{base}...{head}","merges_url":"https://api.github.com/repos/SonarSource/SonarTS/merges","archive_url":"https://api.github.com/repos/SonarSource/SonarTS/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/SonarSource/SonarTS/downloads","issues_url":"https://api.github.com/repos/SonarSource/SonarTS/issues{/number}","pulls_url":"https://api.github.com/repos/SonarSource/SonarTS/pulls{/number}","milestones_url":"https://api.github.com/repos/SonarSource/SonarTS/milestones{/number}","notifications_url":"https://api.github.com/repos/SonarSource/SonarTS/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/SonarSource/SonarTS/labels{/name}","releases_url":"https://api.github.com/repos/SonarSource/SonarTS/releases{/id}","deployments_url":"https://api.github.com/repos/SonarSource/SonarTS/deployments","created_at":"2017-05-11T08:17:46Z","updated_at":"2018-05-17T08:22:11Z","pushed_at":"2018-05-17T09:29:09Z","git_url":"git://github.com/SonarSource/SonarTS.git","ssh_url":"git@github.com:SonarSource/SonarTS.git","clone_url":"https://github.com/SonarSource/SonarTS.git","svn_url":"https://github.com/SonarSource/SonarTS","homepage":"","size":6706,"stargazers_count":164,"watchers_count":164,"language":"TypeScript","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":19,"mirror_url":null,"archived":false,"open_issues_count":74,"license":{"key":"lgpl-3.0","name":"GNU Lesser General Public License v3.0","spdx_id":"LGPL-3.0","url":"https://api.github.com/licenses/lgpl-3.0"},"forks":19,"open_issues":74,"watchers":164,"default_branch":"master"}},"base":{"label":"SonarSource:master","ref":"master","sha":"e607632e7daefd34a5b8e84206370838ba03ab9d","user":{"login":"SonarSource","id":545988,"avatar_url":"https://avatars0.githubusercontent.com/u/545988?v=4","gravatar_id":"","url":"https://api.github.com/users/SonarSource","html_url":"https://github.com/SonarSource","followers_url":"https://api.github.com/users/SonarSource/followers","following_url":"https://api.github.com/users/SonarSource/following{/other_user}","gists_url":"https://api.github.com/users/SonarSource/gists{/gist_id}","starred_url":"https://api.github.com/users/SonarSource/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SonarSource/subscriptions","organizations_url":"https://api.github.com/users/SonarSource/orgs","repos_url":"https://api.github.com/users/SonarSource/repos","events_url":"https://api.github.com/users/SonarSource/events{/privacy}","received_events_url":"https://api.github.com/users/SonarSource/received_events","type":"Organization","site_admin":false},"repo":{"id":90955014,"name":"SonarTS","full_name":"SonarSource/SonarTS","owner":{"login":"SonarSource","id":545988,"avatar_url":"https://avatars0.githubusercontent.com/u/545988?v=4","gravatar_id":"","url":"https://api.github.com/users/SonarSource","html_url":"https://github.com/SonarSource","followers_url":"https://api.github.com/users/SonarSource/followers","following_url":"https://api.github.com/users/SonarSource/following{/other_user}","gists_url":"https://api.github.com/users/SonarSource/gists{/gist_id}","starred_url":"https://api.github.com/users/SonarSource/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SonarSource/subscriptions","organizations_url":"https://api.github.com/users/SonarSource/orgs","repos_url":"https://api.github.com/users/SonarSource/repos","events_url":"https://api.github.com/users/SonarSource/events{/privacy}","received_events_url":"https://api.github.com/users/SonarSource/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/SonarSource/SonarTS","description":"Static code analyzer for TypeScript","fork":false,"url":"https://api.github.com/repos/SonarSource/SonarTS","forks_url":"https://api.github.com/repos/SonarSource/SonarTS/forks","keys_url":"https://api.github.com/repos/SonarSource/SonarTS/keys{/key_id}","collaborators_url":"https://api.github.com/repos/SonarSource/SonarTS/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/SonarSource/SonarTS/teams","hooks_url":"https://api.github.com/repos/SonarSource/SonarTS/hooks","issue_events_url":"https://api.github.com/repos/SonarSource/SonarTS/issues/events{/number}","events_url":"https://api.github.com/repos/SonarSource/SonarTS/events","assignees_url":"https://api.github.com/repos/SonarSource/SonarTS/assignees{/user}","branches_url":"https://api.github.com/repos/SonarSource/SonarTS/branches{/branch}","tags_url":"https://api.github.com/repos/SonarSource/SonarTS/tags","blobs_url":"https://api.github.com/repos/SonarSource/SonarTS/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/SonarSource/SonarTS/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/SonarSource/SonarTS/git/refs{/sha}","trees_url":"https://api.github.com/repos/SonarSource/SonarTS/git/trees{/sha}","statuses_url":"https://api.github.com/repos/SonarSource/SonarTS/statuses/{sha}","languages_url":"https://api.github.com/repos/SonarSource/SonarTS/languages","stargazers_url":"https://api.github.com/repos/SonarSource/SonarTS/stargazers","contributors_url":"https://api.github.com/repos/SonarSource/SonarTS/contributors","subscribers_url":"https://api.github.com/repos/SonarSource/SonarTS/subscribers","subscription_url":"https://api.github.com/repos/SonarSource/SonarTS/subscription","commits_url":"https://api.github.com/repos/SonarSource/SonarTS/commits{/sha}","git_commits_url":"https://api.github.com/repos/SonarSource/SonarTS/git/commits{/sha}","comments_url":"https://api.github.com/repos/SonarSource/SonarTS/comments{/number}","issue_comment_url":"https://api.github.com/repos/SonarSource/SonarTS/issues/comments{/number}","contents_url":"https://api.github.com/repos/SonarSource/SonarTS/contents/{+path}","compare_url":"https://api.github.com/repos/SonarSource/SonarTS/compare/{base}...{head}","merges_url":"https://api.github.com/repos/SonarSource/SonarTS/merges","archive_url":"https://api.github.com/repos/SonarSource/SonarTS/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/SonarSource/SonarTS/downloads","issues_url":"https://api.github.com/repos/SonarSource/SonarTS/issues{/number}","pulls_url":"https://api.github.com/repos/SonarSource/SonarTS/pulls{/number}","milestones_url":"https://api.github.com/repos/SonarSource/SonarTS/milestones{/number}","notifications_url":"https://api.github.com/repos/SonarSource/SonarTS/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/SonarSource/SonarTS/labels{/name}","releases_url":"https://api.github.com/repos/SonarSource/SonarTS/releases{/id}","deployments_url":"https://api.github.com/repos/SonarSource/SonarTS/deployments","created_at":"2017-05-11T08:17:46Z","updated_at":"2018-05-17T08:22:11Z","pushed_at":"2018-05-17T09:29:09Z","git_url":"git://github.com/SonarSource/SonarTS.git","ssh_url":"git@github.com:SonarSource/SonarTS.git","clone_url":"https://github.com/SonarSource/SonarTS.git","svn_url":"https://github.com/SonarSource/SonarTS","homepage":"","size":6706,"stargazers_count":164,"watchers_count":164,"language":"TypeScript","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":19,"mirror_url":null,"archived":false,"open_issues_count":74,"license":{"key":"lgpl-3.0","name":"GNU Lesser General Public License v3.0","spdx_id":"LGPL-3.0","url":"https://api.github.com/licenses/lgpl-3.0"},"forks":19,"open_issues":74,"watchers":164,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/SonarSource/SonarTS/pulls/642"},"html":{"href":"https://github.com/SonarSource/SonarTS/pull/642"},"issue":{"href":"https://api.github.com/repos/SonarSource/SonarTS/issues/642"},"comments":{"href":"https://api.github.com/repos/SonarSource/SonarTS/issues/642/comments"},"review_comments":{"href":"https://api.github.com/repos/SonarSource/SonarTS/pulls/642/comments"},"review_comment":{"href":"https://api.github.com/repos/SonarSource/SonarTS/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/SonarSource/SonarTS/pulls/642/commits"},"statuses":{"href":"https://api.github.com/repos/SonarSource/SonarTS/statuses/cc36861f829a1d72670321089ad2f77f6207bac5"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"andrea-guarino-sonarsource"}}