Skip to content

Commit 0e719dc

Browse files
committed
docs(linter): Add configuration option docs for promise/no-callback-in-promise rule.
Also rename the struct field name from `callbacks` to `exceptions`, as that's what is actually used in the code and is what's defined in the original ESLint rule.
1 parent baaeca8 commit 0e719dc

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

crates/oxc_linter/src/rules/promise/no_callback_in_promise.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use oxc_ast::{
55
use oxc_diagnostics::OxcDiagnostic;
66
use oxc_macros::declare_oxc_lint;
77
use oxc_span::{CompactStr, GetSpan, Span};
8+
use schemars::JsonSchema;
89

910
use crate::{AstNode, context::LintContext, rule::Rule};
1011

@@ -17,14 +18,16 @@ fn no_callback_in_promise_diagnostic(span: Span) -> OxcDiagnostic {
1718
#[derive(Debug, Default, Clone)]
1819
pub struct NoCallbackInPromise(Box<NoCallbackInPromiseConfig>);
1920

20-
#[derive(Debug, Clone)]
21+
#[derive(Debug, Clone, JsonSchema)]
22+
#[serde(rename_all = "camelCase", default)]
2123
pub struct NoCallbackInPromiseConfig {
22-
callbacks: Vec<CompactStr>,
24+
/// An array of callback names to allow in promises.
25+
exceptions: Vec<CompactStr>,
2326
}
2427

2528
impl Default for NoCallbackInPromiseConfig {
2629
fn default() -> Self {
27-
Self { callbacks: vec!["callback".into(), "cb".into(), "done".into(), "next".into()] }
30+
Self { exceptions: vec!["callback".into(), "cb".into(), "done".into(), "next".into()] }
2831
}
2932
}
3033

@@ -72,6 +75,7 @@ declare_oxc_lint!(
7275
NoCallbackInPromise,
7376
promise,
7477
correctness,
78+
config = NoCallbackInPromiseConfig,
7579
);
7680

7781
impl Rule for NoCallbackInPromise {
@@ -87,7 +91,7 @@ impl Rule for NoCallbackInPromise {
8791
})
8892
.unwrap_or_default();
8993

90-
default_config.callbacks.retain(|item| !exceptions.contains(&item.to_string()));
94+
default_config.exceptions.retain(|item| !exceptions.contains(&item.to_string()));
9195

9296
Self(Box::new(default_config))
9397
}
@@ -100,7 +104,7 @@ impl Rule for NoCallbackInPromise {
100104
let is_not_callback = call_expr
101105
.callee
102106
.get_identifier_reference()
103-
.is_none_or(|id| self.callbacks.binary_search(&id.name.as_str().into()).is_err());
107+
.is_none_or(|id| self.exceptions.binary_search(&id.name.as_str().into()).is_err());
104108

105109
if is_not_callback {
106110
if Self::has_promise_callback(call_expr) {
@@ -111,7 +115,7 @@ impl Rule for NoCallbackInPromise {
111115
};
112116

113117
let name = id.name.as_str();
114-
if self.callbacks.binary_search(&name.into()).is_ok() {
118+
if self.exceptions.binary_search(&name.into()).is_ok() {
115119
ctx.diagnostic(no_callback_in_promise_diagnostic(id.span));
116120
}
117121
}

0 commit comments

Comments
 (0)