You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Immediate evaluation prevents a template being stored in a variable. Token syntax is fixed. Whitespace sensitivity causes alignment issues, especially within nested code blocks.
816
+
817
+
##### Notes
818
+
819
+
*Afunction which performs string concatenation is equivalently effective.
820
+
821
+
##### Enforcement
822
+
823
+
TODO: ESLint rule. Code review.
824
+
825
+
<!-- </rule> -->
826
+
809
827
<!-- </rule-set> -->
810
828
811
829
@@ -1092,6 +1110,45 @@ TODO: ESLint rule
1092
1110
1093
1111
<!-- <rule> -->
1094
1112
1113
+
<!-- <rule> -->
1114
+
1115
+
### R: No object literal shorthand
1116
+
1117
+
##### Reason
1118
+
1119
+
Unnecessary syntactic sugar. In complex objects, shorthand notation decreases readability. Prefer making key-value pairs explicit.
1120
+
1121
+
##### Bad Example
1122
+
1123
+
```javascript
1124
+
var foo ='beep';
1125
+
var x =true;
1126
+
var y =10;
1127
+
1128
+
var obj = { foo, 'baz':'boop', x, y };
1129
+
```
1130
+
1131
+
##### Good Example
1132
+
1133
+
```javascript
1134
+
var foo ='beep';
1135
+
var x =true;
1136
+
var y =10;
1137
+
1138
+
var obj = {
1139
+
'foo': foo,
1140
+
'baz':'boop',
1141
+
'x': x,
1142
+
'y': y
1143
+
};
1144
+
```
1145
+
1146
+
##### Enforcement
1147
+
1148
+
TODO: ESLint rule. Code review.
1149
+
1150
+
<!-- </rule> -->
1151
+
1095
1152
<!-- <rule-set> -->
1096
1153
1097
1154
@@ -1301,11 +1358,11 @@ TODO: ESLint rule
1301
1358
1302
1359
<!-- <rule> -->
1303
1360
1304
-
### R: Enclosed function below return statement
1361
+
### R: Enclosed functions below return statement
1305
1362
1306
1363
##### Reason
1307
1364
1308
-
Reduces noise when first attempting understand implementation flow, especially if enclosed functions are documented.
1365
+
Reduces noise when first attempting to understand implementation flow, especially if enclosed functions are documented.
1309
1366
1310
1367
##### Bad Example
1311
1368
@@ -1374,7 +1431,7 @@ TODO: ESLint rule
1374
1431
1375
1432
##### Reason
1376
1433
1377
-
Avoids unnecessary `function` calls introduce additional overhead and, often, functional counterparts do not save space, a frequently cited benefit.
1434
+
Function calls introduce additional overhead and, often, functional counterparts do not save space, a frequently cited benefit.
1378
1435
1379
1436
##### Bad Example
1380
1437
@@ -1512,6 +1569,20 @@ request({
1512
1569
* If no errors; the `error` argument should be `null`.
1513
1570
1514
1571
1572
+
##### Enforcement
1573
+
1574
+
Code review.
1575
+
1576
+
<!-- </rule> -->
1577
+
1578
+
<!-- <rule> -->
1579
+
1580
+
### R: No promises
1581
+
1582
+
##### Reason
1583
+
1584
+
Error handling in `promises` is ill-defined. These primitives originated primarily due to poor coding practices when using callbacks rather than out of existential need.
1585
+
1515
1586
##### Enforcement
1516
1587
1517
1588
Code review.
@@ -1647,7 +1718,7 @@ function fcn() {
1647
1718
##### Good Example
1648
1719
1649
1720
```javascript
1650
-
// Do:
1721
+
// Do...
1651
1722
functionfcn() {
1652
1723
var nargs =arguments.length;
1653
1724
var args =newArray( nargs );
@@ -1730,62 +1801,105 @@ TODO: ESLint rule
1730
1801
1731
1802
<!-- <rule> -->
1732
1803
1733
-
* Do assign regular expressions to variables rather than using them inline.
1804
+
### R: Assign to variables
1734
1805
1735
-
```javascript
1736
-
// Do:
1737
-
var regex =/\.+/;
1806
+
##### Reason
1738
1807
1739
-
beep();
1808
+
Ensures a regular expression is only created once and improves readability.
1740
1809
1741
-
functionbeep( str ) {
1742
-
if ( regex.test( str ) ) {
1743
-
// Do something...
1744
-
}
1810
+
##### Bad Example
1811
+
1812
+
```javascript
1813
+
// Do not...
1814
+
beep();
1815
+
1816
+
functionbeep( str ) {
1817
+
if (/\.+/.test( str ) ) {
1818
+
// Do something...
1745
1819
}
1820
+
}
1821
+
```
1746
1822
1747
-
// Don't:
1748
-
beep();
1823
+
##### Good Example
1749
1824
1750
-
functionbeep( str ) {
1751
-
if (/\.+/.test( str ) ) {
1752
-
// Do something...
1753
-
}
1825
+
```javascript
1826
+
// Do...
1827
+
var regex =/\.+/;
1828
+
1829
+
beep();
1830
+
1831
+
functionbeep( str ) {
1832
+
if ( regex.test( str ) ) {
1833
+
// Do something...
1754
1834
}
1755
-
```
1835
+
}
1836
+
```
1837
+
1838
+
##### Enforcement
1756
1839
1757
-
* __Always__ document regular expressions.
1840
+
Code review.
1758
1841
1759
-
``` javascript
1760
-
/**
1761
-
* REGEX: /^\/((?:\\\/|[^\/])+)\/([imgy]*)$/
1762
-
* Matches parts of a regular expression string.
1763
-
*
1764
-
* /^\/
1765
-
* - match a string that begins with a /
1766
-
* ()
1767
-
* - capture
1768
-
* (?:)+
1769
-
* - capture, but do not remember, a group of characters which occur 1 or more times
1770
-
* \\\/
1771
-
* - match the literal \/
1772
-
* |
1773
-
* - OR
1774
-
* [^\/]
1775
-
* - anything which is not the literal \/
1776
-
* \/
1777
-
* - match the literal /
1778
-
* ([imgy]*)
1779
-
* - capture any characters matching `imgy` occurring 0 or more times
1780
-
* $/
1781
-
* - string end
1782
-
*/
1783
-
var re = /^\/((?:\\\/|[^\/])+)\/([imgy]*)$/;
1784
-
```
1842
+
<!-- </rule> -->
1843
+
1844
+
<!-- <rule> -->
1845
+
1846
+
### R: Documentation
1847
+
1848
+
##### Reason
1849
+
1850
+
Regular expressions are error prone and difficult to understand without thorough examination.
0 commit comments