Skip to content

Commit

Permalink
fix(linter): move promise/avoid-new to style category (#5961)
Browse files Browse the repository at this point in the history
  • Loading branch information
DonIsaac committed Sep 22, 2024
1 parent f1551d6 commit 40c89c2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
21 changes: 17 additions & 4 deletions crates/oxc_linter/src/rules/promise/avoid_new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
/// function foo() {
/// return new Promise((resolve, reject) => { /* ... */ });
/// }
/// ```
///
/// Examples of **correct** code for this rule:
/// ```javascript
/// new Promise((resolve, reject) => { /* ... */ });
/// async function foo() {
/// // ...
/// }
/// const bar = await Promise.all([baz(), bang()]);
/// ```
AvoidNew,
restriction,
style,
);

impl Rule for AvoidNew {
Expand Down
11 changes: 7 additions & 4 deletions crates/oxc_linter/src/rules/promise/catch_or_return.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
///
Expand Down

0 comments on commit 40c89c2

Please sign in to comment.