Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upNew rule: don't use destructing for index access #551
Comments
This comment has been minimized.
This comment has been minimized.
|
What about |
This comment has been minimized.
This comment has been minimized.
|
Good question, you could write it as |
This comment has been minimized.
This comment has been minimized.
|
I agree that the initial case is a bit odd, especially when taken to such an extreme, but I don't think its going to be easy to make a hard and fast rule about this that won't seem inconsistent just because |
This comment has been minimized.
This comment has been minimized.
|
Maybe make the rule only about when extracting a single value? Just throwing out some ideas, any input is highly welcome :) |
This comment has been minimized.
This comment has been minimized.
I don't particularly like the comma version either but it's most probably just because I'm not used to that even being an option. Some patterns are only idiomatic because an alternative didn't exist until recently. |
This comment has been minimized.
This comment has been minimized.
|
This feels too fancy for my taste: const [, , , , code, tests] = /(\d)?(test|hello)( - )?(\d)/.exec('...')I prefer dumb, explicit code that won't impress anyone: const re = /(\d)?(test|hello)( - )?(\d)/.exec('...')
const code = re[4]
const tests = re[5]From RULES.md:
That said, I don't think this is an easy thing to enforce (no existing eslint rule for it, and where would you draw the line? How many commas is too many?) |
feross
added
the
enhancement
label
Jun 22, 2016
feross
added
help wanted
blocked
labels
Jul 12, 2016
This comment has been minimized.
This comment has been minimized.
|
@LinusU Can you open this as an issue on ESLint to see what the ESLint team thinks? There's nothing we can do in Once this is part of ESLint, I will notice it in the changelog when I upgrade the ESLint version or you can open an issue/PR to discuss adding the rule to |
LinusU commentedJun 20, 2016
Today I saw some code that looked a bit like this (admittedly with less commas, but still)
While it works, I think it's much more idiomatic to write it like so:
How about a rule enforcing this?