{"record":{"id":"a00452423f9840ac","repo":"oxc-project/oxc","slug":"unexpected-commas-in-middle-of-array","errorCode":null,"errorMessage":"{} unexpected commas in middle of array","messagePattern":"(.+?) unexpected commas in middle of array","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/no_sparse_arrays.rs","lineNumber":93,"sourceCode":"            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                        ))\n                        .with_help(\"remove the comma or insert `undefined`\")\n                        .with_label(span),\n                    );\n                }\n            }\n        }\n    }\n}\n\n#[test]\nfn test() {\n    use crate::tester::Tester;\n\n    let pass = vec![\"var a = [ 1, 2, ]\", \"var a = [];\"];\n","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/no_sparse_arrays.rs#L75-L111","documentation":"Same `no-sparse-arrays` rule, but for arrays with 10 or more holes the per-hole labels are replaced by one aggregated message `\"{n} unexpected commas in middle of array\"`. If the array's source span is under 50 chars the whole array is labeled `\"the array here\"`; otherwise a zero-width label `\"the array starting here\"` points at the array's start. This keeps the diagnostic readable instead of spraying dozens of labels.","triggerScenarios":"An array literal with `violations.len() >= 10` elisions, e.g. `const a = [,,,,,,,,,,];` — commonly the result of fat-fingered commas or generated data.","commonSituations":"Generated or data-table literals where many entries were removed; accidental long runs of commas from merge conflicts or spreadsheet exports; test fixtures for Array(n)-like behavior written as literals.","solutions":["Replace the hole-filled literal with `Array(n)` or `Array.from({ length: n }, ...)`.","If the array is data, re-export it without empty cells rather than hand-editing commas.","After fixing, re-run oxlint on the file to confirm the rule is quiet."],"exampleFix":"// before\nconst slots = [,,,,,,,,,,];\n\n// after\nconst slots = Array(10);","handlingStrategy":"validation","validationCode":"# catch big hole-runs in literals before commit\nrg -n '(\\s*,){9,}' src/","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Generate large arrays with Array.from, not comma-filled literals.","Validate spreadsheet/JSON exports before pasting them into JS source.","Keep no-sparse-arrays enabled so any regression is flagged immediately."],"tags":["eslint","oxlint","no-sparse-arrays","arrays","holes","aggregate-diagnostic"],"backgroundTag":"sparse-array","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}