From 06e73fa6b357010d55f724c0828adf8b464d15a5 Mon Sep 17 00:00:00 2001
From: Siddharth Doshi <sidoshi510@gmail.com>
Date: Mon, 15 May 2017 00:17:04 +0530
Subject: [PATCH] Blacklist confusing global variables (#2130)

* Blacklist confusing global variables

* Blacklist globals

* Fix kitchensink test to lint

* Edit the list

* Use no-restricted globals for this
---
 packages/eslint-config-react-app/index.js     | 68 ++++++++++++++++++-
 .../fixtures/kitchensink/src/App.js           |  2 +-
 2 files changed, 68 insertions(+), 2 deletions(-)

diff --git a/packages/eslint-config-react-app/index.js b/packages/eslint-config-react-app/index.js
index fac862c72..c31e46cc1 100644
--- a/packages/eslint-config-react-app/index.js
+++ b/packages/eslint-config-react-app/index.js
@@ -18,6 +18,72 @@
 // In the future, we might create a separate list of rules for production.
 // It would probably be more strict.
 
+// The ESLint browser environment defines all browser globals as valid,
+// even though most people don't know some of them exist (e.g. `name` or `status`).
+// This is dangerous as it hides accidentally undefined variables.
+// We blacklist the globals that we deem potentially confusing.
+// To use them, explicitly reference them, e.g. `window.name` or `window.status`.
+var restrictedGlobals = [
+  'addEventListener',
+  'blur',
+  'close',
+  'closed',
+  'confirm',
+  'defaultStatus',
+  'defaultstatus',
+  'event',
+  'external',
+  'find',
+  'focus',
+  'frameElement',
+  'frames',
+  'history',
+  'innerHeight',
+  'innerWidth',
+  'length',
+  'location',
+  'locationbar',
+  'menubar',
+  'moveBy',
+  'moveTo',
+  'name',
+  'onblur',
+  'onerror',
+  'onfocus',
+  'onload',
+  'onresize',
+  'onunload',
+  'open',
+  'opener',
+  'opera',
+  'outerHeight',
+  'outerWidth',
+  'pageXOffset',
+  'pageYOffset',
+  'parent',
+  'print',
+  'removeEventListener',
+  'resizeBy',
+  'resizeTo',
+  'screen',
+  'screenLeft',
+  'screenTop',
+  'screenX',
+  'screenY',
+  'scroll',
+  'scrollbars',
+  'scrollBy',
+  'scrollTo',
+  'scrollX',
+  'scrollY',
+  'self',
+  'status',
+  'statusbar',
+  'stop',
+  'toolbar',
+  'top',
+];
+
 module.exports = {
   root: true,
 
@@ -121,7 +187,7 @@ module.exports = {
     'no-this-before-super': 'warn',
     'no-throw-literal': 'warn',
     'no-undef': 'error',
-    'no-restricted-globals': ['error', 'event'],
+    'no-restricted-globals': ['error'].concat(restrictedGlobals),
     'no-unexpected-multiline': 'warn',
     'no-unreachable': 'warn',
     'no-unused-expressions': [
diff --git a/packages/react-scripts/fixtures/kitchensink/src/App.js b/packages/react-scripts/fixtures/kitchensink/src/App.js
index 3e57c3c5a..3a1981a40 100644
--- a/packages/react-scripts/fixtures/kitchensink/src/App.js
+++ b/packages/react-scripts/fixtures/kitchensink/src/App.js
@@ -54,7 +54,7 @@ class App extends Component {
   }
 
   componentDidMount() {
-    const feature = location.hash.slice(1);
+    const feature = window.location.hash.slice(1);
     switch (feature) {
       case 'array-destructuring':
         import(
-- 
GitLab