Skip to content
This repository was archived by the owner on Mar 25, 2021. It is now read-only.

Prevent spreading of an array into an object #4339

Closed
James-E-Adams opened this issue Dec 5, 2018 · 4 comments
Closed

Prevent spreading of an array into an object #4339

James-E-Adams opened this issue Dec 5, 2018 · 4 comments

Comments

@James-E-Adams
Copy link

Rule Suggestion

Is your rule for a general problem or is it specific to your development style?

I think it's a general problem. I have buy in from one other person on twitter, so surely it's ubiquitous, right? https://twitter.com/jamesadams0/status/1069845022722277376

What does your suggested rule do?

Warns when you attempt to spread an array into an object.

List several examples where your rule could be used

const a = [1,2,3]
const b = {...a}

Additional context

Playground: http://www.typescriptlang.org/play/#src=const%20a%20%3D%20%5B1%2C%202%2C%203%5D%0A%0Aconst%20b%20%3D%20%7B%20...a%20%7D%0A

@JoshuaKGoldberg
Copy link
Contributor

😄 that didn't take long! Yes, this seems reasonable as a TSLint rule. The above code results in { '0': 1, '1': 2, '2': 3 }, which could be surprising. Let's see if anybody else has suggestions or opposing thoughts.

@James-E-Adams
Copy link
Author

Yeah it's perfectly valid javascript. But I think people do it 99% of the time without really wanting an object mapping indices to values.

😄Just a tab away!

@JoshuaKGoldberg
Copy link
Contributor

Note: per #4534, this issue will be closed in less than a month if no PR is sent to add the rule. If you really need the rule, custom rules are always an option and can be maintained outside this repo!

@JoshuaKGoldberg
Copy link
Contributor

💀 It's time! 💀

TSLint is being deprecated and no longer accepting pull requests for new rules. See #4534. 😱

If you'd like to see this rule implemented, you have two choices:

👋 It was a pleasure open sourcing with you!

If you believe this message was posted here in error, please comment so we can re-open the issue!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants