Skip to content

Commit

Permalink
Blacklist confusing global variables (facebook#2130)
Browse files Browse the repository at this point in the history
* Blacklist confusing global variables

* Blacklist globals

* Fix kitchensink test to lint

* Edit the list

* Use no-restricted globals for this
  • Loading branch information
sidoshi authored and romaindso committed Jul 10, 2017
1 parent 689b2ed commit 28a4c43
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 2 deletions.
68 changes: 67 additions & 1 deletion packages/eslint-config-react-app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down Expand Up @@ -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': [
Expand Down
2 changes: 1 addition & 1 deletion packages/react-scripts/fixtures/kitchensink/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 28a4c43

Please sign in to comment.