From 2af461c1312abf33f87a189e0ce1888f6885d32b Mon Sep 17 00:00:00 2001 From: Oliver Sieweke Date: Mon, 17 Jun 2019 12:26:48 +0200 Subject: [PATCH] Docs: Clarify prefer-destructuring array/object difference (fixes #9970) --- docs/rules/prefer-destructuring.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/rules/prefer-destructuring.md b/docs/rules/prefer-destructuring.md index 8525dc2d0ef..00b55774b21 100644 --- a/docs/rules/prefer-destructuring.md +++ b/docs/rules/prefer-destructuring.md @@ -16,6 +16,11 @@ One key is `VariableDeclarator` and the other is `AssignmentExpression`, which c The rule has a second object with a single key, `enforceForRenamedProperties`, which determines whether the `object` destructuring applies to renamed variables. +**Note**: It is not possible to determine if a variable will be referring to an object or an array at runtime. This rule therefore guesses the assignment type by checking whether the key being accessed is an integer. This can lead to the following possibly confusing situations: + +- Accessing an object property whose key is an integer will fall under the category `array` destructuring. +- Accessing an array element through a computed index will fall under the category `object` destructuring. + Examples of **incorrect** code for this rule: ```javascript