From 65faa04e8b42eecd4505111bbff296951179f033 Mon Sep 17 00:00:00 2001 From: Oliver Sieweke Date: Tue, 18 Jun 2019 03:46:56 +0200 Subject: [PATCH] Docs: Clarify prefer-destructuring array/object difference (fixes #9970) (#11851) --- 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