fix(linter): move promise/avoid-new to style category (#5961)

This commit is contained in:
DonIsaac 2024-09-22 04:25:47 +00:00
parent f1551d64bc
commit 40c89c2c5f
2 changed files with 24 additions and 8 deletions

View file

@ -15,18 +15,31 @@ pub struct AvoidNew;
declare_oxc_lint!(
/// ### What it does
///
/// Disallow creating new promises outside of utility libs.
/// Disallow creating promises with `new Promise()`.
///
/// ### 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
///
/// Examples of **incorrect** code for this rule:
/// ```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,
restriction,
style,
);
impl Rule for AvoidNew {

View file

@ -49,13 +49,16 @@ impl std::ops::Deref for CatchOrReturn {
declare_oxc_lint!(
/// ### What it does
///
/// Ensure that each time a then() is applied to a promise, a catch() is applied as well.
/// Exceptions are made if you are returning that promise.
/// Ensure that each time a `then()` is applied to a promise, a `catch()`
/// must be applied as well. Exceptions are made for promises returned from
/// a function.
///
/// ### Why is this bad?
///
/// Not catching errors in a promise can cause hard to debug problems or missing handling of
/// error conditions.
/// Not catching errors in a promise can cause hard to debug problems or
/// missing handling of error conditions. In the worst case, unhandled
/// promise rejections can cause your application to crash.
///
///
/// ### Example
///