{"action":"created","issue":{"url":"https://api.github.com/repos/crystal-lang/crystal/issues/3571","repository_url":"https://api.github.com/repos/crystal-lang/crystal","labels_url":"https://api.github.com/repos/crystal-lang/crystal/issues/3571/labels{/name}","comments_url":"https://api.github.com/repos/crystal-lang/crystal/issues/3571/comments","events_url":"https://api.github.com/repos/crystal-lang/crystal/issues/3571/events","html_url":"https://github.com/crystal-lang/crystal/issues/3571","id":191319292,"number":3571,"title":"Format multiline chained method calls for better git diffs","user":{"login":"paulcsmith","id":22394,"avatar_url":"https://avatars.githubusercontent.com/u/22394?v=3","gravatar_id":"","url":"https://api.github.com/users/paulcsmith","html_url":"https://github.com/paulcsmith","followers_url":"https://api.github.com/users/paulcsmith/followers","following_url":"https://api.github.com/users/paulcsmith/following{/other_user}","gists_url":"https://api.github.com/users/paulcsmith/gists{/gist_id}","starred_url":"https://api.github.com/users/paulcsmith/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paulcsmith/subscriptions","organizations_url":"https://api.github.com/users/paulcsmith/orgs","repos_url":"https://api.github.com/users/paulcsmith/repos","events_url":"https://api.github.com/users/paulcsmith/events{/privacy}","received_events_url":"https://api.github.com/users/paulcsmith/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":8,"created_at":"2016-11-23T16:24:23Z","updated_at":"2016-11-23T20:37:48Z","closed_at":null,"body":"I checked the issues and couldn't find something similar, so posting here to gather thoughts before proposing a PR\r\n\r\n```crystal\r\nsomething = SomeClass.new\r\n  .do_something\r\n  .do_something_else\r\n  \r\n# Is formatted to this when using `crystal tool format`\r\nthing = SomeClass.new\r\n                 .do_something\r\n                 .do_something_else\r\n```\r\n\r\nI think the first one is \"better\" because even if I change the class or rename the variable, the other lines don't change. This makes diffs a lot cleaner and makes it easier to see what actually changed. I also think it makes it easier to remember the rules, because everything is consistently indented by 2 spaces. It also makes it much easier to keep things under 80 lines. With the current format, if you have a long variable name it makes it very difficult to keep some lines under 80 on the following lines.\r\n\r\n```crystal\r\ntask_for_current_user = TaskQuery.new\r\n                                 .where({published: current_user.id}) # Pushes this far to the right, making it hard to fit under 80 lines\r\n```\r\n\r\nSubjectively, I also think it looks nicer since long variable names won't push things super far to the right (which looks strange IMO)\r\n\r\nWhat are thoughts on changing the formatter so that it uses the first version (indented by two spaces instead of right aligned?)"},"comment":{"url":"https://api.github.com/repos/crystal-lang/crystal/issues/comments/262624394","html_url":"https://github.com/crystal-lang/crystal/issues/3571#issuecomment-262624394","issue_url":"https://api.github.com/repos/crystal-lang/crystal/issues/3571","id":262624394,"user":{"login":"RX14","id":2788811,"avatar_url":"https://avatars.githubusercontent.com/u/2788811?v=3","gravatar_id":"","url":"https://api.github.com/users/RX14","html_url":"https://github.com/RX14","followers_url":"https://api.github.com/users/RX14/followers","following_url":"https://api.github.com/users/RX14/following{/other_user}","gists_url":"https://api.github.com/users/RX14/gists{/gist_id}","starred_url":"https://api.github.com/users/RX14/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RX14/subscriptions","organizations_url":"https://api.github.com/users/RX14/orgs","repos_url":"https://api.github.com/users/RX14/repos","events_url":"https://api.github.com/users/RX14/events{/privacy}","received_events_url":"https://api.github.com/users/RX14/received_events","type":"User","site_admin":false},"created_at":"2016-11-23T20:37:48Z","updated_at":"2016-11-23T20:37:48Z","body":"```cr\r\nvar = if foo\r\n        \"bar\"\r\n      else\r\n        \"baz\"\r\n      end\r\n```\r\ncan be rewritten\r\n```cr\r\nif foo\r\n  var = \"bar\"\r\nelse\r\n  var = \"baz\"\r\nend\r\n```\r\nwhich is IMHO better in pretty much every way.\r\n\r\n```cr\r\n[1, 2, 3].map { |x| x + 1 }\r\n         .select(&.odd?)\r\n         .group_by(&.itself)\r\n```\r\ncan be formatted\r\n```\r\n[1, 2, 3]\r\n  .map { |x| x + 1 }\r\n  .select(&.odd?)\r\n  .group_by(&.itself)\r\n```\r\n\r\nAll of these examples format to themselves with the current formatter, so I guess this change isn't required."}}
{"actor":{"display_login":"RX14"}}