mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
fix(linter): move promise/avoid-new to style category (#5961)
This commit is contained in:
parent
f1551d64bc
commit
40c89c2c5f
2 changed files with 24 additions and 8 deletions
|
|
@ -15,18 +15,31 @@ pub struct AvoidNew;
|
||||||
declare_oxc_lint!(
|
declare_oxc_lint!(
|
||||||
/// ### What it does
|
/// ### What it does
|
||||||
///
|
///
|
||||||
/// Disallow creating new promises outside of utility libs.
|
/// Disallow creating promises with `new Promise()`.
|
||||||
///
|
///
|
||||||
/// ### Why is this bad?
|
/// ### Why is this bad?
|
||||||
///
|
///
|
||||||
/// If you dislike the new promise style promises.
|
/// Many cases that use `new Promise()` could be refactored to use an
|
||||||
|
/// `async` function. `async` is considered more idiomatic in modern JavaScript.
|
||||||
///
|
///
|
||||||
/// ### Example
|
/// ### Example
|
||||||
|
///
|
||||||
|
/// Examples of **incorrect** code for this rule:
|
||||||
/// ```javascript
|
/// ```javascript
|
||||||
/// new Promise((resolve, reject) => { /* ... */ });
|
/// function foo() {
|
||||||
|
/// return new Promise((resolve, reject) => { /* ... */ });
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// Examples of **correct** code for this rule:
|
||||||
|
/// ```javascript
|
||||||
|
/// async function foo() {
|
||||||
|
/// // ...
|
||||||
|
/// }
|
||||||
|
/// const bar = await Promise.all([baz(), bang()]);
|
||||||
/// ```
|
/// ```
|
||||||
AvoidNew,
|
AvoidNew,
|
||||||
restriction,
|
style,
|
||||||
);
|
);
|
||||||
|
|
||||||
impl Rule for AvoidNew {
|
impl Rule for AvoidNew {
|
||||||
|
|
|
||||||
|
|
@ -49,13 +49,16 @@ impl std::ops::Deref for CatchOrReturn {
|
||||||
declare_oxc_lint!(
|
declare_oxc_lint!(
|
||||||
/// ### What it does
|
/// ### What it does
|
||||||
///
|
///
|
||||||
/// Ensure that each time a then() is applied to a promise, a catch() is applied as well.
|
/// Ensure that each time a `then()` is applied to a promise, a `catch()`
|
||||||
/// Exceptions are made if you are returning that promise.
|
/// must be applied as well. Exceptions are made for promises returned from
|
||||||
|
/// a function.
|
||||||
///
|
///
|
||||||
/// ### Why is this bad?
|
/// ### Why is this bad?
|
||||||
///
|
///
|
||||||
/// Not catching errors in a promise can cause hard to debug problems or missing handling of
|
/// Not catching errors in a promise can cause hard to debug problems or
|
||||||
/// error conditions.
|
/// missing handling of error conditions. In the worst case, unhandled
|
||||||
|
/// promise rejections can cause your application to crash.
|
||||||
|
///
|
||||||
///
|
///
|
||||||
/// ### Example
|
/// ### Example
|
||||||
///
|
///
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue