Skip to content
Merged
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
27 changes: 7 additions & 20 deletions crates/oxc_linter/src/rules/oxc/no_optional_chaining.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use oxc_ast::AstKind;
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;
use schemars::JsonSchema;

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

Expand All @@ -18,8 +19,12 @@ fn no_optional_chaining_diagnostic(span: Span, help: &str) -> OxcDiagnostic {
#[derive(Debug, Default, Clone)]
pub struct NoOptionalChaining(Box<NoOptionalChainingConfig>);

#[derive(Debug, Default, Clone)]
#[derive(Debug, Default, Clone, JsonSchema)]
#[serde(rename_all = "camelCase", default)]
pub struct NoOptionalChainingConfig {
/// 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."
message: String,
}

Expand Down Expand Up @@ -52,28 +57,10 @@ declare_oxc_lint!(
/// const foo = obj?.foo;
/// obj.fn?.();
/// ```
///
/// ### Options
///
/// ```json
/// {
/// "rules": {
/// "no-optional-chaining": [
/// "error",
/// {
/// "message": "Our output target is ES2016, and optional chaining results in verbose
/// helpers and should be avoided.",
/// }
/// ]
/// }
/// }
/// ```
///
/// - `message`: A custom help message to display when optional chaining is found.
///
NoOptionalChaining,
oxc,
restriction,
config = NoOptionalChainingConfig,
);

impl Rule for NoOptionalChaining {
Expand Down
Loading