Skip to content

Commit 261f3bb

Browse files
committed
Merge pull request airbnb#329 from airbnb/es6-trailing-commas
es6 additional trailing commas
2 parents fc248e6 + 2521d46 commit 261f3bb

File tree

1 file changed

+51
-49
lines changed

1 file changed

+51
-49
lines changed

README.md

Lines changed: 51 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -189,15 +189,15 @@
189189
// bad
190190
const obj = {
191191
id: 5,
192-
name: 'San Francisco'
192+
name: 'San Francisco',
193193
};
194194
obj[getKey('enabled')] = true;
195195
196196
// good
197197
const obj = {
198198
id: 5,
199199
name: 'San Francisco',
200-
[getKey('enabled')]: true
200+
[getKey('enabled')]: true,
201201
};
202202
```
203203

@@ -211,7 +211,7 @@
211211
212212
addValue: function (value) {
213213
return atom.value + value;
214-
}
214+
},
215215
};
216216
217217
// good
@@ -220,7 +220,7 @@
220220
221221
addValue(value) {
222222
return atom.value + value;
223-
}
223+
},
224224
};
225225
```
226226

@@ -258,7 +258,7 @@
258258
lukeSkywalker,
259259
episodeThree: 3,
260260
mayTheFourth: 4,
261-
anakinSkywalker
261+
anakinSkywalker,
262262
};
263263
264264
// good
@@ -268,7 +268,7 @@
268268
episodeOne: 1,
269269
twoJedisWalkIntoACantina: 2,
270270
episodeThree: 3,
271-
mayTheFourth: 4
271+
mayTheFourth: 4,
272272
};
273273
```
274274
@@ -397,10 +397,10 @@
397397
398398
```javascript
399399
// bad
400-
const name = "Bob Parr";
400+
const name = "Capt. Janeway";
401401
402402
// good
403-
const name = 'Bob Parr';
403+
const name = 'Capt. Janeway';
404404
```
405405
406406
- Strings longer than 80 characters should be written across multiple lines using string concatenation.
@@ -809,7 +809,7 @@
809809
sum === 15;
810810
```
811811
812-
- Don't use generators.
812+
- Don't use generators for now.
813813
814814
> Why? They don't transpile well to ES5.
815815
@@ -823,7 +823,7 @@
823823
```javascript
824824
const luke = {
825825
jedi: true,
826-
age: 28
826+
age: 28,
827827
};
828828

829829
// bad
@@ -838,7 +838,7 @@
838838
```javascript
839839
const luke = {
840840
jedi: true,
841-
age: 28
841+
age: 28,
842842
};
843843

844844
function getProp(prop) {
@@ -1225,24 +1225,26 @@
12251225
- Use `// FIXME:` to annotate problems.
12261226

12271227
```javascript
1228-
function Calculator() {
1228+
class Calculator {
1229+
constructor() {
1230+
// FIXME: shouldn't use a global here
1231+
total = 0;
12291232
1230-
// FIXME: shouldn't use a global here
1231-
total = 0;
1232-
1233-
return this;
1233+
return this;
1234+
}
12341235
}
12351236
```
12361237

12371238
- Use `// TODO:` to annotate solutions to problems.
12381239

12391240
```javascript
1240-
function Calculator() {
1241-
1242-
// TODO: total should be configurable by an options param
1243-
this.total = 0;
1241+
class Calculator {
1242+
constructor() {
1243+
// TODO: total should be configurable by an options param
1244+
this.total = 0;
12441245
1245-
return this;
1246+
return this;
1247+
}
12461248
}
12471249
```
12481250

@@ -1412,20 +1414,20 @@
14121414

14131415
// bad
14141416
const obj = {
1415-
foo: function() {
1417+
foo() {
1418+
},
1419+
bar() {
14161420
},
1417-
bar: function() {
1418-
}
14191421
};
14201422
return obj;
14211423

14221424
// good
14231425
const obj = {
1424-
foo: function() {
1426+
foo() {
14251427
},
14261428

1427-
bar: function() {
1428-
}
1429+
bar() {
1430+
},
14291431
};
14301432

14311433
return obj;
@@ -1450,23 +1452,23 @@
14501452
const story = [
14511453
once,
14521454
upon,
1453-
aTime
1455+
aTime,
14541456
];
14551457

14561458
// bad
14571459
const hero = {
1458-
firstName: 'Bob'
1459-
, lastName: 'Parr'
1460-
, heroName: 'Mr. Incredible'
1461-
, superPower: 'strength'
1460+
firstName: 'Ada'
1461+
, lastName: 'Lovelace'
1462+
, birthYear: 1815
1463+
, superPower: 'computers'
14621464
};
14631465

14641466
// good
14651467
const hero = {
1466-
firstName: 'Bob',
1467-
lastName: 'Parr',
1468-
heroName: 'Mr. Incredible',
1469-
superPower: 'strength'
1468+
firstName: 'Ada',
1469+
lastName: 'Lovelace',
1470+
birthYear: 1815,
1471+
superPower: 'computers',
14701472
};
14711473
```
14721474
@@ -1477,23 +1479,23 @@
14771479
```javascript
14781480
// bad - git diff without trailing comma
14791481
const hero = {
1480-
firstName: 'Bob',
1481-
- lastName: 'Parr'
1482-
+ lastName: 'Parr',
1483-
+ heroName: 'Mr. Incredible'
1482+
firstName: 'Florence',
1483+
- lastName: 'Nightingale'
1484+
+ lastName: 'Nightingale',
1485+
+ inventorOf: ['coxcomb graph', 'mordern nursing']
14841486
}
14851487

14861488
// good - git diff with trailing comma
14871489
const hero = {
1488-
firstName: 'Bob',
1489-
lastName: 'Parr',
1490-
+ heroName: 'Mr. Incredible',
1490+
firstName: 'Florence',
1491+
lastName: 'Nightingale',
1492+
+ inventorOf: ['coxcomb chart', 'mordern nursing'],
14911493
}
14921494

14931495
// bad
14941496
const hero = {
1495-
firstName: 'Kevin',
1496-
lastName: 'Flynn'
1497+
firstName: 'Dana',
1498+
lastName: 'Scully'
14971499
};
14981500

14991501
const heroes = [
@@ -1503,8 +1505,8 @@
15031505

15041506
// good
15051507
const hero = {
1506-
firstName: 'Kevin',
1507-
lastName: 'Flynn',
1508+
firstName: 'Dana',
1509+
lastName: 'Scully',
15081510
};
15091511

15101512
const heroes = [
@@ -1660,7 +1662,7 @@
16601662
}
16611663

16621664
const bad = new user({
1663-
name: 'nope'
1665+
name: 'nope',
16641666
});
16651667

16661668
// good
@@ -1671,7 +1673,7 @@
16711673
}
16721674

16731675
const good = new User({
1674-
name: 'yup'
1676+
name: 'yup',
16751677
});
16761678
```
16771679

0 commit comments

Comments
 (0)