Skip to content

Commit c7c9213

Browse files
authored
docs(linter): Add configuration option docs for oxc/no-optional-chaining rule. (#15071)
Part of #14743. Generated docs: ```md ## Configuration This rule accepts a configuration object with the following properties: ### message type: `string` default: `""` A custom help message to display when optional chaining is found. For example, "Our output target is ES2016, and optional chaining results in verbose helpers and should be avoided." ```
1 parent c0dfd9b commit c7c9213

File tree

1 file changed

+7
-20
lines changed

1 file changed

+7
-20
lines changed

crates/oxc_linter/src/rules/oxc/no_optional_chaining.rs

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use oxc_ast::AstKind;
22
use oxc_diagnostics::OxcDiagnostic;
33
use oxc_macros::declare_oxc_lint;
44
use oxc_span::Span;
5+
use schemars::JsonSchema;
56

67
use 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)]
1920
pub struct NoOptionalChaining(Box<NoOptionalChainingConfig>);
2021

21-
#[derive(Debug, Default, Clone)]
22+
#[derive(Debug, Default, Clone, JsonSchema)]
23+
#[serde(rename_all = "camelCase", default)]
2224
pub 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

7966
impl Rule for NoOptionalChaining {

0 commit comments

Comments
 (0)