Enforce Promises with specified syntax to be handled appropriately (no-restricted-floating-promises
)
A "floating" Promise is one that is created without any code set up to handle any errors it might throw.
Floating Promises can cause several issues, such as improperly sequenced operations, ignored Promise rejections, and more.
This rule is similar to @typescript-eslint/no-floating-promises
, except that it only checks Promise expressions with the specified syntax.
This rule has a list of string or object options. Each option can be:
- An AST Selector string
- An object with the following properties:
type
: Predefined selector, such asvuex-action
,element-message-box
orvant-dialog
selector
: An AST Selector stringpaths
: An array of ignore pattern, meaning that promises generated by functions imported from specified modules will be checkedmessage
: Custom reporting message
/* eslint galaxy/no-restricted-floating-promises: ["error", "CallExpression[callee.name='foo']"] */
foo()
/* eslint galaxy/no-restricted-floating-promises: ["error", "CallExpression[callee.name='foo']"] */
Promise.all([foo()])
/* eslint galaxy/no-restricted-floating-promises: ["error", "CallExpression[callee.name='foo']"] */
Promise.resolve(foo())
/* eslint galaxy/no-restricted-floating-promises: ["error", "CallExpression[callee.name='foo']"] */
foo().then(() => {})
/* eslint galaxy/no-restricted-floating-promises: ["error", { "type": "vuex-action" }] */
this.$store.dispatch('submit')
/* eslint galaxy/no-restricted-floating-promises: ["error", { "type": "element-message-box" }] */
this.$confirm({})
/* eslint galaxy/no-restricted-floating-promises: ["error", { "type": "vant-dialog" }] */
this.$dialog.confirm({})
/* eslint galaxy/no-restricted-floating-promises: ["error", { "names": ["foo"] }] */
foo()
/* eslint galaxy/no-restricted-floating-promises: ["error", { "paths": ["foo"] }] */
import { foo } from 'foo'
foo()
/* eslint galaxy/no-restricted-floating-promises: ["error", "CallExpression[callee.name='foo']"] */
bar()
/* eslint galaxy/no-restricted-floating-promises: ["error", "CallExpression[callee.name='foo']"] */
foo().catch(() => {})
/* eslint galaxy/no-restricted-floating-promises: ["error", "CallExpression[callee.name='foo']"] */
foo().then(() => {}, () => {})
/* eslint galaxy/no-restricted-floating-promises: ["error", "CallExpression[callee.name='foo']"] */
await foo()
/* eslint galaxy/no-restricted-floating-promises: ["error", "CallExpression[callee.name='foo']"] */
wrap(foo())
/* eslint galaxy/no-restricted-floating-promises: ["error", { "names": ["foo"] }] */
bar()
/* eslint galaxy/no-restricted-floating-promises: ["error", { "paths": ["foo"] }] */
import { foo } from 'bar'
foo()