Last active
August 26, 2020 16:39
-
-
Save e0da/e539c6aa220eedd0cf76dc94e1e26ed9 to your computer and use it in GitHub Desktop.
Disable the airbnb style guide rules that violates the no-restricted-syntax rule when using for...of loops in JavaScript, which are incredible and a wonderful and perfectly valid alternative to Array.prototype.forEach. Fight me.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
extends: ["airbnb-base"], | |
rules: { | |
"no-restricted-syntax": [ | |
"error", | |
/** | |
* for...of is wonderful! Copy the rest of Airbnb's rules. | |
* Gist permalink: https://gist.github.com/e0da/e539c6aa220eedd0cf76dc94e1e26ed9 | |
* Airbnb source: https://github.com/airbnb/javascript/blob/a24dc34a4a2748c99006a48e997aa0a06b1d4d94/packages/eslint-config-airbnb-base/rules/style.js#L339-L357 | |
* Feature discussion: https://github.com/airbnb/javascript/issues/1271#issuecomment-548688952 | |
*/ | |
/* | |
{ | |
selector: "ForOfStatement", | |
message: | |
"iterators/generators require regenerator-runtime, which is too heavyweight for this guide to allow them. Separately, loops should be avoided in favor of array iterations.", | |
}, | |
*/ | |
{ | |
selector: "ForInStatement", | |
message: | |
"for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array.", | |
}, | |
{ | |
selector: "LabeledStatement", | |
message: | |
"Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand.", | |
}, | |
{ | |
selector: "WithStatement", | |
message: | |
"`with` is disallowed in strict mode because it makes code impossible to predict and optimize.", | |
}, | |
], | |
}, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment