{"action":"created","comment":{"url":"https://api.github.com/repos/scala-js/scala-js/pulls/comments/32352198","id":32352198,"diff_hunk":"@@ -0,0 +1,335 @@\n+# Coding Style Guide\n+\n+The Scala.js project has pretty drastic rules in terms of coding style.\n+This document tries to document them as much as possible.\n+\n+A *few* of these rules are checked automatically using Scalastyle, but most of them are too complex to teach to an automated tool.\n+\n+In some cases, [@sjrd](https://github.com/sjrd) will just say something else on a code review.\n+His opinion on a direct piece of code always takes precedence over this document.\n+Feel free to point out the conflict, though: the document can be improved.\n+\n+\n+## General style (whitespaces, braces, etc.)\n+\n+### Tabs, new lines, and eofs\n+\n+* Files must not contain tabs\n+* New lines are UNIX style (\\n)\n+* A final new line must be present at the end of file\n+* There must not be whitespace characters at the end of a line\n+\n+### Line length\n+\n+Lines should be limited at 80 characters.\n+In some cases, if breaking a line makes it significantly less readable, it can go up to 120 characters.\n+\n+Rationale: when reviewing on GitHub, only 120 characters are visible; when reviewing on a mobile phone, only 80 characters are visible.\n+And we do review on mobile phone quite a lot.\n+\n+#### Where to break a line\n+\n+A line can be broken after either a `,` or a `(`, or possibly after a binary operator in a long expression.\n+\n+### Indentation\n+\n+In general, indentation is 2 spaces, except continuation lines, which are indented 4 spaces.\n+A continuation line is a line appearing because we broke something that should have been on one line for line length reasons.\n+Typically, this means inside parentheses (formal or actual parameters of methods and constructors), and a long `extends` clause.\n+\n+Note that breaking a line right after the `=` sign of an initialization or assignment is *not* considered a continuation line.\n+\n+### Blank lines\n+\n+* Never put two blank lines in a row\n+* (Almost) always put a blank line between two declarations in a class (exceptions are several related consecutive ScalaDocless private fields)\n+* Always put blank lines around a `case` whose body spans several lines\n+* Insert blank lines at will between logical blocks of statements in a method\n+\n+### Braces\n+\n+Braces should not be used for one-liner methods, nor for two-liner `if/else` methods.\n+Similarly, you should not use braces for the body of a `while`/`if`/`for` that is a one-liner (but you should if it is a two-liner `if/else`).\n+\n+```scala\n+def abs(x: Int): Int =\n+  if (x >= 0) x\n+  else -x\n+\n+def clamp(v: Int, min: Int, max: Int): Int = {\n+  if (v < min) min\n+  else if (v > max) max\n+  else v\n+}\n+```\n+\n+Every expression that spans more than one line should be enclosed in braces.\n+For example, this is wrong:\n+\n+```scala\n+val iterator =\n+  new Iterator[A] {\n+    ...\n+  }\n+```\n+\n+It should be:\n+\n+```scala\n+val iterator = {\n+  new Iterator[A] {\n+    ...\n+  }\n+}\n+```\n+\n+#### Braces in lambdas\n+\n+In lambdas (anonymous functions), the opening brace must be placed before the formal arguments, and not after the `=>`:\n+\n+```scala\n+val f = { (x: Int) =>\n+  body\n+}\n+```\n+\n+### Spaces\n+\n+There must not be any space before the following tokens: `: , ; )`\n+\n+There must be exactly one space after the following tokens: `: , ; if for while`\n+Sometimes, it is acceptable to have several spaces, for vertical alignment reasons.\n+\n+There must be exactly one space before and after `{` and `}`.\n+With the exception of partial import, where there is no space on either side.\n+\n+Binary operators, including `=>`, must have a single space on both sides.\n+Sometimes, spaces can be removed to highlight the relatively higher priority wrt. to a neighboring operator, for easier visual parsing.\n+For example, instead of `x < len - 1`, it is better to write `x < len-1`, highlighting that `-` has a higher priority than `<`.\n+\n+Unary operators must not be followed by a space.\n+\n+### Method call style\n+\n+Usually, parentheses should be used for actual parameters to a method call.\n+Braces should be used instead if an argument list has only a lambda, and that lambda does not fit in an inline one-liner.\n+\n+In general, dot-notation should be used for non-symbolic methods, and infix notation should be used for symbolic methods.\n+Infix notation is also used if the only argument is a brace lambda.\n+\n+Examples:\n+\n+```scala\n+// inline lambda, hence (), hence dot-notation\n+list.map(x => x * 2)\n+\n+// long lambda, hence braces, hence infix notation\n+list map { x =>\n+  if (x < 5) x\n+  else x * 2\n+}\n+\n+// symbolic operator, hence infix notation\n+value :: list\n+```\n+\n+When calling a method declared with an empty pair of parentheses, use `()`, except if the method is Java-defined *and* does not have side-effects.\n+\n+### Method definition\n+\n+All public and protected methods must have an explicit result type.\n+\n+Procedure syntax must not be used. `: Unit =` must be used instead.\n+\n+Side-effect-free methods without formal parameters should be declared without `()`, unless either a) it overrides a methode defined with `()` (such as `toString()`) or b) it implements a Java method in the Java libraries.\n+\n+### for comprehensions\n+\n+For-comprehensions must use `()` if they have a single generator without `if`, such as:\n+\n+```scala\n+for (i <- 0 until n)\n+  doStuff(i)\n+```\n+\n+Otherwise, it must use `{}`, and there must be one generator per line.\n+The body of the `for` is then automatically surrounding by braces too, even if it is a one-liner:","path":"CODINGSTYLE.md","position":156,"original_position":156,"commit_id":"3b8fdc0e100fdcf2843a7bd2e8ca402d025d1734","original_commit_id":"3b8fdc0e100fdcf2843a7bd2e8ca402d025d1734","user":{"login":"sjrd","id":535934,"avatar_url":"https://avatars.githubusercontent.com/u/535934?v=3","gravatar_id":"","url":"https://api.github.com/users/sjrd","html_url":"https://github.com/sjrd","followers_url":"https://api.github.com/users/sjrd/followers","following_url":"https://api.github.com/users/sjrd/following{/other_user}","gists_url":"https://api.github.com/users/sjrd/gists{/gist_id}","starred_url":"https://api.github.com/users/sjrd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sjrd/subscriptions","organizations_url":"https://api.github.com/users/sjrd/orgs","repos_url":"https://api.github.com/users/sjrd/repos","events_url":"https://api.github.com/users/sjrd/events{/privacy}","received_events_url":"https://api.github.com/users/sjrd/received_events","type":"User","site_admin":false},"body":"OK","created_at":"2015-06-12T20:30:30Z","updated_at":"2015-06-12T20:30:30Z","html_url":"https://github.com/scala-js/scala-js/pull/1716#discussion_r32352198","pull_request_url":"https://api.github.com/repos/scala-js/scala-js/pulls/1716","_links":{"self":{"href":"https://api.github.com/repos/scala-js/scala-js/pulls/comments/32352198"},"html":{"href":"https://github.com/scala-js/scala-js/pull/1716#discussion_r32352198"},"pull_request":{"href":"https://api.github.com/repos/scala-js/scala-js/pulls/1716"}}},"pull_request":{"url":"https://api.github.com/repos/scala-js/scala-js/pulls/1716","id":37578130,"html_url":"https://github.com/scala-js/scala-js/pull/1716","diff_url":"https://github.com/scala-js/scala-js/pull/1716.diff","patch_url":"https://github.com/scala-js/scala-js/pull/1716.patch","issue_url":"https://api.github.com/repos/scala-js/scala-js/issues/1716","number":1716,"state":"open","locked":false,"title":"Fix #1644: Document the coding style.","user":{"login":"sjrd","id":535934,"avatar_url":"https://avatars.githubusercontent.com/u/535934?v=3","gravatar_id":"","url":"https://api.github.com/users/sjrd","html_url":"https://github.com/sjrd","followers_url":"https://api.github.com/users/sjrd/followers","following_url":"https://api.github.com/users/sjrd/following{/other_user}","gists_url":"https://api.github.com/users/sjrd/gists{/gist_id}","starred_url":"https://api.github.com/users/sjrd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sjrd/subscriptions","organizations_url":"https://api.github.com/users/sjrd/orgs","repos_url":"https://api.github.com/users/sjrd/repos","events_url":"https://api.github.com/users/sjrd/events{/privacy}","received_events_url":"https://api.github.com/users/sjrd/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-06-12T15:59:30Z","updated_at":"2015-06-12T20:30:30Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2c7d4abe3c58103867adfcc5ed3646f75a025a93","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/scala-js/scala-js/pulls/1716/commits","review_comments_url":"https://api.github.com/repos/scala-js/scala-js/pulls/1716/comments","review_comment_url":"https://api.github.com/repos/scala-js/scala-js/pulls/comments{/number}","comments_url":"https://api.github.com/repos/scala-js/scala-js/issues/1716/comments","statuses_url":"https://api.github.com/repos/scala-js/scala-js/statuses/3b8fdc0e100fdcf2843a7bd2e8ca402d025d1734","head":{"label":"sjrd:codingstyle","ref":"codingstyle","sha":"3b8fdc0e100fdcf2843a7bd2e8ca402d025d1734","user":{"login":"sjrd","id":535934,"avatar_url":"https://avatars.githubusercontent.com/u/535934?v=3","gravatar_id":"","url":"https://api.github.com/users/sjrd","html_url":"https://github.com/sjrd","followers_url":"https://api.github.com/users/sjrd/followers","following_url":"https://api.github.com/users/sjrd/following{/other_user}","gists_url":"https://api.github.com/users/sjrd/gists{/gist_id}","starred_url":"https://api.github.com/users/sjrd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sjrd/subscriptions","organizations_url":"https://api.github.com/users/sjrd/orgs","repos_url":"https://api.github.com/users/sjrd/repos","events_url":"https://api.github.com/users/sjrd/events{/privacy}","received_events_url":"https://api.github.com/users/sjrd/received_events","type":"User","site_admin":false},"repo":{"id":8660284,"name":"scala-js","full_name":"sjrd/scala-js","owner":{"login":"sjrd","id":535934,"avatar_url":"https://avatars.githubusercontent.com/u/535934?v=3","gravatar_id":"","url":"https://api.github.com/users/sjrd","html_url":"https://github.com/sjrd","followers_url":"https://api.github.com/users/sjrd/followers","following_url":"https://api.github.com/users/sjrd/following{/other_user}","gists_url":"https://api.github.com/users/sjrd/gists{/gist_id}","starred_url":"https://api.github.com/users/sjrd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sjrd/subscriptions","organizations_url":"https://api.github.com/users/sjrd/orgs","repos_url":"https://api.github.com/users/sjrd/repos","events_url":"https://api.github.com/users/sjrd/events{/privacy}","received_events_url":"https://api.github.com/users/sjrd/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/sjrd/scala-js","description":"Scala.js, a Scala to JavaScript compiler","fork":true,"url":"https://api.github.com/repos/sjrd/scala-js","forks_url":"https://api.github.com/repos/sjrd/scala-js/forks","keys_url":"https://api.github.com/repos/sjrd/scala-js/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sjrd/scala-js/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sjrd/scala-js/teams","hooks_url":"https://api.github.com/repos/sjrd/scala-js/hooks","issue_events_url":"https://api.github.com/repos/sjrd/scala-js/issues/events{/number}","events_url":"https://api.github.com/repos/sjrd/scala-js/events","assignees_url":"https://api.github.com/repos/sjrd/scala-js/assignees{/user}","branches_url":"https://api.github.com/repos/sjrd/scala-js/branches{/branch}","tags_url":"https://api.github.com/repos/sjrd/scala-js/tags","blobs_url":"https://api.github.com/repos/sjrd/scala-js/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sjrd/scala-js/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sjrd/scala-js/git/refs{/sha}","trees_url":"https://api.github.com/repos/sjrd/scala-js/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sjrd/scala-js/statuses/{sha}","languages_url":"https://api.github.com/repos/sjrd/scala-js/languages","stargazers_url":"https://api.github.com/repos/sjrd/scala-js/stargazers","contributors_url":"https://api.github.com/repos/sjrd/scala-js/contributors","subscribers_url":"https://api.github.com/repos/sjrd/scala-js/subscribers","subscription_url":"https://api.github.com/repos/sjrd/scala-js/subscription","commits_url":"https://api.github.com/repos/sjrd/scala-js/commits{/sha}","git_commits_url":"https://api.github.com/repos/sjrd/scala-js/git/commits{/sha}","comments_url":"https://api.github.com/repos/sjrd/scala-js/comments{/number}","issue_comment_url":"https://api.github.com/repos/sjrd/scala-js/issues/comments{/number}","contents_url":"https://api.github.com/repos/sjrd/scala-js/contents/{+path}","compare_url":"https://api.github.com/repos/sjrd/scala-js/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sjrd/scala-js/merges","archive_url":"https://api.github.com/repos/sjrd/scala-js/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sjrd/scala-js/downloads","issues_url":"https://api.github.com/repos/sjrd/scala-js/issues{/number}","pulls_url":"https://api.github.com/repos/sjrd/scala-js/pulls{/number}","milestones_url":"https://api.github.com/repos/sjrd/scala-js/milestones{/number}","notifications_url":"https://api.github.com/repos/sjrd/scala-js/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sjrd/scala-js/labels{/name}","releases_url":"https://api.github.com/repos/sjrd/scala-js/releases{/id}","created_at":"2013-03-08T21:32:59Z","updated_at":"2015-05-06T16:26:13Z","pushed_at":"2015-06-12T15:59:07Z","git_url":"git://github.com/sjrd/scala-js.git","ssh_url":"git@github.com:sjrd/scala-js.git","clone_url":"https://github.com/sjrd/scala-js.git","svn_url":"https://github.com/sjrd/scala-js","homepage":"http://www.scala-js.org/","size":13081,"stargazers_count":11,"watchers_count":11,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":0,"forks":1,"open_issues":0,"watchers":11,"default_branch":"master"}},"base":{"label":"scala-js:master","ref":"master","sha":"a08d5c509b586d60cbbd1f668e3ba91393696937","user":{"login":"scala-js","id":6039724,"avatar_url":"https://avatars.githubusercontent.com/u/6039724?v=3","gravatar_id":"","url":"https://api.github.com/users/scala-js","html_url":"https://github.com/scala-js","followers_url":"https://api.github.com/users/scala-js/followers","following_url":"https://api.github.com/users/scala-js/following{/other_user}","gists_url":"https://api.github.com/users/scala-js/gists{/gist_id}","starred_url":"https://api.github.com/users/scala-js/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scala-js/subscriptions","organizations_url":"https://api.github.com/users/scala-js/orgs","repos_url":"https://api.github.com/users/scala-js/repos","events_url":"https://api.github.com/users/scala-js/events{/privacy}","received_events_url":"https://api.github.com/users/scala-js/received_events","type":"Organization","site_admin":false},"repo":{"id":8272315,"name":"scala-js","full_name":"scala-js/scala-js","owner":{"login":"scala-js","id":6039724,"avatar_url":"https://avatars.githubusercontent.com/u/6039724?v=3","gravatar_id":"","url":"https://api.github.com/users/scala-js","html_url":"https://github.com/scala-js","followers_url":"https://api.github.com/users/scala-js/followers","following_url":"https://api.github.com/users/scala-js/following{/other_user}","gists_url":"https://api.github.com/users/scala-js/gists{/gist_id}","starred_url":"https://api.github.com/users/scala-js/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scala-js/subscriptions","organizations_url":"https://api.github.com/users/scala-js/orgs","repos_url":"https://api.github.com/users/scala-js/repos","events_url":"https://api.github.com/users/scala-js/events{/privacy}","received_events_url":"https://api.github.com/users/scala-js/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/scala-js/scala-js","description":"Scala.js, the Scala to JavaScript compiler","fork":false,"url":"https://api.github.com/repos/scala-js/scala-js","forks_url":"https://api.github.com/repos/scala-js/scala-js/forks","keys_url":"https://api.github.com/repos/scala-js/scala-js/keys{/key_id}","collaborators_url":"https://api.github.com/repos/scala-js/scala-js/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/scala-js/scala-js/teams","hooks_url":"https://api.github.com/repos/scala-js/scala-js/hooks","issue_events_url":"https://api.github.com/repos/scala-js/scala-js/issues/events{/number}","events_url":"https://api.github.com/repos/scala-js/scala-js/events","assignees_url":"https://api.github.com/repos/scala-js/scala-js/assignees{/user}","branches_url":"https://api.github.com/repos/scala-js/scala-js/branches{/branch}","tags_url":"https://api.github.com/repos/scala-js/scala-js/tags","blobs_url":"https://api.github.com/repos/scala-js/scala-js/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/scala-js/scala-js/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/scala-js/scala-js/git/refs{/sha}","trees_url":"https://api.github.com/repos/scala-js/scala-js/git/trees{/sha}","statuses_url":"https://api.github.com/repos/scala-js/scala-js/statuses/{sha}","languages_url":"https://api.github.com/repos/scala-js/scala-js/languages","stargazers_url":"https://api.github.com/repos/scala-js/scala-js/stargazers","contributors_url":"https://api.github.com/repos/scala-js/scala-js/contributors","subscribers_url":"https://api.github.com/repos/scala-js/scala-js/subscribers","subscription_url":"https://api.github.com/repos/scala-js/scala-js/subscription","commits_url":"https://api.github.com/repos/scala-js/scala-js/commits{/sha}","git_commits_url":"https://api.github.com/repos/scala-js/scala-js/git/commits{/sha}","comments_url":"https://api.github.com/repos/scala-js/scala-js/comments{/number}","issue_comment_url":"https://api.github.com/repos/scala-js/scala-js/issues/comments{/number}","contents_url":"https://api.github.com/repos/scala-js/scala-js/contents/{+path}","compare_url":"https://api.github.com/repos/scala-js/scala-js/compare/{base}...{head}","merges_url":"https://api.github.com/repos/scala-js/scala-js/merges","archive_url":"https://api.github.com/repos/scala-js/scala-js/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/scala-js/scala-js/downloads","issues_url":"https://api.github.com/repos/scala-js/scala-js/issues{/number}","pulls_url":"https://api.github.com/repos/scala-js/scala-js/pulls{/number}","milestones_url":"https://api.github.com/repos/scala-js/scala-js/milestones{/number}","notifications_url":"https://api.github.com/repos/scala-js/scala-js/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/scala-js/scala-js/labels{/name}","releases_url":"https://api.github.com/repos/scala-js/scala-js/releases{/id}","created_at":"2013-02-18T16:33:55Z","updated_at":"2015-06-12T05:31:54Z","pushed_at":"2015-06-12T20:07:07Z","git_url":"git://github.com/scala-js/scala-js.git","ssh_url":"git@github.com:scala-js/scala-js.git","clone_url":"https://github.com/scala-js/scala-js.git","svn_url":"https://github.com/scala-js/scala-js","homepage":"http://www.scala-js.org/","size":15888,"stargazers_count":1711,"watchers_count":1711,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":145,"mirror_url":null,"open_issues_count":60,"forks":145,"open_issues":60,"watchers":1711,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/scala-js/scala-js/pulls/1716"},"html":{"href":"https://github.com/scala-js/scala-js/pull/1716"},"issue":{"href":"https://api.github.com/repos/scala-js/scala-js/issues/1716"},"comments":{"href":"https://api.github.com/repos/scala-js/scala-js/issues/1716/comments"},"review_comments":{"href":"https://api.github.com/repos/scala-js/scala-js/pulls/1716/comments"},"review_comment":{"href":"https://api.github.com/repos/scala-js/scala-js/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/scala-js/scala-js/pulls/1716/commits"},"statuses":{"href":"https://api.github.com/repos/scala-js/scala-js/statuses/3b8fdc0e100fdcf2843a7bd2e8ca402d025d1734"}}}}