Add rule options for useDestructuring to disable array checks on simple index operations
#8785
Bertie690
started this conversation in
Rule suggestion
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
useDestructuringwould be a nice rule to enable for our team, were it not for it insisting on destructuring every single index signature in our codebase.The benefits of enforcing destructured arrays for simple cases like
const foo = arr[0]range from dubious to absolutely nonsensical depending on the index number in question.That being said, I also feel there should be a middle ground between "no enforcement" and "full enforcement".
For instance, consecutive array references like this would be far better candidates for destructuring IMO (and ones that I would prefer being flagged):
In light of this, I suggest adding a rule option for
useDestructuring, tentatively namedcheckArrays.It would take 3 distinct values, as described here: (names to be discussed)
"on"- Current behavior, check all forms of array indexing"off"- Completely disable checks on array indexing"multiple"/"consecutive"(name TBD) - Only enforce checks for assignment operators if 2 or more consecutive assignments are detected from the same array/etc.(This might need a max. difference between indices for this to avoid suggesting 99 filler elements - something around 5-6 might make sense.)
Note
If future proofing is desired, this could arguably go inside its own "assignments" sub property or similar - I just want something other than black/white "all-or-nothing" enforcement.
Let me know what your thoughts are!
(If anything, the first step would be actually letting people disable either form of check to start with.)
Beta Was this translation helpful? Give feedback.
All reactions