mirror of
https://github.com/airbnb/javascript.git
synced 2026-01-13 16:47:55 -05:00
Merge pull request #547 from chrisngobanh/padded-blocks
Prohibit Padded Blocks and Allow Comments in the First Line of a Block
This commit is contained in:
42
README.md
42
README.md
@@ -1248,7 +1248,7 @@ Other Style Guides
|
||||
}
|
||||
```
|
||||
|
||||
- [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.
|
||||
- [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.
|
||||
|
||||
```javascript
|
||||
// bad
|
||||
@@ -1276,6 +1276,14 @@ Other Style Guides
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
// also good
|
||||
function getType() {
|
||||
// set the default type to 'no type'
|
||||
const type = this._type || 'no type';
|
||||
|
||||
return type;
|
||||
}
|
||||
```
|
||||
|
||||
- [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
|
||||
return arr;
|
||||
```
|
||||
|
||||
- [18.8](#18.8) <a name='18.8'></a> Do not pad your blocks with blank lines.
|
||||
|
||||
```javascript
|
||||
// bad
|
||||
function bar() {
|
||||
|
||||
console.log(foo);
|
||||
|
||||
}
|
||||
|
||||
// also bad
|
||||
if (baz) {
|
||||
|
||||
console.log(qux);
|
||||
} else {
|
||||
console.log(foo);
|
||||
|
||||
}
|
||||
|
||||
// good
|
||||
function bar() {
|
||||
console.log(foo);
|
||||
}
|
||||
|
||||
// good
|
||||
if (baz) {
|
||||
console.log(qux);
|
||||
} else {
|
||||
console.log(foo);
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
**[⬆ back to top](#table-of-contents)**
|
||||
|
||||
|
||||
Reference in New Issue
Block a user