Skip to content

Commit 06e73fa

Browse files
sidoshigaearon
authored andcommitted
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
1 parent dbd12f1 commit 06e73fa

File tree

2 files changed

+68
-2
lines changed
  • packages
    • eslint-config-react-app
    • react-scripts/fixtures/kitchensink/src

2 files changed

+68
-2
lines changed

packages/eslint-config-react-app/index.js

+67-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,72 @@
1818
// In the future, we might create a separate list of rules for production.
1919
// It would probably be more strict.
2020

21+
// The ESLint browser environment defines all browser globals as valid,
22+
// even though most people don't know some of them exist (e.g. `name` or `status`).
23+
// This is dangerous as it hides accidentally undefined variables.
24+
// We blacklist the globals that we deem potentially confusing.
25+
// To use them, explicitly reference them, e.g. `window.name` or `window.status`.
26+
var restrictedGlobals = [
27+
'addEventListener',
28+
'blur',
29+
'close',
30+
'closed',
31+
'confirm',
32+
'defaultStatus',
33+
'defaultstatus',
34+
'event',
35+
'external',
36+
'find',
37+
'focus',
38+
'frameElement',
39+
'frames',
40+
'history',
41+
'innerHeight',
42+
'innerWidth',
43+
'length',
44+
'location',
45+
'locationbar',
46+
'menubar',
47+
'moveBy',
48+
'moveTo',
49+
'name',
50+
'onblur',
51+
'onerror',
52+
'onfocus',
53+
'onload',
54+
'onresize',
55+
'onunload',
56+
'open',
57+
'opener',
58+
'opera',
59+
'outerHeight',
60+
'outerWidth',
61+
'pageXOffset',
62+
'pageYOffset',
63+
'parent',
64+
'print',
65+
'removeEventListener',
66+
'resizeBy',
67+
'resizeTo',
68+
'screen',
69+
'screenLeft',
70+
'screenTop',
71+
'screenX',
72+
'screenY',
73+
'scroll',
74+
'scrollbars',
75+
'scrollBy',
76+
'scrollTo',
77+
'scrollX',
78+
'scrollY',
79+
'self',
80+
'status',
81+
'statusbar',
82+
'stop',
83+
'toolbar',
84+
'top',
85+
];
86+
2187
module.exports = {
2288
root: true,
2389

@@ -121,7 +187,7 @@ module.exports = {
121187
'no-this-before-super': 'warn',
122188
'no-throw-literal': 'warn',
123189
'no-undef': 'error',
124-
'no-restricted-globals': ['error', 'event'],
190+
'no-restricted-globals': ['error'].concat(restrictedGlobals),
125191
'no-unexpected-multiline': 'warn',
126192
'no-unreachable': 'warn',
127193
'no-unused-expressions': [

packages/react-scripts/fixtures/kitchensink/src/App.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class App extends Component {
5454
}
5555

5656
componentDidMount() {
57-
const feature = location.hash.slice(1);
57+
const feature = window.location.hash.slice(1);
5858
switch (feature) {
5959
case 'array-destructuring':
6060
import(

0 commit comments

Comments
 (0)