Skip to content

Commit 72c0daa

Browse files
authored
Update no-then.md
The 'improved code' after linting was unnecessarily complex introducing a named variable across multiple lines for no reason which made it look better to keep using `then`. A bit surprising. Previous catch example was code which didn't differentiate between failing case (which is now a deliberate null) and undefined case (which is often the result of an error).
1 parent e77f49c commit 72c0daa

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

docs/rules/no-then.md

+18-5
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,39 @@ https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/asy
1212

1313
👎 Examples of **incorrect** code for this rule:
1414

15+
```js
16+
function countData(url) {
17+
return downloadData(url).then(data => {
18+
return data.length
19+
})
20+
}
21+
```
22+
1523
```js
1624
function getProcessedData(url) {
1725
return downloadData(url).catch(e => {
1826
console.log('Error occurred!', e)
27+
return null;
1928
})
2029
}
2130
```
2231

2332
👍 Examples of **correct** code for this rule:
2433

34+
```js
35+
async function countProcessedData(url) {
36+
const data = await downloadData(url);
37+
return data.length
38+
```
39+
2540
```js
2641
async function getProcessedData(url) {
27-
let v
2842
try {
29-
v = await downloadData(url)
43+
return await downloadData(url)
3044
} catch (e) {
31-
console.log('Error occurred!', e)
32-
return
45+
console.log('Error occurred!', e);
46+
return null;
3347
}
34-
return v
3548
}
3649
```
3750

0 commit comments

Comments
 (0)