diff --git a/packages/eslint-config-react-app/index.js b/packages/eslint-config-react-app/index.js index fac862c72c..c31e46cc11 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 3e57c3c5a7..3a1981a400 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(