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

Lines changed: 18 additions & 5 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy