diff --git a/crates/oxc_linter/src/rules/promise/avoid_new.rs b/crates/oxc_linter/src/rules/promise/avoid_new.rs index 700536381ff0d..39ce36100e963 100644 --- a/crates/oxc_linter/src/rules/promise/avoid_new.rs +++ b/crates/oxc_linter/src/rules/promise/avoid_new.rs @@ -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 { diff --git a/crates/oxc_linter/src/rules/promise/catch_or_return.rs b/crates/oxc_linter/src/rules/promise/catch_or_return.rs index 83e5760655210..20b8447b04fbf 100644 --- a/crates/oxc_linter/src/rules/promise/catch_or_return.rs +++ b/crates/oxc_linter/src/rules/promise/catch_or_return.rs @@ -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 ///