noUselessSpread rule #7526
mirelon
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.
-
Rule type: suggestion / suspicious code
Description:
Prevent spreading array literals into function or constructor calls when the spread is unnecessary or misleading.
Example:
This happens because
['aa']
spreads into"aa"
, andSet
treats a string as an iterable of characters. This is almost always unintended.Valid code:
Invalid code:
Motivation:
(new Set(...['aa'])
instead ofnew Set([...iterable]))
. To avoid confusion, we can call it noConfusingSpread or noArgumentSpreadArray.Suggested category:
suspicious (since it’s very likely a bug)
Autofix:
Replace
fn(...[expr])
withfn(expr)
orfn([expr])
depending on context.Beta Was this translation helpful? Give feedback.
All reactions