Skip to content

Commit

Permalink
Go with GM styled comment requirement of // fallthrough syntax inst…
Browse files Browse the repository at this point in the history
…ead of curly braces.

* Apply some more of the styleguide to the STYLEGUIDE.md
* Clarify in notation that sometimes a `switch` may not always be the best option for readabilty in some cases.
* Leaving the choice of curly braces up to each contributor for the time being. Code folding is nice but ususally `switch` isn't that complex enough to need that.

Applies to OpenUserJS#245 and OpenUserJS#19
  • Loading branch information
Martii committed Jul 8, 2014
1 parent 6eba4d9 commit 5e993ae
Showing 1 changed file with 29 additions and 25 deletions.
54 changes: 29 additions & 25 deletions STYLEGUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,21 +201,21 @@ The `if` class of statements should have the following form:

```javascript
if (condition) {
// statements
/* statements */
}

if (condition) {
// statements
/* statements */
} else {
// statements
/* statements */
}

if (condition) {
// statements
/* statements */
} else if (condition) {
// statements
/* statements */
} else {
// statements
/* statements */
}
```

Expand All @@ -225,12 +225,12 @@ A for class of statements should have the following form:

```javascript
for (initialization; condition; update) {
// statements
/* statements */
}

for (variable in object) {
if (filter) {
// statements
/* statements */
}
}
```
Expand All @@ -246,7 +246,7 @@ A `while` statement should have the following form:

```javascript
while (condition) {
// statements
/* statements */
}
```

Expand All @@ -256,7 +256,7 @@ A `do` statement should have the following form:

```javascript
do {
// statements
/* statements */
} while (condition);
```

Expand All @@ -268,37 +268,41 @@ A `switch` statement should have the following form:

```javascript
switch (expression) {
case expression1:
case expression2:
case expressionNth: {
// statements
break;
}
default: {
// statements
}
case expression1:
/* statements */
// fallthrough
case expression2:
/* previously declared `// fallthrough` statements */
break;
case expression3:
case expression4:
case expressionNth:
/* statements */
break;
default:
/* default statements */
}
```

Each group of statements *(except the default)* should end with `break`, `return`, or `throw`. **Complex conditionaling may be better described if there are no fall throughs. In these cases it may be preferred to use an `if...else` syntax for readability** Curly braces are used only for code folding in some editors and can be used as a visual aid to ensure that `break` is included in a pull request.
Each logical grouping of statements *(except the default)* should end with `// fallthrough`, `break`, `return`, or `throw`. **NOTE: Complex conditionaling may sometimes be better described with an `if...else` or other ECMAScript syntax for readability purposes.**

#### try Statement

The `try` class of statements should have the following form:

```javascript
try {
// statements
/* statements */
} catch (variable) {
// statements
/* statements */
}

try {
// statements
/* statements */
} catch (variable) {
// statements
/* statements */
} finally {
// statements
/* statements */
}
```

Expand Down

0 comments on commit 5e993ae

Please sign in to comment.