unicorn/no-thenable
eslint-plugin-unicorn
No autofix
eslint.config.js
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/no-thenable": "error",
},
},
];const foo = {
unicorn: 1,
then() {},
};
const {unicorn} = await foo;
console.log('after'); //<- This will never executeconst foo = {
unicorn: 1,
then() {
throw new Error('You shouldn’t have called me')
},
};
const {unicorn} = await foo;
// Error: You shouldn’t have called me// foo.js
export function then () {
throw new Error('You shouldn’t have called me')
}export {resolve};const foo = {
success() {}
};const foo = {
get success() {}
};Examples from the ESLint documentation.
unicorn/no-thenable
eslint-plugin-unicorn
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/no-thenable": "error",
},
},
];unicorn/no-thenable
unicorn plugin · correctness
{
"rules": {
"unicorn/no-thenable": "error"
}
}suspicious/noThenProperty
suspicious · since 1.5.0
{
"linter": {
"rules": {
"suspicious": {
"noThenProperty": "error"
}
}
}
}Disallow passing single-element arrays to Promise methods.
Disallow useless fallback when spreading in object literals.
Prevent calling EventTarget#removeEventListener() with the result of an expression.
Disallow useless array length check.
Disallow invalid options in fetch() and new Request().