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
12 changes: 10 additions & 2 deletions crates/oxc_linter/src/rules/eslint/no_unneeded_ternary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use oxc_ast::{
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::{GetSpan, Span};
use schemars::JsonSchema;

fn no_unneeded_ternary_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Unnecessary use of boolean literals in conditional expression")
Expand All @@ -19,8 +20,14 @@ fn no_unneeded_ternary_conditional_expression_diagnostic(span: Span) -> OxcDiagn
.with_label(span)
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, JsonSchema)]
#[serde(rename_all = "camelCase", default)]
pub struct NoUnneededTernary {
/// Whether to allow the default assignment pattern `x ? x : y`.
///
/// When set to `false`, the rule also flags cases like `x ? x : y` and suggests using
/// the logical OR form `x || y` instead. When `true` (default), such default assignments
/// are allowed and not reported.
default_assignment: bool,
}

Expand Down Expand Up @@ -63,7 +70,8 @@ declare_oxc_lint!(
NoUnneededTernary,
eslint,
suspicious,
fix_dangerous
fix_dangerous,
config = NoUnneededTernary,
);

impl Rule for NoUnneededTernary {
Expand Down
Loading