@@ -2,6 +2,7 @@ use oxc_ast::AstKind;
22use oxc_diagnostics:: OxcDiagnostic ;
33use oxc_macros:: declare_oxc_lint;
44use oxc_span:: Span ;
5+ use schemars:: JsonSchema ;
56
67use crate :: { AstNode , context:: LintContext , rule:: Rule } ;
78
@@ -18,8 +19,12 @@ fn no_optional_chaining_diagnostic(span: Span, help: &str) -> OxcDiagnostic {
1819#[ derive( Debug , Default , Clone ) ]
1920pub struct NoOptionalChaining ( Box < NoOptionalChainingConfig > ) ;
2021
21- #[ derive( Debug , Default , Clone ) ]
22+ #[ derive( Debug , Default , Clone , JsonSchema ) ]
23+ #[ serde( rename_all = "camelCase" , default ) ]
2224pub struct NoOptionalChainingConfig {
25+ /// A custom help message to display when optional chaining is found.
26+ /// For example, "Our output target is ES2016, and optional chaining results in verbose
27+ /// helpers and should be avoided."
2328 message : String ,
2429}
2530
@@ -52,28 +57,10 @@ declare_oxc_lint!(
5257 /// const foo = obj?.foo;
5358 /// obj.fn?.();
5459 /// ```
55- ///
56- /// ### Options
57- ///
58- /// ```json
59- /// {
60- /// "rules": {
61- /// "no-optional-chaining": [
62- /// "error",
63- /// {
64- /// "message": "Our output target is ES2016, and optional chaining results in verbose
65- /// helpers and should be avoided.",
66- /// }
67- /// ]
68- /// }
69- /// }
70- /// ```
71- ///
72- /// - `message`: A custom help message to display when optional chaining is found.
73- ///
7460 NoOptionalChaining ,
7561 oxc,
7662 restriction,
63+ config = NoOptionalChainingConfig ,
7764) ;
7865
7966impl Rule for NoOptionalChaining {
0 commit comments