{"record":{"id":"3d6b607d63328d34","repo":"oxc-project/oxc","slug":"unexpected-comma-in-middle-of-array","errorCode":null,"errorMessage":"Unexpected comma in middle of array","messagePattern":"Unexpected comma in middle of array","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/no_sparse_arrays.rs","lineNumber":78,"sourceCode":"impl Rule for NoSparseArrays {\n    fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {\n        if let AstKind::ArrayExpression(array_expr) = node.kind() {\n            let violations = array_expr\n                .elements\n                .iter()\n                .filter_map(|el| match el {\n                    ArrayExpressionElement::Elision(elision) => Some(elision),\n                    _ => None,\n                })\n                .map(|elision| {\n                    LabeledSpan::at(elision.span.start..elision.span.start, \"unexpected comma\")\n                })\n                .collect::<Vec<_>>();\n\n            if !violations.is_empty() {\n                if violations.len() < 10 {\n                    ctx.diagnostic(\n                        OxcDiagnostic::warn(\"Unexpected comma in middle of array\")\n                            .with_help(\"remove the comma or insert `undefined`\")\n                            .with_labels(violations),\n                    );\n                } else {\n                    let span = if (array_expr.span.end - array_expr.span.start) < 50 {\n                        LabeledSpan::at(array_expr.span, \"the array here\")\n                    } else {\n                        LabeledSpan::at(\n                            array_expr.span.start..array_expr.span.start,\n                            \"the array starting here\",\n                        )\n                    };\n\n                    ctx.diagnostic(\n                        OxcDiagnostic::warn(format!(\n                            \"{} unexpected commas in middle of array\",\n                            violations.len()\n                        ))","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/no_sparse_arrays.rs#L60-L96","documentation":"`no-sparse-arrays` reports arrays containing elisions (holes), e.g. `[,,1]`. This variant fires when fewer than 10 holes exist: each elision gets its own zero-width label `\"unexpected comma\"` at the hole's start offset, and one diagnostic carries all the labels. Holes are `undefined` slots that most array methods (map, forEach, filter) skip, which makes behavior surprising.","triggerScenarios":"Any `ArrayExpressionElement::Elision` in an array literal: `[,,]`, `[1,,3]`, trailing `[,]`. Emitted from the `run` visitor when `violations` is non-empty and `violations.len() < 10`.","commonSituations":"Typo like a double comma when editing large literal arrays; code relying on `Array(n)`-style hole semantics via literals; JSON-ish config data pasted into JS where a value was deleted leaving `[a,,c]`.","solutions":["Remove the extra comma so the array has no holes: `[1, 2, 3]`.","If holes are intentional, use `Array(n)` or `Array.from({length: n})` to express intent explicitly.","If the hole means 'no value', write `undefined` explicitly: `[1, undefined, 3]`."],"exampleFix":"// before\nconst scores = [90, , 75];\n\n// after\nconst scores = [90, undefined, 75];","handlingStrategy":"validation","validationCode":"// runtime hole check for arrays crossing API boundaries\nfunction hasHoles(arr) {\n  for (let i = 0; i < arr.length; i++) if (!(i in arr)) return true;\n  return false;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Write explicit `undefined` (or Array(n)) instead of holes in literals.","Remember map/forEach/filter skip holes — dense arrays behave predictably.","Lint data exports and generated literals where stray commas creep in."],"tags":["eslint","oxlint","no-sparse-arrays","arrays","holes","elision"],"backgroundTag":"sparse-array","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"}