{"record":{"id":"c610057abefe9f75","repo":"oxc-project/oxc","slug":"empty-array-binding-pattern","errorCode":null,"errorMessage":"Empty array binding pattern","messagePattern":"Empty array binding pattern","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/no_empty_pattern.rs","lineNumber":16,"sourceCode":"use schemars::JsonSchema;\nuse serde::Deserialize;\n\nuse oxc_ast::{AstKind, ast::Expression};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\n\nuse crate::{\n    AstNode,\n    context::LintContext,\n    rule::{DefaultRuleConfig, Rule},\n};\n\nfn no_empty_array_pattern_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Empty array binding pattern\")\n        .with_help(\"Passing non-iterable values (null, undefined, numbers, booleans, etc.) will result in a runtime error because these values are not iterable.\")\n        .with_label(span)\n}\n\nfn no_empty_object_pattern_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Empty object binding pattern\")\n        .with_help(\"Passing `null` or `undefined` will result in runtime error because `null` and `undefined` cannot be destructured.\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone, JsonSchema, Deserialize)]\n#[serde(rename_all = \"camelCase\", default, deny_unknown_fields)]\npub struct NoEmptyPattern {\n    /// When set to `true`, this rule allows empty object patterns used directly as function\n    /// parameters, including parameters defaulted to an empty object literal.\n    allow_object_patterns_as_parameters: bool,\n}\n","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/no_empty_pattern.rs#L1-L34","documentation":"Diagnostic from oxlint's port of ESLint's no-empty-pattern rule (array variant). It fires on any array destructuring pattern with zero elements, e.g. `var [] = foo`. An empty pattern creates no variables yet still forces the engine to iterate the value at runtime, so non-iterables (null, undefined, numbers, booleans) throw a TypeError. It is almost always a typo where the author meant a default value or deleted the bound names.","triggerScenarios":"Any zero-element ArrayPattern anywhere in the AST: `var [] = foo;`, `const {a: []} = foo;` (nested), `function foo([]) {}` (parameter), per the `AstKind::ArrayPattern if array.is_empty()` check. Unlike the object variant, no option suppresses the array form.","commonSituations":"Intended a default (`var {a = []} = foo`) but wrote the pattern form (`var {a: []} = foo`); names removed during refactoring leaving `[]` behind; empty destructured parameters used as 'takes an array' documentation; auto-generated code emitting empty patterns.","solutions":["If you meant a default value, move the brackets to the initializer: `var {a = []} = foo;`","If no binding is needed, delete the empty pattern entirely.","For parameters, destructure the fields you actually use, or accept the whole value: `function foo(options) {}`.","If it is provably intentional, suppress once with an `oxlint-disable no-empty-pattern` comment (no config option exists for the array form)."],"exampleFix":"// before\nvar {a: []} = foo;\nfunction foo([]) {}\n\n// after\nvar {a = []} = foo;\nfunction foo(a = []) {}","handlingStrategy":"validation","validationCode":"# CI gate: fail on the diagnostic before it reaches users\noxlint --deny-warnings --rule 'no-empty-pattern=warn' src/","typeGuard":"// optional runtime guard if you must destructure unknown input\nconst isIterable = (v: unknown): v is Iterable<unknown> =>\n  v != null && typeof (v as Iterable<unknown>)[Symbol.iterator] === 'function';","tryCatchPattern":null,"preventionTips":["Write defaults as `= []`, never as nested empty patterns (`{a: []}` vs `{a = []}`).","Delete pattern elements instead of emptying them when removing variables.","Keep no-empty-pattern enabled in the eslint/correctness category — it is on by default in oxlint."],"tags":["eslint","destructuring","oxlint","lint","correctness"],"backgroundTag":"empty-destructuring-pattern","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"}