@@ -5,6 +5,7 @@ use oxc_ast::{
55use oxc_diagnostics:: OxcDiagnostic ;
66use oxc_macros:: declare_oxc_lint;
77use oxc_span:: { CompactStr , GetSpan , Span } ;
8+ use schemars:: JsonSchema ;
89
910use 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 ) ]
1819pub struct NoCallbackInPromise ( Box < NoCallbackInPromiseConfig > ) ;
1920
20- #[ derive( Debug , Clone ) ]
21+ #[ derive( Debug , Clone , JsonSchema ) ]
22+ #[ serde( rename_all = "camelCase" , default ) ]
2123pub struct NoCallbackInPromiseConfig {
22- callbacks : Vec < CompactStr > ,
24+ /// An array of callback names to allow in promises.
25+ exceptions : Vec < CompactStr > ,
2326}
2427
2528impl 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
7781impl 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