{"action":"created","comment":{"url":"https://api.github.com/repos/facebook/hhvm/pulls/comments/209355321","pull_request_review_id":145360938,"id":209355321,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIwOTM1NTMyMQ==","diff_hunk":"@@ -822,7 +822,15 @@ let rec t (env: Env.t) (node: Syntax.t) : Doc.t =\n       t env kw;\n       Space;\n       transform_condition env left_p condition right_p;\n-      handle_possible_compound_statement env if_body;\n+      (match Syntax.syntax if_body with\n+      | Syntax.CompoundStatement _ ->\n+          handle_possible_compound_statement env if_body;\n+      | _ -> Concat [\n+          Space;\n+          SplitWith Cost.Base;\n+          Nest [t env if_body];","path":"hphp/hack/src/hackfmt/hack_format.ml","position":11,"original_position":11,"commit_id":"2d06b44d8e2b79df61d30437ef823ab420f48e6c","original_commit_id":"2d06b44d8e2b79df61d30437ef823ab420f48e6c","user":{"login":"rjbailey","id":2250242,"node_id":"MDQ6VXNlcjIyNTAyNDI=","avatar_url":"https://avatars3.githubusercontent.com/u/2250242?v=4","gravatar_id":"","url":"https://api.github.com/users/rjbailey","html_url":"https://github.com/rjbailey","followers_url":"https://api.github.com/users/rjbailey/followers","following_url":"https://api.github.com/users/rjbailey/following{/other_user}","gists_url":"https://api.github.com/users/rjbailey/gists{/gist_id}","starred_url":"https://api.github.com/users/rjbailey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rjbailey/subscriptions","organizations_url":"https://api.github.com/users/rjbailey/orgs","repos_url":"https://api.github.com/users/rjbailey/repos","events_url":"https://api.github.com/users/rjbailey/events{/privacy}","received_events_url":"https://api.github.com/users/rjbailey/received_events","type":"User","site_admin":false},"body":"@alisha, I'm seeing some pretty funky-looking results from some of our internal test cases.\r\n\r\nCode that was previously formatted like this:\r\n\r\n```\r\nif ($this->head->isEmpty())\r\n  return new MyQueue($this->head->push($item), $this->tail);\r\nelse\r\n  return new MyQueue($this->head, $this->tail->push($item));\r\n```\r\n\r\nIs now formatted like this:\r\n\r\n```\r\nif ($this->head->isEmpty()) return\r\n  new MyQueue($this->head->push($item), $this->tail);\r\nelse return new MyQueue($this->head, $this->tail->push($item));\r\n```\r\n\r\nWe could probably deal with this case:\r\n\r\n```\r\nif ($cond) return\r\n  $x;\r\n```\r\n\r\nby using a `Parental` rule to control the split before the body instead of an independent split (`SplitWith`):\r\n\r\n```\r\nWithRule (Rule.Parental, Nest [ Span [\r\n  Space;\r\n  Split;\r\n  t env if_body;\r\n]]);\r\n```\r\n\r\nUsing a `Parental` rule means that if any line break is added within the body, we'll add a line break at the `Split` preceding the body, too. Sorry for suggesting `SplitWith` earlier--I hadn't considered this possible outcome!\r\n\r\nEven if we deal with that case, to be frank, I think this formatting:\r\n\r\n```\r\nif ($this->head->isEmpty())\r\n  return new MyQueue($this->head->push($item), $this->tail);\r\nelse\r\n  return new MyQueue($this->head, $this->tail->push($item));\r\n```\r\n\r\nIs much more readable than this:\r\n\r\n```\r\nif ($this->head->isEmpty())\r\n  return new MyQueue($this->head->push($item), $this->tail);\r\nelse return new MyQueue($this->head, $this->tail->push($item));\r\n```\r\n\r\nOr this:\r\n\r\n```\r\nif ($empty) return new MyQueue($this->head->push($item), $this->tail);\r\nelse return new MyQueue($this->head, $this->tail->push($item));\r\n```\r\n\r\nSo I've become a little more uneasy about this change! I feel like some human input is useful in deciding when it's appropriate to put a single-statement `if` on one line.\r\n\r\nOne way we could deal with this is by preserving single-line `if`s when they already exist (and fit within the line length limit), and not forcing other single-statement `if`s onto one line if they aren't already. We just need to find out if there was already a newline after the condition's right parenthesis:\r\n\r\n```\r\nif has_newline (Syntax.trailing_trivia right_p)\r\nthen Newline\r\nelse Split;\r\n```\r\n\r\nSince this is starting to be a fair bit of code which is duplicated across `IfStatement`, `ElseifClause`, and `ElseClause`, perhaps we should move it to a new helper function called something like `transform_consequence` :)","created_at":"2018-08-10T18:55:02Z","updated_at":"2018-08-10T18:55:02Z","html_url":"https://github.com/facebook/hhvm/pull/8277#discussion_r209355321","pull_request_url":"https://api.github.com/repos/facebook/hhvm/pulls/8277","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/facebook/hhvm/pulls/comments/209355321"},"html":{"href":"https://github.com/facebook/hhvm/pull/8277#discussion_r209355321"},"pull_request":{"href":"https://api.github.com/repos/facebook/hhvm/pulls/8277"}}},"pull_request":{"url":"https://api.github.com/repos/facebook/hhvm/pulls/8277","id":206889584,"node_id":"MDExOlB1bGxSZXF1ZXN0MjA2ODg5NTg0","html_url":"https://github.com/facebook/hhvm/pull/8277","diff_url":"https://github.com/facebook/hhvm/pull/8277.diff","patch_url":"https://github.com/facebook/hhvm/pull/8277.patch","issue_url":"https://api.github.com/repos/facebook/hhvm/issues/8277","number":8277,"state":"open","locked":false,"title":"Add hackfmt support for single line if statements","user":{"login":"alisha","id":1406727,"node_id":"MDQ6VXNlcjE0MDY3Mjc=","avatar_url":"https://avatars3.githubusercontent.com/u/1406727?v=4","gravatar_id":"","url":"https://api.github.com/users/alisha","html_url":"https://github.com/alisha","followers_url":"https://api.github.com/users/alisha/followers","following_url":"https://api.github.com/users/alisha/following{/other_user}","gists_url":"https://api.github.com/users/alisha/gists{/gist_id}","starred_url":"https://api.github.com/users/alisha/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alisha/subscriptions","organizations_url":"https://api.github.com/users/alisha/orgs","repos_url":"https://api.github.com/users/alisha/repos","events_url":"https://api.github.com/users/alisha/events{/privacy}","received_events_url":"https://api.github.com/users/alisha/received_events","type":"User","site_admin":false},"body":"Currently, a single line if statement will be split into 2 lines after hackfmt is run. For example,\r\n```\r\nif (true) print(\"Hello, world!\");\r\n```\r\nbecomes\r\n```\r\nif (true)\r\n  print(\"Hello, world!\");\r\n```\r\n\r\nThis PR changes hackfmt so it keeps single line if statements, as long as the line isn't too long. If the line exceeds the specified limit, then it'll be split into 2 lines.\r\n\r\nThis was tested on a file with both single line if statements (of various lengths) and multi-line if statements.","created_at":"2018-08-08T04:29:43Z","updated_at":"2018-08-10T18:55:02Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8239bdbe8085e226dfbfbb76bdbfa8d528b1893a","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":196857004,"node_id":"MDU6TGFiZWwxOTY4NTcwMDQ=","url":"https://api.github.com/repos/facebook/hhvm/labels/CLA%20Signed","name":"CLA Signed","color":"009900","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/facebook/hhvm/pulls/8277/commits","review_comments_url":"https://api.github.com/repos/facebook/hhvm/pulls/8277/comments","review_comment_url":"https://api.github.com/repos/facebook/hhvm/pulls/comments{/number}","comments_url":"https://api.github.com/repos/facebook/hhvm/issues/8277/comments","statuses_url":"https://api.github.com/repos/facebook/hhvm/statuses/2d06b44d8e2b79df61d30437ef823ab420f48e6c","head":{"label":"alisha:single_line_if","ref":"single_line_if","sha":"2d06b44d8e2b79df61d30437ef823ab420f48e6c","user":{"login":"alisha","id":1406727,"node_id":"MDQ6VXNlcjE0MDY3Mjc=","avatar_url":"https://avatars3.githubusercontent.com/u/1406727?v=4","gravatar_id":"","url":"https://api.github.com/users/alisha","html_url":"https://github.com/alisha","followers_url":"https://api.github.com/users/alisha/followers","following_url":"https://api.github.com/users/alisha/following{/other_user}","gists_url":"https://api.github.com/users/alisha/gists{/gist_id}","starred_url":"https://api.github.com/users/alisha/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alisha/subscriptions","organizations_url":"https://api.github.com/users/alisha/orgs","repos_url":"https://api.github.com/users/alisha/repos","events_url":"https://api.github.com/users/alisha/events{/privacy}","received_events_url":"https://api.github.com/users/alisha/received_events","type":"User","site_admin":false},"repo":{"id":139205889,"node_id":"MDEwOlJlcG9zaXRvcnkxMzkyMDU4ODk=","name":"hhvm","full_name":"alisha/hhvm","owner":{"login":"alisha","id":1406727,"node_id":"MDQ6VXNlcjE0MDY3Mjc=","avatar_url":"https://avatars3.githubusercontent.com/u/1406727?v=4","gravatar_id":"","url":"https://api.github.com/users/alisha","html_url":"https://github.com/alisha","followers_url":"https://api.github.com/users/alisha/followers","following_url":"https://api.github.com/users/alisha/following{/other_user}","gists_url":"https://api.github.com/users/alisha/gists{/gist_id}","starred_url":"https://api.github.com/users/alisha/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alisha/subscriptions","organizations_url":"https://api.github.com/users/alisha/orgs","repos_url":"https://api.github.com/users/alisha/repos","events_url":"https://api.github.com/users/alisha/events{/privacy}","received_events_url":"https://api.github.com/users/alisha/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/alisha/hhvm","description":"A virtual machine for executing programs written in Hack.","fork":true,"url":"https://api.github.com/repos/alisha/hhvm","forks_url":"https://api.github.com/repos/alisha/hhvm/forks","keys_url":"https://api.github.com/repos/alisha/hhvm/keys{/key_id}","collaborators_url":"https://api.github.com/repos/alisha/hhvm/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/alisha/hhvm/teams","hooks_url":"https://api.github.com/repos/alisha/hhvm/hooks","issue_events_url":"https://api.github.com/repos/alisha/hhvm/issues/events{/number}","events_url":"https://api.github.com/repos/alisha/hhvm/events","assignees_url":"https://api.github.com/repos/alisha/hhvm/assignees{/user}","branches_url":"https://api.github.com/repos/alisha/hhvm/branches{/branch}","tags_url":"https://api.github.com/repos/alisha/hhvm/tags","blobs_url":"https://api.github.com/repos/alisha/hhvm/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/alisha/hhvm/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/alisha/hhvm/git/refs{/sha}","trees_url":"https://api.github.com/repos/alisha/hhvm/git/trees{/sha}","statuses_url":"https://api.github.com/repos/alisha/hhvm/statuses/{sha}","languages_url":"https://api.github.com/repos/alisha/hhvm/languages","stargazers_url":"https://api.github.com/repos/alisha/hhvm/stargazers","contributors_url":"https://api.github.com/repos/alisha/hhvm/contributors","subscribers_url":"https://api.github.com/repos/alisha/hhvm/subscribers","subscription_url":"https://api.github.com/repos/alisha/hhvm/subscription","commits_url":"https://api.github.com/repos/alisha/hhvm/commits{/sha}","git_commits_url":"https://api.github.com/repos/alisha/hhvm/git/commits{/sha}","comments_url":"https://api.github.com/repos/alisha/hhvm/comments{/number}","issue_comment_url":"https://api.github.com/repos/alisha/hhvm/issues/comments{/number}","contents_url":"https://api.github.com/repos/alisha/hhvm/contents/{+path}","compare_url":"https://api.github.com/repos/alisha/hhvm/compare/{base}...{head}","merges_url":"https://api.github.com/repos/alisha/hhvm/merges","archive_url":"https://api.github.com/repos/alisha/hhvm/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/alisha/hhvm/downloads","issues_url":"https://api.github.com/repos/alisha/hhvm/issues{/number}","pulls_url":"https://api.github.com/repos/alisha/hhvm/pulls{/number}","milestones_url":"https://api.github.com/repos/alisha/hhvm/milestones{/number}","notifications_url":"https://api.github.com/repos/alisha/hhvm/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/alisha/hhvm/labels{/name}","releases_url":"https://api.github.com/repos/alisha/hhvm/releases{/id}","deployments_url":"https://api.github.com/repos/alisha/hhvm/deployments","created_at":"2018-06-29T23:58:13Z","updated_at":"2018-08-08T04:24:56Z","pushed_at":"2018-08-09T20:19:45Z","git_url":"git://github.com/alisha/hhvm.git","ssh_url":"git@github.com:alisha/hhvm.git","clone_url":"https://github.com/alisha/hhvm.git","svn_url":"https://github.com/alisha/hhvm","homepage":"https://hhvm.com","size":310191,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_projects":true,"has_downloads":false,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"other","name":"Other","spdx_id":null,"url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"facebook:master","ref":"master","sha":"e5f8966df303e7c68ae61b4c1f79c6c1fdee03de","user":{"login":"facebook","id":69631,"node_id":"MDEyOk9yZ2FuaXphdGlvbjY5NjMx","avatar_url":"https://avatars3.githubusercontent.com/u/69631?v=4","gravatar_id":"","url":"https://api.github.com/users/facebook","html_url":"https://github.com/facebook","followers_url":"https://api.github.com/users/facebook/followers","following_url":"https://api.github.com/users/facebook/following{/other_user}","gists_url":"https://api.github.com/users/facebook/gists{/gist_id}","starred_url":"https://api.github.com/users/facebook/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/facebook/subscriptions","organizations_url":"https://api.github.com/users/facebook/orgs","repos_url":"https://api.github.com/users/facebook/repos","events_url":"https://api.github.com/users/facebook/events{/privacy}","received_events_url":"https://api.github.com/users/facebook/received_events","type":"Organization","site_admin":false},"repo":{"id":455600,"node_id":"MDEwOlJlcG9zaXRvcnk0NTU2MDA=","name":"hhvm","full_name":"facebook/hhvm","owner":{"login":"facebook","id":69631,"node_id":"MDEyOk9yZ2FuaXphdGlvbjY5NjMx","avatar_url":"https://avatars3.githubusercontent.com/u/69631?v=4","gravatar_id":"","url":"https://api.github.com/users/facebook","html_url":"https://github.com/facebook","followers_url":"https://api.github.com/users/facebook/followers","following_url":"https://api.github.com/users/facebook/following{/other_user}","gists_url":"https://api.github.com/users/facebook/gists{/gist_id}","starred_url":"https://api.github.com/users/facebook/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/facebook/subscriptions","organizations_url":"https://api.github.com/users/facebook/orgs","repos_url":"https://api.github.com/users/facebook/repos","events_url":"https://api.github.com/users/facebook/events{/privacy}","received_events_url":"https://api.github.com/users/facebook/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/facebook/hhvm","description":"A virtual machine for executing programs written in Hack.","fork":false,"url":"https://api.github.com/repos/facebook/hhvm","forks_url":"https://api.github.com/repos/facebook/hhvm/forks","keys_url":"https://api.github.com/repos/facebook/hhvm/keys{/key_id}","collaborators_url":"https://api.github.com/repos/facebook/hhvm/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/facebook/hhvm/teams","hooks_url":"https://api.github.com/repos/facebook/hhvm/hooks","issue_events_url":"https://api.github.com/repos/facebook/hhvm/issues/events{/number}","events_url":"https://api.github.com/repos/facebook/hhvm/events","assignees_url":"https://api.github.com/repos/facebook/hhvm/assignees{/user}","branches_url":"https://api.github.com/repos/facebook/hhvm/branches{/branch}","tags_url":"https://api.github.com/repos/facebook/hhvm/tags","blobs_url":"https://api.github.com/repos/facebook/hhvm/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/facebook/hhvm/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/facebook/hhvm/git/refs{/sha}","trees_url":"https://api.github.com/repos/facebook/hhvm/git/trees{/sha}","statuses_url":"https://api.github.com/repos/facebook/hhvm/statuses/{sha}","languages_url":"https://api.github.com/repos/facebook/hhvm/languages","stargazers_url":"https://api.github.com/repos/facebook/hhvm/stargazers","contributors_url":"https://api.github.com/repos/facebook/hhvm/contributors","subscribers_url":"https://api.github.com/repos/facebook/hhvm/subscribers","subscription_url":"https://api.github.com/repos/facebook/hhvm/subscription","commits_url":"https://api.github.com/repos/facebook/hhvm/commits{/sha}","git_commits_url":"https://api.github.com/repos/facebook/hhvm/git/commits{/sha}","comments_url":"https://api.github.com/repos/facebook/hhvm/comments{/number}","issue_comment_url":"https://api.github.com/repos/facebook/hhvm/issues/comments{/number}","contents_url":"https://api.github.com/repos/facebook/hhvm/contents/{+path}","compare_url":"https://api.github.com/repos/facebook/hhvm/compare/{base}...{head}","merges_url":"https://api.github.com/repos/facebook/hhvm/merges","archive_url":"https://api.github.com/repos/facebook/hhvm/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/facebook/hhvm/downloads","issues_url":"https://api.github.com/repos/facebook/hhvm/issues{/number}","pulls_url":"https://api.github.com/repos/facebook/hhvm/pulls{/number}","milestones_url":"https://api.github.com/repos/facebook/hhvm/milestones{/number}","notifications_url":"https://api.github.com/repos/facebook/hhvm/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/facebook/hhvm/labels{/name}","releases_url":"https://api.github.com/repos/facebook/hhvm/releases{/id}","deployments_url":"https://api.github.com/repos/facebook/hhvm/deployments","created_at":"2010-01-02T01:17:06Z","updated_at":"2018-08-10T18:13:15Z","pushed_at":"2018-08-10T18:13:03Z","git_url":"git://github.com/facebook/hhvm.git","ssh_url":"git@github.com:facebook/hhvm.git","clone_url":"https://github.com/facebook/hhvm.git","svn_url":"https://github.com/facebook/hhvm","homepage":"https://hhvm.com","size":311996,"stargazers_count":15464,"watchers_count":15464,"language":"C++","has_issues":true,"has_projects":true,"has_downloads":false,"has_wiki":true,"has_pages":false,"forks_count":2778,"mirror_url":null,"archived":false,"open_issues_count":823,"license":{"key":"other","name":"Other","spdx_id":null,"url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":2778,"open_issues":823,"watchers":15464,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/facebook/hhvm/pulls/8277"},"html":{"href":"https://github.com/facebook/hhvm/pull/8277"},"issue":{"href":"https://api.github.com/repos/facebook/hhvm/issues/8277"},"comments":{"href":"https://api.github.com/repos/facebook/hhvm/issues/8277/comments"},"review_comments":{"href":"https://api.github.com/repos/facebook/hhvm/pulls/8277/comments"},"review_comment":{"href":"https://api.github.com/repos/facebook/hhvm/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/facebook/hhvm/pulls/8277/commits"},"statuses":{"href":"https://api.github.com/repos/facebook/hhvm/statuses/2d06b44d8e2b79df61d30437ef823ab420f48e6c"}},"author_association":"NONE"}}
{"actor":{"display_login":"rjbailey"}}