Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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