{"action":"created","issue":{"url":"https://api.github.com/repos/DotNetAnalyzers/StyleCopAnalyzers/issues/651","labels_url":"https://api.github.com/repos/DotNetAnalyzers/StyleCopAnalyzers/issues/651/labels{/name}","comments_url":"https://api.github.com/repos/DotNetAnalyzers/StyleCopAnalyzers/issues/651/comments","events_url":"https://api.github.com/repos/DotNetAnalyzers/StyleCopAnalyzers/issues/651/events","html_url":"https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/651","id":67106798,"number":651,"title":"New readability rule to format ternary expression","user":{"login":"Przemyslaw-W","id":10596585,"avatar_url":"https://avatars.githubusercontent.com/u/10596585?v=3","gravatar_id":"","url":"https://api.github.com/users/Przemyslaw-W","html_url":"https://github.com/Przemyslaw-W","followers_url":"https://api.github.com/users/Przemyslaw-W/followers","following_url":"https://api.github.com/users/Przemyslaw-W/following{/other_user}","gists_url":"https://api.github.com/users/Przemyslaw-W/gists{/gist_id}","starred_url":"https://api.github.com/users/Przemyslaw-W/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Przemyslaw-W/subscriptions","organizations_url":"https://api.github.com/users/Przemyslaw-W/orgs","repos_url":"https://api.github.com/users/Przemyslaw-W/repos","events_url":"https://api.github.com/users/Przemyslaw-W/events{/privacy}","received_events_url":"https://api.github.com/users/Przemyslaw-W/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/DotNetAnalyzers/StyleCopAnalyzers/labels/new%20rule","name":"new rule","color":"207de5"},{"url":"https://api.github.com/repos/DotNetAnalyzers/StyleCopAnalyzers/labels/readability","name":"readability","color":"ffffff"},{"url":"https://api.github.com/repos/DotNetAnalyzers/StyleCopAnalyzers/labels/up%20for%20grabs","name":"up for grabs","color":"006b75"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":10,"created_at":"2015-04-08T11:20:06Z","updated_at":"2015-08-05T15:45:16Z","closed_at":null,"body":"Hi,\r\n\r\nI'd like to propose new readability rule for ternary expressions. Valid options should be:\r\n\r\n1. Whole expression in one line:\r\n\r\n    ```c#\r\n    int x = booleanExpression ? firstIntValueExpression : secondIntValueExpression;\r\n    ```\r\n\r\n2. Each subexpression on its own line, with `?` and `:` as starting characters:\r\n\r\n    ```c#\r\n    int x = booleanExpression\r\n        ? firstIntValueExpression\r\n        : secondIntValueExpression;\r\n    ```\r\n\r\nRationale for placement expressions in separate lines: \r\n* consistency with parameters and statement rules - parameters should be in one line or each in separate lines, statements should be each in its own line. \r\n* each expression in its own line allows to easy grasp where it starts and ends.\r\n\r\nRationale for `?` and `:` placement: \r\n* when these operators are placed at the beginning of line, one can easy see that rest of the line is part of ternary expression. \r\n* when these operators are placed at the end of line and expressions are long, `?` and `:` tokens can go out of view. This makes harder to see that ternary expression is used.\r\n\r\nHere is corresponding original SC issue, together with follow up discussion: https://stylecop.codeplex.com/discussions/253622"},"comment":{"url":"https://api.github.com/repos/DotNetAnalyzers/StyleCopAnalyzers/issues/comments/128045587","html_url":"https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/651#issuecomment-128045587","issue_url":"https://api.github.com/repos/DotNetAnalyzers/StyleCopAnalyzers/issues/651","id":128045587,"user":{"login":"otac0n","id":193584,"avatar_url":"https://avatars.githubusercontent.com/u/193584?v=3","gravatar_id":"","url":"https://api.github.com/users/otac0n","html_url":"https://github.com/otac0n","followers_url":"https://api.github.com/users/otac0n/followers","following_url":"https://api.github.com/users/otac0n/following{/other_user}","gists_url":"https://api.github.com/users/otac0n/gists{/gist_id}","starred_url":"https://api.github.com/users/otac0n/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/otac0n/subscriptions","organizations_url":"https://api.github.com/users/otac0n/orgs","repos_url":"https://api.github.com/users/otac0n/repos","events_url":"https://api.github.com/users/otac0n/events{/privacy}","received_events_url":"https://api.github.com/users/otac0n/received_events","type":"User","site_admin":false},"created_at":"2015-08-05T15:45:16Z","updated_at":"2015-08-05T15:45:16Z","body":"I should elaborate to say that what @AArnott described is exactly how I've been formatting my code for a couple of years.  I think it turns out very readable. (e.g. [single conditional](https://github.com/otac0n/GitReview/blob/master/GitReview/ActionResults/AdvertiseRefsResult.cs#L65 ) vs [multiple conditionals](https://github.com/otac0n/GitReview/blob/master/GitReview/ActionResults/ProtocolUtils.cs#L348))\r\n"}}