DISCUSSION: Enforce JSHint W084?#4345
Conversation
|
vim script used to edit file, for posterity: |
|
Vim script! Maybe you should do a brown bag on that.
|
|
Ooooh. On vim or regexes? Cause I do love both |
|
I personally find approach number 1 much more readable. I would be interested in seeing some jsperf analysis of what the performance delta between the two approaches is if anyone knows how to use jsperf well. Another approach for these types of iterations is to use forEach Not sure what the cost of calling a function for each iteration is. If we were using ES6, we could instead do |
|
👍 upvote on the parentheses-wrap solution. I think W084 is a useful check because it covers a specific 'silent but deadly' type of bug, so I don't want to disable it entirely. |
|
unfortunately, blockly-core makes frequent use of HTMLCollections, which do not support forEach |
|
well, according to jsperf Google doesn't know what they're talking about |
|
It's possible that their statements once held true, but that compiler improvements have since optimized for the other (arguably more readable) case |
|
After a few more jsperf tests, it looks like the performance issue is real in every browser EXCEPT Chrome. Crafty, Google. Unless there are objections, I'm gonna go with the third option, and will update our styleguide appropriately. |
According to our style guide, we default to following Google's style guide which makes the following recommendation:
This pattern is used quite frequently in
blockly-core. Unfortunately, this pattern violates JSHint W084, AKA boss, which protects against assignments going in unexpected places. Most commonly,if (x = 'foo')rather thanif (x == 'foo').Note that JSHint supports the following:
For consistency, we should do one of the following:
Thoughts?