{"record":{"id":"25f954ac8b3773e1","repo":"oxc-project/oxc","slug":"prefer-consistent-types-when-spreading-a-ternary-i","errorCode":null,"errorMessage":"Prefer consistent types when spreading a ternary in an array literal.","messagePattern":"Prefer consistent types when spreading a ternary in an array literal\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/unicorn/consistent_empty_array_spread.rs","lineNumber":9,"sourceCode":"use oxc_ast::{AstKind, ast::Expression};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\n\nuse crate::{AstNode, ast_util::outermost_paren_parent, context::LintContext, rule::Rule};\n\nfn consistent_empty_array_spread_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Prefer consistent types when spreading a ternary in an array literal.\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct ConsistentEmptyArraySpread;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// When spreading a ternary in an array, we can use both `[]` and `''` as fallbacks,\n    /// but it's better to have consistent types in both branches.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// Having consistent types in both branches makes the code easier to read and understand.\n    ///\n    /// ### Examples\n    ///","sourceCodeStart":1,"sourceCodeEnd":27,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/unicorn/consistent_empty_array_spread.rs#L1-L27","documentation":"Diagnostic from oxlint's `unicorn/consistent-empty-array-spread` rule. When a ternary is spread into an array literal and one branch is an array while the other is the empty string `''`, the fallback type is inconsistent — both contribute nothing when spread, but mixing types is confusing. The rule suggests making both branches arrays. It is registered as a suggestion, so it is applied via the fix/suggestion flow rather than silently.","triggerScenarios":"A ConditionalExpression directly inside a SpreadElement inside an ArrayExpression where exactly one branch is an ArrayExpression and the other is an empty string literal: `[...(foo ? [b, c] : '')]` or the mirrored `[...(foo ? 'bc' : [])]`. Ternaries in call arguments or elsewhere are not flagged.","commonSituations":"Building filter/part lists with conditional segments; code migrated from string-concatenation styles where `''` was the natural empty fallback; enabling the unicorn pedantic preset.","solutions":["Replace the empty-string fallback with `[]` so both branches are arrays.","If strings are the intended element source, make both branches strings and spread outside the ternary.","Prefer `.concat`/`.flat()` composition when branch types genuinely differ."],"exampleFix":"// before\nconst parts = [\n  a,\n  ...(foo ? [b, c] : ''),\n];\n// after\nconst parts = [\n  a,\n  ...(foo ? [b, c] : []),\n];","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use `[]` as the empty fallback in every spread ternary so both branches are arrays.","Keep ternary branches type-consistent before spreading into array literals.","Prefer explicit conditionals building the array (`foo ? [...xs, b, c] : xs`) when branch shapes diverge."],"tags":["oxlint","lint","unicorn","arrays","spread","types"],"backgroundTag":"array-spread-type-consistency","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}