Skip to content

Commit f4e5967

Browse files
committed
Merge pull request airbnb#547 from chrisngobanh/padded-blocks
Prohibit Padded Blocks and Allow Comments in the First Line of a Block
2 parents 7b0ff12 + 4b5348a commit f4e5967

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

README.md

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1248,7 +1248,7 @@ Other Style Guides
12481248
}
12491249
```
12501250
1251-
- [17.2](#17.2) <a name='17.2'></a> Use `//` for single line comments. Place single line comments on a newline above the subject of the comment. Put an empty line before the comment.
1251+
- [17.2](#17.2) <a name='17.2'></a> Use `//` for single line comments. Place single line comments on a newline above the subject of the comment. Put an empty line before the comment unless it's on the first line of a block.
12521252

12531253
```javascript
12541254
// bad
@@ -1276,6 +1276,14 @@ Other Style Guides
12761276
12771277
return type;
12781278
}
1279+
1280+
// also good
1281+
function getType() {
1282+
// set the default type to 'no type'
1283+
const type = this._type || 'no type';
1284+
1285+
return type;
1286+
}
12791287
```
12801288

12811289
- [17.3](#17.3) <a name='17.3'></a> Prefixing your comments with `FIXME` or `TODO` helps other developers quickly understand if you're pointing out a problem that needs to be revisited, or if you're suggesting a solution to the problem that needs to be implemented. These are different than regular comments because they are actionable. The actions are `FIXME -- need to figure this out` or `TODO -- need to implement`.
@@ -1511,6 +1519,38 @@ Other Style Guides
15111519
return arr;
15121520
```
15131521
1522+
- [18.8](#18.8) <a name='18.8'></a> Do not pad your blocks with blank lines.
1523+
1524+
```javascript
1525+
// bad
1526+
function bar() {
1527+
1528+
console.log(foo);
1529+
1530+
}
1531+
1532+
// also bad
1533+
if (baz) {
1534+
1535+
console.log(qux);
1536+
} else {
1537+
console.log(foo);
1538+
1539+
}
1540+
1541+
// good
1542+
function bar() {
1543+
console.log(foo);
1544+
}
1545+
1546+
// good
1547+
if (baz) {
1548+
console.log(qux);
1549+
} else {
1550+
console.log(foo);
1551+
}
1552+
```
1553+
15141554
15151555
**[⬆ back to top](#table-of-contents)**
15161556

0 commit comments

Comments
 (0)