@spscommerce/eslint-config-typescript 8.2.1 → 8.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/GUIDE.md
CHANGED
|
@@ -249,15 +249,15 @@ function getKey(k: string) {
|
|
|
249
249
|
// bad
|
|
250
250
|
const obj = {
|
|
251
251
|
id: 5,
|
|
252
|
-
name:
|
|
252
|
+
name: "San Francisco",
|
|
253
253
|
};
|
|
254
|
-
obj[getKey(
|
|
254
|
+
obj[getKey("enabled")] = true;
|
|
255
255
|
|
|
256
256
|
// good
|
|
257
257
|
const obj = {
|
|
258
258
|
id: 5,
|
|
259
|
-
name:
|
|
260
|
-
[getKey(
|
|
259
|
+
name: "San Francisco",
|
|
260
|
+
[getKey("enabled")]: true,
|
|
261
261
|
};
|
|
262
262
|
```
|
|
263
263
|
|
|
@@ -334,7 +334,7 @@ const bad = {
|
|
|
334
334
|
const good = {
|
|
335
335
|
foo: 3,
|
|
336
336
|
bar: 4,
|
|
337
|
-
|
|
337
|
+
"data-blah": 5,
|
|
338
338
|
};
|
|
339
339
|
```
|
|
340
340
|
|
|
@@ -391,10 +391,10 @@ const items = new Array(8);
|
|
|
391
391
|
const someStack = [];
|
|
392
392
|
|
|
393
393
|
// bad
|
|
394
|
-
someStack[someStack.length] =
|
|
394
|
+
someStack[someStack.length] = "abracadabra";
|
|
395
395
|
|
|
396
396
|
// good
|
|
397
|
-
someStack.push(
|
|
397
|
+
someStack.push("abracadabra");
|
|
398
398
|
```
|
|
399
399
|
|
|
400
400
|
---
|
|
@@ -422,7 +422,7 @@ const itemsCopy = [...items];
|
|
|
422
422
|
[**4.4**](#arrays--from-iterable) ‣ To convert an iterable object to an array, use spreads `...` instead of [`Array.from`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/from).
|
|
423
423
|
|
|
424
424
|
```typescript
|
|
425
|
-
const foo = document.querySelectorAll(
|
|
425
|
+
const foo = document.querySelectorAll(".foo");
|
|
426
426
|
|
|
427
427
|
// good
|
|
428
428
|
const nodes = Array.from(foo);
|
|
@@ -437,7 +437,7 @@ const nodes = [...foo];
|
|
|
437
437
|
[**4.5**](#arrays--from-array-like) ‣ Use [`Array.from`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/from) for converting an array-like object to an array.
|
|
438
438
|
|
|
439
439
|
```typescript
|
|
440
|
-
const arrLike = { 0:
|
|
440
|
+
const arrLike = { 0: "foo", 1: "bar", 2: "baz", length: 3 };
|
|
441
441
|
|
|
442
442
|
// bad
|
|
443
443
|
const arr = Array.prototype.slice.call(arrLike);
|
|
@@ -490,16 +490,16 @@ const baz = Array.from(foo, bar);
|
|
|
490
490
|
// bad
|
|
491
491
|
inbox.filter((msg) => {
|
|
492
492
|
const { subject, author } = msg;
|
|
493
|
-
if (subject ===
|
|
494
|
-
return author ===
|
|
493
|
+
if (subject === "Mockingbird") {
|
|
494
|
+
return author === "Harper Lee";
|
|
495
495
|
}
|
|
496
496
|
});
|
|
497
497
|
|
|
498
498
|
// good
|
|
499
499
|
inbox.filter((msg) => {
|
|
500
500
|
const { subject, author } = msg;
|
|
501
|
-
if (subject ===
|
|
502
|
-
return author ===
|
|
501
|
+
if (subject === "Mockingbird") {
|
|
502
|
+
return author === "Harper Lee";
|
|
503
503
|
}
|
|
504
504
|
|
|
505
505
|
return false;
|
|
@@ -542,9 +542,9 @@ const objectInArray = [
|
|
|
542
542
|
];
|
|
543
543
|
|
|
544
544
|
const stringInArray = [
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
545
|
+
"foofoofoofoofoofoofoofoo",
|
|
546
|
+
"foofoofoofoofoofoofoofoo",
|
|
547
|
+
"foofoofoofoofoofoofoofoo",
|
|
548
548
|
];
|
|
549
549
|
```
|
|
550
550
|
|
|
@@ -688,7 +688,7 @@ const errorMessage = 'This is a super long error that was thrown because ' +
|
|
|
688
688
|
'with this, you would get nowhere fast.';
|
|
689
689
|
|
|
690
690
|
// good
|
|
691
|
-
const errorMessage =
|
|
691
|
+
const errorMessage = "This is a super long error that was thrown because of Batman. When you stop to think about how Batman had anything to do with this, you would get nowhere fast.";
|
|
692
692
|
```
|
|
693
693
|
|
|
694
694
|
---
|
|
@@ -745,7 +745,7 @@ function sayHi(name) {
|
|
|
745
745
|
const foo = '\'this\' \i\s \"quoted\"';
|
|
746
746
|
|
|
747
747
|
// good
|
|
748
|
-
const foo =
|
|
748
|
+
const foo = "\"this\" is "quoted"";
|
|
749
749
|
const foo = `my name is '${name}'`;
|
|
750
750
|
```
|
|
751
751
|
|
|
@@ -817,7 +817,7 @@ void someBackendCall();
|
|
|
817
817
|
// bad
|
|
818
818
|
if (currentUser) {
|
|
819
819
|
function test() {
|
|
820
|
-
console.log(
|
|
820
|
+
console.log("Nope.");
|
|
821
821
|
}
|
|
822
822
|
}
|
|
823
823
|
|
|
@@ -825,7 +825,7 @@ if (currentUser) {
|
|
|
825
825
|
let test;
|
|
826
826
|
if (currentUser) {
|
|
827
827
|
test = () => {
|
|
828
|
-
console.log(
|
|
828
|
+
console.log("Yup.");
|
|
829
829
|
};
|
|
830
830
|
}
|
|
831
831
|
```
|
|
@@ -843,12 +843,12 @@ if (currentUser) {
|
|
|
843
843
|
// bad
|
|
844
844
|
function concatenateAll() {
|
|
845
845
|
const args = Array.prototype.slice.call(arguments);
|
|
846
|
-
return args.join(
|
|
846
|
+
return args.join("");
|
|
847
847
|
}
|
|
848
848
|
|
|
849
849
|
// good
|
|
850
850
|
function concatenateAll(...args) {
|
|
851
|
-
return args.join(
|
|
851
|
+
return args.join("");
|
|
852
852
|
}
|
|
853
853
|
```
|
|
854
854
|
|
|
@@ -932,10 +932,10 @@ function handleThings(name: string, opts: IHandleThingsOpts = {}) {
|
|
|
932
932
|
|
|
933
933
|
```typescript
|
|
934
934
|
// bad
|
|
935
|
-
const add = new Function(
|
|
935
|
+
const add = new Function("a", "b", "return a + b");
|
|
936
936
|
|
|
937
937
|
// still bad
|
|
938
|
-
const subtract = Function(
|
|
938
|
+
const subtract = Function("a", "b", "return a - b");
|
|
939
939
|
```
|
|
940
940
|
|
|
941
941
|
---
|
|
@@ -1195,14 +1195,14 @@ foo(() => {
|
|
|
1195
1195
|
|
|
1196
1196
|
```typescript
|
|
1197
1197
|
// bad
|
|
1198
|
-
[
|
|
1198
|
+
["get", "post", "put"].map((httpMethod) => Object.prototype.hasOwnProperty.call(
|
|
1199
1199
|
httpMagicObjectWithAVeryLongName,
|
|
1200
1200
|
httpMethod,
|
|
1201
1201
|
)
|
|
1202
1202
|
);
|
|
1203
1203
|
|
|
1204
1204
|
// good
|
|
1205
|
-
[
|
|
1205
|
+
["get", "post", "put"].map((httpMethod) => (
|
|
1206
1206
|
Object.prototype.hasOwnProperty.call(
|
|
1207
1207
|
httpMagicObjectWithAVeryLongName,
|
|
1208
1208
|
httpMethod,
|
|
@@ -1343,7 +1343,7 @@ class Queue<T> {
|
|
|
1343
1343
|
|
|
1344
1344
|
```typescript
|
|
1345
1345
|
// bad
|
|
1346
|
-
const inherits = require(
|
|
1346
|
+
const inherits = require("inherits");
|
|
1347
1347
|
function PeekableQueue(contents) {
|
|
1348
1348
|
Queue.apply(this, contents);
|
|
1349
1349
|
}
|
|
@@ -1412,7 +1412,7 @@ class Jedi {
|
|
|
1412
1412
|
name: string;
|
|
1413
1413
|
|
|
1414
1414
|
constructor(options: IJediOptions = {}) {
|
|
1415
|
-
this.name = options.name ||
|
|
1415
|
+
this.name = options.name || "no name";
|
|
1416
1416
|
}
|
|
1417
1417
|
|
|
1418
1418
|
getName(): string {
|
|
@@ -1455,7 +1455,7 @@ class Rey extends Jedi {
|
|
|
1455
1455
|
class Rey extends Jedi {
|
|
1456
1456
|
constructor(...args) {
|
|
1457
1457
|
super(...args);
|
|
1458
|
-
this.name =
|
|
1458
|
+
this.name = "Rey";
|
|
1459
1459
|
}
|
|
1460
1460
|
}
|
|
1461
1461
|
```
|
|
@@ -1498,7 +1498,7 @@ class Foo {
|
|
|
1498
1498
|
// bad
|
|
1499
1499
|
class Foo {
|
|
1500
1500
|
bar() {
|
|
1501
|
-
console.log(
|
|
1501
|
+
console.log("bar");
|
|
1502
1502
|
}
|
|
1503
1503
|
}
|
|
1504
1504
|
|
|
@@ -1519,7 +1519,7 @@ class Foo {
|
|
|
1519
1519
|
// good - static methods aren't expected to use this
|
|
1520
1520
|
class Foo {
|
|
1521
1521
|
static bar() {
|
|
1522
|
-
console.log(
|
|
1522
|
+
console.log("bar");
|
|
1523
1523
|
}
|
|
1524
1524
|
}
|
|
1525
1525
|
```
|
|
@@ -1535,15 +1535,15 @@ class Foo {
|
|
|
1535
1535
|
|
|
1536
1536
|
```typescript
|
|
1537
1537
|
// bad
|
|
1538
|
-
const AirbnbStyleGuide = require(
|
|
1538
|
+
const AirbnbStyleGuide = require("./AirbnbStyleGuide");
|
|
1539
1539
|
module.exports = AirbnbStyleGuide.es6;
|
|
1540
1540
|
|
|
1541
1541
|
// ok
|
|
1542
|
-
import AirbnbStyleGuide from
|
|
1542
|
+
import AirbnbStyleGuide from "./AirbnbStyleGuide";
|
|
1543
1543
|
export default AirbnbStyleGuide.es6;
|
|
1544
1544
|
|
|
1545
1545
|
// best
|
|
1546
|
-
import { es6 } from
|
|
1546
|
+
import { es6 } from "./AirbnbStyleGuide";
|
|
1547
1547
|
export default es6;
|
|
1548
1548
|
```
|
|
1549
1549
|
|
|
@@ -1558,18 +1558,18 @@ export default es6;
|
|
|
1558
1558
|
|
|
1559
1559
|
```typescript
|
|
1560
1560
|
// bad
|
|
1561
|
-
import foo from
|
|
1561
|
+
import foo from "foo";
|
|
1562
1562
|
// … some other imports … //
|
|
1563
|
-
import { named1, named2 } from
|
|
1563
|
+
import { named1, named2 } from "foo";
|
|
1564
1564
|
|
|
1565
1565
|
// good
|
|
1566
|
-
import foo, { named1, named2 } from
|
|
1566
|
+
import foo, { named1, named2 } from "foo";
|
|
1567
1567
|
|
|
1568
1568
|
// good
|
|
1569
1569
|
import foo, {
|
|
1570
1570
|
named1,
|
|
1571
1571
|
named2,
|
|
1572
|
-
} from
|
|
1572
|
+
} from "foo";
|
|
1573
1573
|
```
|
|
1574
1574
|
|
|
1575
1575
|
---
|
|
@@ -1602,14 +1602,14 @@ export { foo };
|
|
|
1602
1602
|
|
|
1603
1603
|
```typescript
|
|
1604
1604
|
// bad
|
|
1605
|
-
import foo from
|
|
1605
|
+
import foo from "foo";
|
|
1606
1606
|
foo.init();
|
|
1607
1607
|
|
|
1608
|
-
import bar from
|
|
1608
|
+
import bar from "bar";
|
|
1609
1609
|
|
|
1610
1610
|
// good
|
|
1611
|
-
import foo from
|
|
1612
|
-
import bar from
|
|
1611
|
+
import foo from "foo";
|
|
1612
|
+
import bar from "bar";
|
|
1613
1613
|
|
|
1614
1614
|
foo.init();
|
|
1615
1615
|
```
|
|
@@ -1626,7 +1626,7 @@ foo.init();
|
|
|
1626
1626
|
```typescript
|
|
1627
1627
|
// bad
|
|
1628
1628
|
import { longNameA, longNameB, longNameC,
|
|
1629
|
-
longNameD, longNameE, longNameF } from
|
|
1629
|
+
longNameD, longNameE, longNameF } from "path";
|
|
1630
1630
|
|
|
1631
1631
|
// good
|
|
1632
1632
|
import {
|
|
@@ -1635,7 +1635,7 @@ import {
|
|
|
1635
1635
|
longNameC,
|
|
1636
1636
|
longNameD,
|
|
1637
1637
|
longNameE,
|
|
1638
|
-
} from
|
|
1638
|
+
} from "path";
|
|
1639
1639
|
```
|
|
1640
1640
|
|
|
1641
1641
|
Note: formerly we used [`object-curly-newline`](https://eslint.org/docs/rules/object-curly-newline) but have turned it off due to conflicts with how Prettier handles this.
|
|
@@ -1651,12 +1651,12 @@ Note: formerly we used [`object-curly-newline`](https://eslint.org/docs/rules/ob
|
|
|
1651
1651
|
|
|
1652
1652
|
```typescript
|
|
1653
1653
|
// bad
|
|
1654
|
-
import fooSass from
|
|
1655
|
-
import barCss from
|
|
1654
|
+
import fooSass from "css!sass!foo.scss";
|
|
1655
|
+
import barCss from "style!css!bar.css";
|
|
1656
1656
|
|
|
1657
1657
|
// good
|
|
1658
|
-
import fooSass from
|
|
1659
|
-
import barCss from
|
|
1658
|
+
import fooSass from "foo.scss";
|
|
1659
|
+
import barCss from "bar.css";
|
|
1660
1660
|
```
|
|
1661
1661
|
|
|
1662
1662
|
---
|
|
@@ -1670,14 +1670,14 @@ import barCss from 'bar.css';
|
|
|
1670
1670
|
|
|
1671
1671
|
```typescript
|
|
1672
1672
|
// bad
|
|
1673
|
-
import foo from
|
|
1674
|
-
import bar from
|
|
1675
|
-
import baz from
|
|
1673
|
+
import foo from "./foo.js";
|
|
1674
|
+
import bar from "./bar.jsx";
|
|
1675
|
+
import baz from "./baz/index.jsx";
|
|
1676
1676
|
|
|
1677
1677
|
// good
|
|
1678
|
-
import foo from
|
|
1679
|
-
import bar from
|
|
1680
|
-
import baz from
|
|
1678
|
+
import foo from "./foo";
|
|
1679
|
+
import bar from "./bar";
|
|
1680
|
+
import baz from "./baz";
|
|
1681
1681
|
```
|
|
1682
1682
|
|
|
1683
1683
|
**[⬆ back to top](#table-of-contents)**
|
|
@@ -1740,7 +1740,7 @@ const increasedByOne = numbers.map((num) => num + 1);
|
|
|
1740
1740
|
> Why? `for-in` has confusing and unexpected behavior. For this reason, `for-of` was added to the language and should be used instead.
|
|
1741
1741
|
|
|
1742
1742
|
```typescript
|
|
1743
|
-
const obj = { a:
|
|
1743
|
+
const obj = { a: "foo", b: "bar" };
|
|
1744
1744
|
|
|
1745
1745
|
// bad
|
|
1746
1746
|
for (const key in obj) {
|
|
@@ -1848,7 +1848,7 @@ const luke = {
|
|
|
1848
1848
|
};
|
|
1849
1849
|
|
|
1850
1850
|
// bad
|
|
1851
|
-
const isJedi = luke[
|
|
1851
|
+
const isJedi = luke["jedi"];
|
|
1852
1852
|
|
|
1853
1853
|
// good
|
|
1854
1854
|
const isJedi = luke.jedi;
|
|
@@ -1885,18 +1885,18 @@ const superPower = new SuperPower();
|
|
|
1885
1885
|
// bad
|
|
1886
1886
|
const items = getItems(),
|
|
1887
1887
|
goSportsTeam = true,
|
|
1888
|
-
dragonball =
|
|
1888
|
+
dragonball = "z";
|
|
1889
1889
|
|
|
1890
1890
|
// bad
|
|
1891
1891
|
// (compare to above, and try to spot the mistake)
|
|
1892
1892
|
const items = getItems(),
|
|
1893
1893
|
goSportsTeam = true;
|
|
1894
|
-
dragonball =
|
|
1894
|
+
dragonball = "z";
|
|
1895
1895
|
|
|
1896
1896
|
// good
|
|
1897
1897
|
const items = getItems();
|
|
1898
1898
|
const goSportsTeam = true;
|
|
1899
|
-
const dragonball =
|
|
1899
|
+
const dragonball = "z";
|
|
1900
1900
|
```
|
|
1901
1901
|
|
|
1902
1902
|
---
|
|
@@ -1939,12 +1939,12 @@ let length: number;
|
|
|
1939
1939
|
function checkName(hasName) {
|
|
1940
1940
|
const name = getName();
|
|
1941
1941
|
|
|
1942
|
-
if (hasName ===
|
|
1942
|
+
if (hasName === "test") {
|
|
1943
1943
|
return false;
|
|
1944
1944
|
}
|
|
1945
1945
|
|
|
1946
|
-
if (name ===
|
|
1947
|
-
this.setName(
|
|
1946
|
+
if (name === "test") {
|
|
1947
|
+
this.setName("");
|
|
1948
1948
|
return false;
|
|
1949
1949
|
}
|
|
1950
1950
|
|
|
@@ -1953,14 +1953,14 @@ function checkName(hasName) {
|
|
|
1953
1953
|
|
|
1954
1954
|
// good
|
|
1955
1955
|
function checkName(hasName) {
|
|
1956
|
-
if (hasName ===
|
|
1956
|
+
if (hasName === "test") {
|
|
1957
1957
|
return false;
|
|
1958
1958
|
}
|
|
1959
1959
|
|
|
1960
1960
|
const name = getName();
|
|
1961
1961
|
|
|
1962
|
-
if (name ===
|
|
1963
|
-
this.setName(
|
|
1962
|
+
if (name === "test") {
|
|
1963
|
+
this.setName("");
|
|
1964
1964
|
return false;
|
|
1965
1965
|
}
|
|
1966
1966
|
|
|
@@ -2057,7 +2057,7 @@ const foo =
|
|
|
2057
2057
|
|
|
2058
2058
|
// bad
|
|
2059
2059
|
const foo
|
|
2060
|
-
=
|
|
2060
|
+
= "superLongLongLongLongLongLongLongLongString";
|
|
2061
2061
|
|
|
2062
2062
|
// good
|
|
2063
2063
|
const foo = (
|
|
@@ -2065,7 +2065,7 @@ const foo = (
|
|
|
2065
2065
|
);
|
|
2066
2066
|
|
|
2067
2067
|
// good
|
|
2068
|
-
const foo =
|
|
2068
|
+
const foo = "superLongLongLongLongLongLongLongLongString";
|
|
2069
2069
|
```
|
|
2070
2070
|
|
|
2071
2071
|
---
|
|
@@ -2130,7 +2130,7 @@ const { type, ...coords } = data;
|
|
|
2130
2130
|
- **Null** evaluates to **false**
|
|
2131
2131
|
- **Booleans** evaluate to **the value of the boolean**
|
|
2132
2132
|
- **Numbers** evaluate to **false** if **+0, -0, or NaN**, otherwise **true**
|
|
2133
|
-
- **Strings** evaluate to **false** if an empty string `
|
|
2133
|
+
- **Strings** evaluate to **false** if an empty string `""`, otherwise **true**
|
|
2134
2134
|
|
|
2135
2135
|
```typescript
|
|
2136
2136
|
if ([0] && []) {
|
|
@@ -2161,7 +2161,7 @@ if (name) {
|
|
|
2161
2161
|
}
|
|
2162
2162
|
|
|
2163
2163
|
// good
|
|
2164
|
-
if (name !==
|
|
2164
|
+
if (name !== "") {
|
|
2165
2165
|
// ...
|
|
2166
2166
|
}
|
|
2167
2167
|
|
|
@@ -2253,15 +2253,15 @@ const foo = maybe1 > maybe2
|
|
|
2253
2253
|
: value1 > value2 ? "baz" : null;
|
|
2254
2254
|
|
|
2255
2255
|
// split into 2 separated ternary expressions
|
|
2256
|
-
const maybeNull = value1 > value2 ?
|
|
2256
|
+
const maybeNull = value1 > value2 ? "baz" : null;
|
|
2257
2257
|
|
|
2258
2258
|
// better
|
|
2259
2259
|
const foo = maybe1 > maybe2
|
|
2260
|
-
?
|
|
2260
|
+
? "bar"
|
|
2261
2261
|
: maybeNull;
|
|
2262
2262
|
|
|
2263
2263
|
// best
|
|
2264
|
-
const foo = maybe1 > maybe2 ?
|
|
2264
|
+
const foo = maybe1 > maybe2 ? "bar" : maybeNull;
|
|
2265
2265
|
```
|
|
2266
2266
|
|
|
2267
2267
|
---
|
|
@@ -2382,12 +2382,12 @@ if (test) {
|
|
|
2382
2382
|
|
|
2383
2383
|
```typescript
|
|
2384
2384
|
// bad
|
|
2385
|
-
if ((foo === 123 || bar ===
|
|
2385
|
+
if ((foo === 123 || bar === "abc") && doesItLookGoodWhenItBecomesThatLong() && isThisReallyHappening()) {
|
|
2386
2386
|
thing1();
|
|
2387
2387
|
}
|
|
2388
2388
|
|
|
2389
2389
|
// bad
|
|
2390
|
-
if ((foo === 123 || bar ===
|
|
2390
|
+
if ((foo === 123 || bar === "abc") &&
|
|
2391
2391
|
doesItLookGoodWhenItBecomesThatLong() &&
|
|
2392
2392
|
isThisReallyHappening()) {
|
|
2393
2393
|
thing1();
|
|
@@ -2395,7 +2395,7 @@ if ((foo === 123 || bar === 'abc') &&
|
|
|
2395
2395
|
|
|
2396
2396
|
// good
|
|
2397
2397
|
if (
|
|
2398
|
-
(foo === 123 || bar ===
|
|
2398
|
+
(foo === 123 || bar === "abc") &&
|
|
2399
2399
|
doesItLookGoodWhenItBecomesThatLong() &&
|
|
2400
2400
|
isThisReallyHappening()
|
|
2401
2401
|
) {
|
|
@@ -2405,7 +2405,7 @@ if (
|
|
|
2405
2405
|
// good
|
|
2406
2406
|
if (
|
|
2407
2407
|
(foo === 123 ||
|
|
2408
|
-
bar ===
|
|
2408
|
+
bar === "abc" ||
|
|
2409
2409
|
someOtherReallyLongFunctionName()) &&
|
|
2410
2410
|
doesItLookGoodWhenItBecomesThatLong() &&
|
|
2411
2411
|
isThisReallyHappening()
|
|
@@ -2414,7 +2414,7 @@ if (
|
|
|
2414
2414
|
}
|
|
2415
2415
|
|
|
2416
2416
|
// good
|
|
2417
|
-
if (foo === 123 && bar ===
|
|
2417
|
+
if (foo === 123 && bar === "abc") {
|
|
2418
2418
|
thing1();
|
|
2419
2419
|
}
|
|
2420
2420
|
```
|
|
@@ -2485,27 +2485,27 @@ const active = true;
|
|
|
2485
2485
|
|
|
2486
2486
|
// bad
|
|
2487
2487
|
function getType() {
|
|
2488
|
-
console.log(
|
|
2489
|
-
// set the default type to
|
|
2490
|
-
const type = this.type ||
|
|
2488
|
+
console.log("fetching type...");
|
|
2489
|
+
// set the default type to "no type"
|
|
2490
|
+
const type = this.type || "no type";
|
|
2491
2491
|
|
|
2492
2492
|
return type;
|
|
2493
2493
|
}
|
|
2494
2494
|
|
|
2495
2495
|
// good
|
|
2496
2496
|
function getType() {
|
|
2497
|
-
console.log(
|
|
2497
|
+
console.log("fetching type...");
|
|
2498
2498
|
|
|
2499
|
-
// set the default type to
|
|
2500
|
-
const type = this.type ||
|
|
2499
|
+
// set the default type to "no type"
|
|
2500
|
+
const type = this.type || "no type";
|
|
2501
2501
|
|
|
2502
2502
|
return type;
|
|
2503
2503
|
}
|
|
2504
2504
|
|
|
2505
2505
|
// also good
|
|
2506
2506
|
function getType() {
|
|
2507
|
-
// set the default type to
|
|
2508
|
-
const type = this.type ||
|
|
2507
|
+
// set the default type to "no type"
|
|
2508
|
+
const type = this.type || "no type";
|
|
2509
2509
|
|
|
2510
2510
|
return type;
|
|
2511
2511
|
}
|
|
@@ -2619,24 +2619,24 @@ function baz() {
|
|
|
2619
2619
|
```typescript
|
|
2620
2620
|
// bad
|
|
2621
2621
|
function test(){
|
|
2622
|
-
console.log(
|
|
2622
|
+
console.log("test");
|
|
2623
2623
|
}
|
|
2624
2624
|
|
|
2625
2625
|
// good
|
|
2626
2626
|
function test() {
|
|
2627
|
-
console.log(
|
|
2627
|
+
console.log("test");
|
|
2628
2628
|
}
|
|
2629
2629
|
|
|
2630
2630
|
// bad
|
|
2631
|
-
dog.set(
|
|
2632
|
-
age:
|
|
2633
|
-
breed:
|
|
2631
|
+
dog.set("attr",{
|
|
2632
|
+
age: "1 year",
|
|
2633
|
+
breed: "Bernese Mountain Dog",
|
|
2634
2634
|
});
|
|
2635
2635
|
|
|
2636
2636
|
// good
|
|
2637
|
-
dog.set(
|
|
2638
|
-
age:
|
|
2639
|
-
breed:
|
|
2637
|
+
dog.set("attr", {
|
|
2638
|
+
age: "1 year",
|
|
2639
|
+
breed: "Bernese Mountain Dog",
|
|
2640
2640
|
});
|
|
2641
2641
|
```
|
|
2642
2642
|
|
|
@@ -2662,12 +2662,12 @@ if (isJedi) {
|
|
|
2662
2662
|
|
|
2663
2663
|
// bad
|
|
2664
2664
|
function fight () {
|
|
2665
|
-
console.log (
|
|
2665
|
+
console.log ("Swooosh!");
|
|
2666
2666
|
}
|
|
2667
2667
|
|
|
2668
2668
|
// good
|
|
2669
2669
|
function fight() {
|
|
2670
|
-
console.log(
|
|
2670
|
+
console.log("Swooosh!");
|
|
2671
2671
|
}
|
|
2672
2672
|
```
|
|
2673
2673
|
|
|
@@ -2699,14 +2699,14 @@ const x = y + 5;
|
|
|
2699
2699
|
|
|
2700
2700
|
```typescript
|
|
2701
2701
|
// bad
|
|
2702
|
-
import { es6 } from
|
|
2702
|
+
import { es6 } from "./AirbnbStyleGuide";
|
|
2703
2703
|
// ...
|
|
2704
2704
|
export default es6;
|
|
2705
2705
|
```
|
|
2706
2706
|
|
|
2707
2707
|
```typescript
|
|
2708
2708
|
// bad
|
|
2709
|
-
import { es6 } from
|
|
2709
|
+
import { es6 } from "./AirbnbStyleGuide";
|
|
2710
2710
|
// ...
|
|
2711
2711
|
export default es6;↵
|
|
2712
2712
|
↵
|
|
@@ -2714,7 +2714,7 @@ export default es6;↵
|
|
|
2714
2714
|
|
|
2715
2715
|
```typescript
|
|
2716
2716
|
// good
|
|
2717
|
-
import { es6 } from
|
|
2717
|
+
import { es6 } from "./AirbnbStyleGuide";
|
|
2718
2718
|
// ...
|
|
2719
2719
|
export default es6;↵
|
|
2720
2720
|
```
|
|
@@ -2730,21 +2730,21 @@ export default es6;↵
|
|
|
2730
2730
|
|
|
2731
2731
|
```typescript
|
|
2732
2732
|
// bad
|
|
2733
|
-
const foo = bar.qwer(
|
|
2734
|
-
.zxc(
|
|
2735
|
-
zxc(
|
|
2733
|
+
const foo = bar.qwer(".baz").tyui(data).op().asdf("beep").ghjkl("baz", true)
|
|
2734
|
+
.zxc("substance", (ecto + plasm) * 2).asdf("green").
|
|
2735
|
+
zxc("try", `contain(${ecto + plasm}, ${ecto + plasm})`)
|
|
2736
2736
|
.call(tron.baz);
|
|
2737
2737
|
|
|
2738
2738
|
// good
|
|
2739
2739
|
const foo = bar
|
|
2740
|
-
.qwer(
|
|
2740
|
+
.qwer(".baz")
|
|
2741
2741
|
.tyui(data)
|
|
2742
2742
|
.op()
|
|
2743
|
-
.asdf(
|
|
2744
|
-
.ghjkl(
|
|
2745
|
-
.zxc(
|
|
2746
|
-
.asdf(
|
|
2747
|
-
.zxc(
|
|
2743
|
+
.asdf("beep")
|
|
2744
|
+
.ghjkl("baz", true)
|
|
2745
|
+
.zxc("substance", (ecto + plasm) * 2)
|
|
2746
|
+
.asdf("green")
|
|
2747
|
+
.zxc("try", `contain(${ecto + plasm}, ${ecto + plasm})`)
|
|
2748
2748
|
.call(tron.baz);
|
|
2749
2749
|
```
|
|
2750
2750
|
|
|
@@ -2986,10 +2986,10 @@ console.log(foo[0]);
|
|
|
2986
2986
|
|
|
2987
2987
|
```typescript
|
|
2988
2988
|
// bad
|
|
2989
|
-
const foo = {clark:
|
|
2989
|
+
const foo = {clark: "kent"};
|
|
2990
2990
|
|
|
2991
2991
|
// good
|
|
2992
|
-
const foo = { clark:
|
|
2992
|
+
const foo = { clark: "kent" };
|
|
2993
2993
|
```
|
|
2994
2994
|
|
|
2995
2995
|
---
|
|
@@ -3045,13 +3045,13 @@ const arr = [1, 2];
|
|
|
3045
3045
|
```typescript
|
|
3046
3046
|
// bad
|
|
3047
3047
|
obj[foo ]
|
|
3048
|
-
obj[
|
|
3048
|
+
obj[ "foo"]
|
|
3049
3049
|
const x = {[ b ]: a}
|
|
3050
3050
|
obj[foo[ bar ]]
|
|
3051
3051
|
|
|
3052
3052
|
// good
|
|
3053
3053
|
obj[foo]
|
|
3054
|
-
obj[
|
|
3054
|
+
obj["foo"]
|
|
3055
3055
|
const x = { [b]: a }
|
|
3056
3056
|
obj[foo[bar]]
|
|
3057
3057
|
```
|
|
@@ -3105,10 +3105,10 @@ const obj = { foo: 42 };
|
|
|
3105
3105
|
|
|
3106
3106
|
```typescript
|
|
3107
3107
|
// bad
|
|
3108
|
-
const foo =
|
|
3108
|
+
const foo = "bar";∙
|
|
3109
3109
|
|
|
3110
3110
|
// good
|
|
3111
|
-
const foo =
|
|
3111
|
+
const foo = "bar";
|
|
3112
3112
|
```
|
|
3113
3113
|
|
|
3114
3114
|
|
|
@@ -3140,18 +3140,18 @@ const story = [
|
|
|
3140
3140
|
|
|
3141
3141
|
// bad
|
|
3142
3142
|
const hero = {
|
|
3143
|
-
firstName:
|
|
3144
|
-
, lastName:
|
|
3143
|
+
firstName: "Ada"
|
|
3144
|
+
, lastName: "Lovelace"
|
|
3145
3145
|
, birthYear: 1815
|
|
3146
|
-
, superPower:
|
|
3146
|
+
, superPower: "computers"
|
|
3147
3147
|
};
|
|
3148
3148
|
|
|
3149
3149
|
// good
|
|
3150
3150
|
const hero = {
|
|
3151
|
-
firstName:
|
|
3152
|
-
lastName:
|
|
3151
|
+
firstName: "Ada",
|
|
3152
|
+
lastName: "Lovelace",
|
|
3153
3153
|
birthYear: 1815,
|
|
3154
|
-
superPower:
|
|
3154
|
+
superPower: "computers",
|
|
3155
3155
|
};
|
|
3156
3156
|
```
|
|
3157
3157
|
|
|
@@ -3169,41 +3169,41 @@ const hero = {
|
|
|
3169
3169
|
```diff
|
|
3170
3170
|
// bad - git diff without trailing comma
|
|
3171
3171
|
const hero = {
|
|
3172
|
-
firstName:
|
|
3173
|
-
- lastName:
|
|
3174
|
-
+ lastName:
|
|
3175
|
-
+ inventorOf: [
|
|
3172
|
+
firstName: "Florence",
|
|
3173
|
+
- lastName: "Nightingale"
|
|
3174
|
+
+ lastName: "Nightingale",
|
|
3175
|
+
+ inventorOf: ["coxcomb chart", "modern nursing"]
|
|
3176
3176
|
};
|
|
3177
3177
|
|
|
3178
3178
|
// good - git diff with trailing comma
|
|
3179
3179
|
const hero = {
|
|
3180
|
-
firstName:
|
|
3181
|
-
lastName:
|
|
3182
|
-
+ inventorOf: [
|
|
3180
|
+
firstName: "Florence",
|
|
3181
|
+
lastName: "Nightingale",
|
|
3182
|
+
+ inventorOf: ["coxcomb chart", "modern nursing"],
|
|
3183
3183
|
};
|
|
3184
3184
|
```
|
|
3185
3185
|
|
|
3186
3186
|
```typescript
|
|
3187
3187
|
// bad
|
|
3188
3188
|
const hero = {
|
|
3189
|
-
firstName:
|
|
3190
|
-
lastName:
|
|
3189
|
+
firstName: "Dana",
|
|
3190
|
+
lastName: "Scully"
|
|
3191
3191
|
};
|
|
3192
3192
|
|
|
3193
3193
|
const heroes = [
|
|
3194
|
-
|
|
3195
|
-
|
|
3194
|
+
"Batman",
|
|
3195
|
+
"Superman"
|
|
3196
3196
|
];
|
|
3197
3197
|
|
|
3198
3198
|
// good
|
|
3199
3199
|
const hero = {
|
|
3200
|
-
firstName:
|
|
3201
|
-
lastName:
|
|
3200
|
+
firstName: "Dana",
|
|
3201
|
+
lastName: "Scully",
|
|
3202
3202
|
};
|
|
3203
3203
|
|
|
3204
3204
|
const heroes = [
|
|
3205
|
-
|
|
3206
|
-
|
|
3205
|
+
"Batman",
|
|
3206
|
+
"Superman",
|
|
3207
3207
|
];
|
|
3208
3208
|
|
|
3209
3209
|
// bad
|
|
@@ -3274,7 +3274,7 @@ createHero(
|
|
|
3274
3274
|
// bad - raises exception
|
|
3275
3275
|
const luke = {}
|
|
3276
3276
|
const leia = {}
|
|
3277
|
-
[luke, leia].forEach((jedi) => jedi.father =
|
|
3277
|
+
[luke, leia].forEach((jedi) => jedi.father = "vader")
|
|
3278
3278
|
|
|
3279
3279
|
// bad - raises exception
|
|
3280
3280
|
const reaction = "No! That’s impossible!"
|
|
@@ -3286,14 +3286,14 @@ const reaction = "No! That’s impossible!"
|
|
|
3286
3286
|
// bad - returns `undefined` instead of the value on the next line - always happens when `return` is on a line by itself because of ASI!
|
|
3287
3287
|
function foo() {
|
|
3288
3288
|
return
|
|
3289
|
-
|
|
3289
|
+
"search your feelings, you know it to be foo"
|
|
3290
3290
|
}
|
|
3291
3291
|
|
|
3292
3292
|
// good
|
|
3293
3293
|
const luke = {};
|
|
3294
3294
|
const leia = {};
|
|
3295
3295
|
[luke, leia].forEach((jedi) => {
|
|
3296
|
-
jedi.father =
|
|
3296
|
+
jedi.father = "vader";
|
|
3297
3297
|
});
|
|
3298
3298
|
|
|
3299
3299
|
// good
|
|
@@ -3305,7 +3305,7 @@ const reaction = "No! That’s impossible!";
|
|
|
3305
3305
|
|
|
3306
3306
|
// good
|
|
3307
3307
|
function foo() {
|
|
3308
|
-
return
|
|
3308
|
+
return "search your feelings, you know it to be foo";
|
|
3309
3309
|
}
|
|
3310
3310
|
```
|
|
3311
3311
|
|
|
@@ -3332,7 +3332,7 @@ function foo() {
|
|
|
3332
3332
|
const totalScore = new String(this.reviewScore); // typeof totalScore is "object" not "string"
|
|
3333
3333
|
|
|
3334
3334
|
// bad
|
|
3335
|
-
const totalScore = this.reviewScore +
|
|
3335
|
+
const totalScore = this.reviewScore + ""; // invokes this.reviewScore.valueOf()
|
|
3336
3336
|
|
|
3337
3337
|
// bad
|
|
3338
3338
|
const totalScore = this.reviewScore.toString(); // isn’t guaranteed to return a string
|
|
@@ -3351,7 +3351,7 @@ const totalScore = String(this.reviewScore);
|
|
|
3351
3351
|
> Why? The `parseInt` function produces an integer value dictated by interpretation of the contents of the string argument according to the specified radix. Leading whitespace in string is ignored. If radix is `undefined` or `0`, it is assumed to be `10` except when the number begins with the character pairs `0x` or `0X`, in which case a radix of 16 is assumed. This differs from ECMAScript 3, which merely discouraged (but allowed) octal interpretation. Many implementations have not adopted this behavior as of 2013. And, because older browsers must be supported, always specify a radix.
|
|
3352
3352
|
|
|
3353
3353
|
```typescript
|
|
3354
|
-
const inputValue =
|
|
3354
|
+
const inputValue = "4";
|
|
3355
3355
|
|
|
3356
3356
|
// bad
|
|
3357
3357
|
const val = new Number(inputValue);
|
|
@@ -3471,7 +3471,7 @@ function user(options) {
|
|
|
3471
3471
|
}
|
|
3472
3472
|
|
|
3473
3473
|
const bad = new user({
|
|
3474
|
-
name:
|
|
3474
|
+
name: "nope",
|
|
3475
3475
|
});
|
|
3476
3476
|
|
|
3477
3477
|
// good
|
|
@@ -3482,7 +3482,7 @@ class User {
|
|
|
3482
3482
|
}
|
|
3483
3483
|
|
|
3484
3484
|
const good = new User({
|
|
3485
|
-
name:
|
|
3485
|
+
name: "yup",
|
|
3486
3486
|
});
|
|
3487
3487
|
```
|
|
3488
3488
|
|
|
@@ -3497,17 +3497,17 @@ const good = new User({
|
|
|
3497
3497
|
|
|
3498
3498
|
```typescript
|
|
3499
3499
|
// bad
|
|
3500
|
-
this.__firstName__ =
|
|
3501
|
-
this.firstName_ =
|
|
3502
|
-
this._firstName =
|
|
3500
|
+
this.__firstName__ = "Panda";
|
|
3501
|
+
this.firstName_ = "Panda";
|
|
3502
|
+
this._firstName = "Panda";
|
|
3503
3503
|
|
|
3504
3504
|
// good
|
|
3505
|
-
this.firstName =
|
|
3505
|
+
this.firstName = "Panda";
|
|
3506
3506
|
|
|
3507
3507
|
// good, in environments where WeakMaps are available
|
|
3508
3508
|
// see https://kangax.github.io/compat-table/es6/#test-WeakMap
|
|
3509
3509
|
const firstNames = new WeakMap();
|
|
3510
|
-
firstNames.set(this,
|
|
3510
|
+
firstNames.set(this, "Panda");
|
|
3511
3511
|
```
|
|
3512
3512
|
|
|
3513
3513
|
---
|
|
@@ -3560,21 +3560,21 @@ export default function insideDirectory() {}
|
|
|
3560
3560
|
|
|
3561
3561
|
// in some other file
|
|
3562
3562
|
// bad
|
|
3563
|
-
import CheckBox from
|
|
3564
|
-
import FortyTwo from
|
|
3565
|
-
import InsideDirectory from
|
|
3563
|
+
import CheckBox from "./checkBox"; // PascalCase import/export, camelCase filename
|
|
3564
|
+
import FortyTwo from "./FortyTwo"; // PascalCase import/filename, camelCase export
|
|
3565
|
+
import InsideDirectory from "./InsideDirectory"; // PascalCase import/filename, camelCase export
|
|
3566
3566
|
|
|
3567
3567
|
// bad
|
|
3568
|
-
import CheckBox from
|
|
3569
|
-
import forty_two from
|
|
3570
|
-
import inside_directory from
|
|
3571
|
-
import index from
|
|
3572
|
-
import insideDirectory from
|
|
3568
|
+
import CheckBox from "./check_box"; // PascalCase import/export, snake_case filename
|
|
3569
|
+
import forty_two from "./forty_two"; // snake_case import/filename, camelCase export
|
|
3570
|
+
import inside_directory from "./inside_directory"; // snake_case import, camelCase export
|
|
3571
|
+
import index from "./inside_directory/index"; // requiring the index file explicitly
|
|
3572
|
+
import insideDirectory from "./insideDirectory/index"; // requiring the index file explicitly
|
|
3573
3573
|
|
|
3574
3574
|
// good
|
|
3575
|
-
import CheckBox from
|
|
3576
|
-
import fortyTwo from
|
|
3577
|
-
import insideDirectory from
|
|
3575
|
+
import CheckBox from "./CheckBox"; // PascalCase export/import/filename
|
|
3576
|
+
import fortyTwo from "./fortyTwo"; // camelCase export/import/filename
|
|
3577
|
+
import insideDirectory from "./insideDirectory"; // camelCase export/import/directory name/implicit "index"
|
|
3578
3578
|
// ^ supports both insideDirectory.js and insideDirectory/index.js
|
|
3579
3579
|
```
|
|
3580
3580
|
|
|
@@ -3601,7 +3601,7 @@ export default AirbnbStyleGuide;
|
|
|
3601
3601
|
|
|
3602
3602
|
```typescript
|
|
3603
3603
|
// bad
|
|
3604
|
-
import SmsContainer from
|
|
3604
|
+
import SmsContainer from "./containers/SmsContainer";
|
|
3605
3605
|
|
|
3606
3606
|
// bad
|
|
3607
3607
|
const HttpRequests = [
|
|
@@ -3609,7 +3609,7 @@ const HttpRequests = [
|
|
|
3609
3609
|
];
|
|
3610
3610
|
|
|
3611
3611
|
// good
|
|
3612
|
-
import SMSContainer from
|
|
3612
|
+
import SMSContainer from "./containers/SMSContainer";
|
|
3613
3613
|
|
|
3614
3614
|
// good
|
|
3615
3615
|
const HTTPRequests = [
|
|
@@ -3622,7 +3622,7 @@ const httpRequests = [
|
|
|
3622
3622
|
];
|
|
3623
3623
|
|
|
3624
3624
|
// best
|
|
3625
|
-
import TextMessageContainer from
|
|
3625
|
+
import TextMessageContainer from "./containers/TextMessageContainer";
|
|
3626
3626
|
|
|
3627
3627
|
// best
|
|
3628
3628
|
const requests = [
|
|
@@ -3641,32 +3641,32 @@ const requests = [
|
|
|
3641
3641
|
|
|
3642
3642
|
```typescript
|
|
3643
3643
|
// bad
|
|
3644
|
-
const PRIVATE_VARIABLE =
|
|
3644
|
+
const PRIVATE_VARIABLE = "should not be unnecessarily uppercased within a file";
|
|
3645
3645
|
|
|
3646
3646
|
// bad
|
|
3647
|
-
export const THING_TO_BE_CHANGED =
|
|
3647
|
+
export const THING_TO_BE_CHANGED = "should obviously not be uppercased";
|
|
3648
3648
|
|
|
3649
3649
|
// bad
|
|
3650
|
-
export let REASSIGNABLE_VARIABLE =
|
|
3650
|
+
export let REASSIGNABLE_VARIABLE = "do not use let with uppercase variables";
|
|
3651
3651
|
|
|
3652
3652
|
// ---
|
|
3653
3653
|
|
|
3654
3654
|
// allowed but does not supply semantic value
|
|
3655
|
-
export const apiKey =
|
|
3655
|
+
export const apiKey = "SOMEKEY";
|
|
3656
3656
|
|
|
3657
3657
|
// better in most cases
|
|
3658
|
-
export const API_KEY =
|
|
3658
|
+
export const API_KEY = "SOMEKEY";
|
|
3659
3659
|
|
|
3660
3660
|
// ---
|
|
3661
3661
|
|
|
3662
3662
|
// bad - unnecessarily uppercases key while adding no semantic value
|
|
3663
3663
|
export const MAPPING = {
|
|
3664
|
-
KEY:
|
|
3664
|
+
KEY: "value"
|
|
3665
3665
|
};
|
|
3666
3666
|
|
|
3667
3667
|
// good
|
|
3668
3668
|
export const MAPPING = {
|
|
3669
|
-
key:
|
|
3669
|
+
key: "value"
|
|
3670
3670
|
};
|
|
3671
3671
|
```
|
|
3672
3672
|
|
|
@@ -3680,7 +3680,7 @@ export const MAPPING = {
|
|
|
3680
3680
|
---
|
|
3681
3681
|
|
|
3682
3682
|
<a name="accessors--no-getters-setters"></a>
|
|
3683
|
-
[**24.2**](#accessors--no-getters-setters) ‣ Do not use JavaScript getters/setters as they cause unexpected side effects and are harder to test, maintain, and reason about. Instead, if you do make accessor functions, use `getVal()` and `setVal(
|
|
3683
|
+
[**24.2**](#accessors--no-getters-setters) ‣ Do not use JavaScript getters/setters as they cause unexpected side effects and are harder to test, maintain, and reason about. Instead, if you do make accessor functions, use `getVal()` and `setVal("hello")`.
|
|
3684
3684
|
|
|
3685
3685
|
```typescript
|
|
3686
3686
|
// bad
|
|
@@ -3731,8 +3731,8 @@ if (!dragon.hasAge()) {
|
|
|
3731
3731
|
```typescript
|
|
3732
3732
|
class Jedi {
|
|
3733
3733
|
constructor(options: IJediOptions = {}) {
|
|
3734
|
-
const lightsaber = options.lightsaber ||
|
|
3735
|
-
this.set(
|
|
3734
|
+
const lightsaber = options.lightsaber || "blue";
|
|
3735
|
+
this.set("lightsaber", lightsaber);
|
|
3736
3736
|
}
|
|
3737
3737
|
|
|
3738
3738
|
set(key: string, val: any) {
|
|
@@ -3754,9 +3754,9 @@ class Jedi {
|
|
|
3754
3754
|
|
|
3755
3755
|
```typescript
|
|
3756
3756
|
// bad
|
|
3757
|
-
const event = new CustomEvent(
|
|
3757
|
+
const event = new CustomEvent("listingUpdated", { detail: listing.id });
|
|
3758
3758
|
|
|
3759
|
-
someElement.addEventListener(
|
|
3759
|
+
someElement.addEventListener("listingUpdated", (event: CustomEvent<string>) => {
|
|
3760
3760
|
// do something with event.detail
|
|
3761
3761
|
});
|
|
3762
3762
|
|
|
@@ -3771,7 +3771,7 @@ interface ListingUpdatedEventDetail {
|
|
|
3771
3771
|
listingId: string;
|
|
3772
3772
|
}
|
|
3773
3773
|
const event = new CustomEvent<ListingUpdatedEventDetail>(
|
|
3774
|
-
|
|
3774
|
+
"listingUpdated",
|
|
3775
3775
|
{
|
|
3776
3776
|
detail: {
|
|
3777
3777
|
listingId: listing.id,
|
|
@@ -3780,7 +3780,7 @@ const event = new CustomEvent<ListingUpdatedEventDetail>(
|
|
|
3780
3780
|
);
|
|
3781
3781
|
|
|
3782
3782
|
someElement.addEventListener(
|
|
3783
|
-
|
|
3783
|
+
"listingUpdated",
|
|
3784
3784
|
(event: CustomEvent<ListingUpdatedEventDetail>) => {
|
|
3785
3785
|
// do something with event.detail.listingId
|
|
3786
3786
|
},
|
|
@@ -3807,12 +3807,12 @@ contains utilities that are functionally broken but remain for legacy reasons.
|
|
|
3807
3807
|
|
|
3808
3808
|
```typescript
|
|
3809
3809
|
// bad
|
|
3810
|
-
isNaN(
|
|
3811
|
-
isNaN(
|
|
3810
|
+
isNaN("1.2"); // false
|
|
3811
|
+
isNaN("1.2.3"); // true
|
|
3812
3812
|
|
|
3813
3813
|
// good
|
|
3814
|
-
Number.isNaN(
|
|
3815
|
-
Number.isNaN(Number(
|
|
3814
|
+
Number.isNaN("1.2.3"); // false
|
|
3815
|
+
Number.isNaN(Number("1.2.3")); // true
|
|
3816
3816
|
```
|
|
3817
3817
|
|
|
3818
3818
|
---
|
|
@@ -3827,11 +3827,11 @@ Number.isNaN(Number('1.2.3')); // true
|
|
|
3827
3827
|
|
|
3828
3828
|
```typescript
|
|
3829
3829
|
// bad
|
|
3830
|
-
isFinite(
|
|
3830
|
+
isFinite("2e3"); // true
|
|
3831
3831
|
|
|
3832
3832
|
// good
|
|
3833
|
-
Number.isFinite(
|
|
3834
|
-
Number.isFinite(parseInt(
|
|
3833
|
+
Number.isFinite("2e3"); // false
|
|
3834
|
+
Number.isFinite(parseInt("2e3", 10)); // true
|
|
3835
3835
|
```
|
|
3836
3836
|
|
|
3837
3837
|
**[⬆ back to top](#table-of-contents)**
|
|
@@ -13,11 +13,6 @@ exports.stylisticIssues = {
|
|
|
13
13
|
* https://eslint.org/docs/rules/array-bracket-spacing
|
|
14
14
|
*/
|
|
15
15
|
"array-bracket-spacing": ["error", "never"],
|
|
16
|
-
/**
|
|
17
|
-
* enforce line breaks between array elements 🔧
|
|
18
|
-
* https://eslint.org/docs/rules/array-element-newline
|
|
19
|
-
*/
|
|
20
|
-
"array-element-newline": ["error", { multiline: true, minItems: 3 }],
|
|
21
16
|
/**
|
|
22
17
|
* enforce spacing inside single-line blocks 🔧
|
|
23
18
|
* https://eslint.org/docs/rules/block-spacing
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stylisticIssues.js","sourceRoot":"","sources":["../../../src/rules/stylisticIssues.ts"],"names":[],"mappings":";;;AAGA,gCAAgC;AACnB,QAAA,eAAe,GAAuB;IACjD;;;OAGG;IACH,uBAAuB,EAAE,CAAC,OAAO,EAAE,YAAY,CAAC;IAEhD;;;OAGG;IACH,uBAAuB,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC;IAE3C;;;OAGG;IACH,
|
|
1
|
+
{"version":3,"file":"stylisticIssues.js","sourceRoot":"","sources":["../../../src/rules/stylisticIssues.ts"],"names":[],"mappings":";;;AAGA,gCAAgC;AACnB,QAAA,eAAe,GAAuB;IACjD;;;OAGG;IACH,uBAAuB,EAAE,CAAC,OAAO,EAAE,YAAY,CAAC;IAEhD;;;OAGG;IACH,uBAAuB,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC;IAE3C;;;OAGG;IACH,eAAe,EAAE,CAAC,OAAO,EAAE,QAAQ,CAAC;IAEpC;;;OAGG;IACH,wBAAwB,EAAE,OAAO;IAEjC;;;OAGG;IACH,SAAS,EAAE,CAAC,OAAO,EAAE,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC;IAE7C;;;OAGG;IACH,sBAAsB,EAAE,KAAK;IAE7B;;;OAGG;IACH,yBAAyB,EAAE,CAAC,OAAO,EAAE,kBAAkB,CAAC;IAExD;;;OAGG;IACH,0BAA0B,EAAE,OAAO;IAEnC;;;OAGG;IACH,aAAa,EAAE,OAAO;IAEtB;;;OAGG;IACH,2BAA2B,EAAE,OAAO;IAEpC;;;;OAI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;;;OAGG;IACH,iBAAiB,EAAE,OAAO;IAE1B;;;OAGG;IACH,cAAc,EAAE,OAAO;IAEvB;;;OAGG;IACH,YAAY,EAAE,OAAO;IAErB;;;OAGG;IACH,WAAW,EAAE,KAAK;IAElB;;;OAGG;IACH,WAAW,EAAE,KAAK;IAElB;;;OAGG;IACH,qBAAqB,EAAE,OAAO;IAE9B;;;OAGG;IACH,wCAAwC,EAAE;QACxC,OAAO;QACP;YACE,SAAS,EAAE,QAAQ;YACnB,KAAK,EAAE,OAAO;YACd,UAAU,EAAE,QAAQ;SACrB;KACF;IAED;;;OAGG;IACH,iBAAiB,EAAE,OAAO;IAE1B;;;OAGG;IACH,4BAA4B,EAAE,OAAO;IAErC;;;OAGG;IACH,iBAAiB,EAAE,OAAO;IAE1B;;;OAGG;IACH,gBAAgB,EAAE,OAAO;IAEzB;;;OAGG;IACH,sBAAsB,EAAE,OAAO;IAE/B;;;OAGG;IACH,sBAAsB,EAAE,OAAO;IAE/B;;;OAGG;IACH,aAAa,EAAE,OAAO;IAEtB;;;OAGG;IACH,YAAY,EAAE,KAAK;CACpB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spscommerce/eslint-config-typescript",
|
|
3
|
-
"version": "8.2.
|
|
3
|
+
"version": "8.2.2",
|
|
4
4
|
"description": "SPS official linter configuration for TypeScript.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
|
-
"url": "https://github.com/SPSCommerce/
|
|
8
|
+
"url": "https://github.com/SPSCommerce/sps-js-shared.git"
|
|
9
9
|
},
|
|
10
10
|
"keywords": [
|
|
11
11
|
"style guide",
|
|
@@ -24,9 +24,9 @@
|
|
|
24
24
|
"author": "SPS Commerce",
|
|
25
25
|
"license": "MIT",
|
|
26
26
|
"bugs": {
|
|
27
|
-
"url": "https://github.com/SPSCommerce/
|
|
27
|
+
"url": "https://github.com/SPSCommerce/sps-js-shared/issues"
|
|
28
28
|
},
|
|
29
|
-
"homepage": "https://github.com/SPSCommerce/
|
|
29
|
+
"homepage": "https://github.com/SPSCommerce/sps-js-shared/tree/main/packages/%40spscommerce/eslint-config-typescript#readme",
|
|
30
30
|
"peerDependencies": {
|
|
31
31
|
"@stylistic/eslint-plugin": "^3.1.0",
|
|
32
32
|
"@typescript-eslint/eslint-plugin": "^8.24.1",
|