Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forbid using window properties as global variables #1840

Merged
merged 3 commits into from
May 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/eslint-config-react-app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,19 @@ module.exports = {
plugins: ['import', 'flowtype', 'jsx-a11y', 'react'],

env: {
browser: true,
commonjs: true,
es6: true,
jest: true,
node: true,
},

globals: {
document: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's change this to the list of globals defined by Standard: document, console, and navigator.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gaearon document and navigator are not part of node, so it still can bring headache to SSR app developer.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to draw the line somewhere, and I think it's honestly not hard to find usages of them if you intend to convert your app to SSR (which CRA doesn't support out of the box anyway).

It's much harder without a whitelist (since then you don't even know what you're looking for).

window: true,
console: true,
navigator: true
},

parserOptions: {
ecmaVersion: 6,
sourceType: 'module',
Expand Down
4 changes: 2 additions & 2 deletions packages/react-scripts/fixtures/kitchensink/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class BuiltEmitter extends Component {
}

handleReady() {
document.dispatchEvent(new Event('ReactFeatureDidMount'));
document.dispatchEvent(new window.Event('ReactFeatureDidMount'));
}

render() {
Expand Down Expand Up @@ -53,7 +53,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
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import React from 'react';
import aFileWithoutExt from './assets/aFileWithoutExt';

const text = aFileWithoutExt.includes('base64')
? atob(aFileWithoutExt.split('base64,')[1]).trim()
? window.atob(aFileWithoutExt.split('base64,')[1]).trim()
: aFileWithoutExt;

export default () => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import React from 'react';
import aFileWithExtUnknown from './assets/aFileWithExt.unknown';

const text = aFileWithExtUnknown.includes('base64')
? atob(aFileWithExtUnknown.split('base64,')[1]).trim()
? window.atob(aFileWithExtUnknown.split('base64,')[1]).trim()
: aFileWithExtUnknown;

export default () => (
Expand Down