1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 09:57:02 +01:00

Add ESLint rule no-async-promise-executor (#7659)

This rule prevents using an async function as a Promise executor (e.g.
as the argument to a `Promise` constructor). This pattern is usually a
mistake because it implies that the Promise constructor was not
necessary in the first place. It also makes error handling difficult,
as any errors thrown would be uncaught unless you wrap the body in a
try/catch block.
This commit is contained in:
Mark Stacey 2019-12-06 11:32:36 -04:00 committed by GitHub
parent e87e79870a
commit 975419db54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 17 deletions

View File

@ -69,6 +69,7 @@
"new-cap": [2, { "newIsCap": true, "capIsNew": false }],
"new-parens": 2,
"no-array-constructor": 2,
"no-async-promise-executor": "error",
"no-caller": 2,
"no-class-assign": 2,
"no-cond-assign": 2,

View File

@ -2,26 +2,22 @@ function delay (time) {
return new Promise(resolve => setTimeout(resolve, time))
}
function loadFromMock3Box (key) {
return new Promise(async (resolve) => {
const res = await fetch('http://localhost:8889?key=' + key)
const text = await res.text()
resolve(text.length ? JSON.parse(text) : null)
})
async function loadFromMock3Box (key) {
const res = await fetch('http://localhost:8889?key=' + key)
const text = await res.text()
return text.length ? JSON.parse(text) : null
}
function saveToMock3Box (key, newDataAtKey) {
return new Promise(async (resolve) => {
const res = await fetch('http://localhost:8889', {
method: 'POST',
body: JSON.stringify({
key,
data: newDataAtKey,
}),
})
resolve(res.text())
async function saveToMock3Box (key, newDataAtKey) {
const res = await fetch('http://localhost:8889', {
method: 'POST',
body: JSON.stringify({
key,
data: newDataAtKey,
}),
})
return res.text()
}
class Mock3Box {