From 74071a809c22fa1104fe5d86bcd1eda949e1d0d9 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 3 Apr 2017 15:23:00 -0700 Subject: [PATCH] [eslint config] [base] [patch] add error messages to `no-restricted-syntax` Fixes #1353. --- .../eslint-config-airbnb-base/rules/style.js | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/packages/eslint-config-airbnb-base/rules/style.js b/packages/eslint-config-airbnb-base/rules/style.js index 610caa21..237f1689 100644 --- a/packages/eslint-config-airbnb-base/rules/style.js +++ b/packages/eslint-config-airbnb-base/rules/style.js @@ -256,10 +256,22 @@ module.exports = { // http://eslint.org/docs/rules/no-restricted-syntax 'no-restricted-syntax': [ 'error', - 'ForInStatement', - 'ForOfStatement', - 'LabeledStatement', - 'WithStatement', + { + 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: '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: '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.', + }, ], // disallow space between function identifier and application