Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save e0da/e539c6aa220eedd0cf76dc94e1e26ed9 to your computer and use it in GitHub Desktop.
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.
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