{"action":"closed","issue":{"url":"https://api.github.com/repos/SonarSource/SonarTS/issues/596","repository_url":"https://api.github.com/repos/SonarSource/SonarTS","labels_url":"https://api.github.com/repos/SonarSource/SonarTS/issues/596/labels{/name}","comments_url":"https://api.github.com/repos/SonarSource/SonarTS/issues/596/comments","events_url":"https://api.github.com/repos/SonarSource/SonarTS/issues/596/events","html_url":"https://github.com/SonarSource/SonarTS/issues/596","id":308183313,"number":596,"title":"Is it possible to detect those code smells?","user":{"login":"SunboX","id":83344,"avatar_url":"https://avatars2.githubusercontent.com/u/83344?v=4","gravatar_id":"","url":"https://api.github.com/users/SunboX","html_url":"https://github.com/SunboX","followers_url":"https://api.github.com/users/SunboX/followers","following_url":"https://api.github.com/users/SunboX/following{/other_user}","gists_url":"https://api.github.com/users/SunboX/gists{/gist_id}","starred_url":"https://api.github.com/users/SunboX/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SunboX/subscriptions","organizations_url":"https://api.github.com/users/SunboX/orgs","repos_url":"https://api.github.com/users/SunboX/repos","events_url":"https://api.github.com/users/SunboX/events{/privacy}","received_events_url":"https://api.github.com/users/SunboX/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-03-23T21:24:25Z","updated_at":"2018-04-30T14:44:03Z","closed_at":"2018-04-30T14:44:03Z","author_association":"NONE","body":"**I want to request a feature.**\r\n\r\nI've some TypeScript with duplicated code or uneeded nested functions like this:\r\n```TypeScript \r\n\r\nimport { Core } from \"../Core\";\r\n\r\nexport class SonarTSTest1 extends Core {\r\n    public foo: number;\r\n    public fooArray: Array<number> = [];\r\n    public isFoo: boolean = false;\r\n\r\n    fnBar() {\r\n        this.fnFoo(\"bar\");\r\n    }\r\n\r\n    fnOne() {\r\n        this.foo = this.given + 1;\r\n        this.fnFoo(\"xXx\", this.foo);\r\n        this.fooArray.push(1);\r\n        this.isFoo = true;\r\n        this.fnFoo(\"yYy\", this.foo);\r\n    }\r\n\r\n    fnTwo() {\r\n        this.foo = this.given + 2;\r\n        this.fnFoo(\"xXx\", this.foo);\r\n        this.fooArray.push(2);\r\n        this.isFoo = true;\r\n        this.fnFoo(\"yYy\", this.foo);\r\n    }\r\n\r\n    fnThree() {\r\n        this.foo = this.given + 3;\r\n        this.fnFoo(\"xXx\", this.foo);\r\n        this.fooArray.push(3);\r\n        this.isFoo = true;\r\n        this.fnFoo(\"yYy\", this.foo);\r\n    }\r\n\r\n    fnFour() {\r\n        this.foo = this.given + 4;\r\n        this.fnFoo(\"xXx\", this.foo);\r\n        this.fooArray.push(4);\r\n        this.isFoo = true;\r\n        this.fnFoo(\"yYy\", this.foo);\r\n    }\r\n\r\n    fnFive() {\r\n        this.foo = this.given + 5;\r\n        this.fnFoo(\"xXx\", this.foo);\r\n        this.fooArray.push(5);\r\n        this.isFoo = true;\r\n        this.fnFoo(\"yYy\", this.foo);\r\n    }\r\n\r\n    public getMethods = {\r\n        fnFoo: () => {\r\n        },\r\n        fnBar: () => {\r\n            this.fnBar();\r\n        },\r\n        fnOne: () => {\r\n            this.fnOne();\r\n        },\r\n        fnTwo: () => {\r\n            this.fnTwo();\r\n        },\r\n        fnThree: () => {\r\n            this.fnThree();\r\n        },\r\n        fnFour: () => {\r\n            this.fnFour();\r\n        },\r\n        fnFive: () => {\r\n            this.fnFive();\r\n        }\r\n    }\r\n}\r\n```\r\n\r\nSonarQube only reports this:\r\n![image](https://user-images.githubusercontent.com/83344/37853891-eb7c68ce-2ee8-11e8-8d59-dff27bfc50aa.png)\r\n\r\nA better way to write this, can be:\r\n```TypeScript\r\n\r\nimport { Core } from \"../Core\";\r\n\r\nexport class SonarTSTest1 extends Core {\r\n    public foo: number;\r\n    public fooArray: Array<number> = [];\r\n    public isFoo: boolean = false;\r\n\r\n    fnBar() {\r\n        this.fnFoo(\"bar\");\r\n    }\r\n\r\n    fnFooBy(amount: number) {\r\n        this.foo = this.given + number;\r\n        this.fnFoo(\"xXx\", this.foo);\r\n        this.fooArray.push(number);\r\n        this.isFoo = true;\r\n        this.fnFoo(\"yYy\", this.foo);\r\n    }\r\n\r\n    public getMethods = {\r\n        fnFoo: () => {\r\n        },\r\n        fnBar: this.fnBar,\r\n        fnOne: () => this.fnFooBy(1),\r\n        fnTwo: () => this.fnFooBy(2),\r\n        fnThree: () => this.fnFooBy(3),\r\n        fnFour: () =>this.fnFooBy(4),\r\n        fnFive: () => this.fnFooBy(5)\r\n    }\r\n}\r\n```\r\n\r\nIs it possible to detect those code smells?"}}
{"actor":{"display_login":"vilchik-elena"}}