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

no-undef complains about globalThis #11553

Closed
wmertens opened this issue Mar 26, 2019 · 4 comments
Closed

no-undef complains about globalThis #11553

wmertens opened this issue Mar 26, 2019 · 4 comments
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion question This issue asks a question about ESLint

Comments

@wmertens
Copy link

Tell us about your environment

  • ESLint Version: 5.15.1
  • Node Version: 10
  • npm Version: pnpm 3

What parser (default, Babel-ESLint, etc.) are you using?

babel-eslint

Please show your full configuration:

Configuration
// keep up to date from https://github.com/facebookincubator/create-react-app/blob/master/packages/babel-preset-react-app/index.js

const path = require('path')
const debug = require('debug')
const dbg = debug('stratokit/babel')

const isDev = process.env.NODE_ENV !== 'production'

module.exports = function(context, opts) {
	if (opts == null) {
		opts = {}
	}
	opts.isDev = isDev
	// Workaround to force browser build when webpack config already loaded babel and can't change options
	opts.isBrowser = opts.isBrowser || !!process.env.BROWSER
	const chromeOnly = process.env.CHROME_ONLY === 'true'
	dbg('Babel config', JSON.stringify(opts))
	const {reactHot, noModules, inWebpack} = opts
	const plugins = [
		// Cherrypick lodash methods until https://github.com/webpack/webpack/issues/1750
		!isDev && require.resolve('babel-plugin-lodash'),
		// Provide meta-data for import()s
		require.resolve('react-imported-component/babel'),
		// work with aliases, not necessary when running from webpack
		!inWebpack && [
			require.resolve('babel-plugin-webpack-alias'),
			{config: path.join(__dirname, 'aliases.js')},
		],

		// Adds consistent names to styles
		[
			require.resolve('babel-plugin-styled-components'),
			// Don't minify or preprocess, it breaks our stuff
			{displayName: isDev, pure: true, minify: false},
		],

		// Plugins from create-react-app
		// Adds component stack to warning messages
		isDev && require.resolve('@babel/plugin-transform-react-jsx-source'),
		// Adds __self attribute to JSX which React will use for some warnings
		isDev && require.resolve('@babel/plugin-transform-react-jsx-self'),
		// stage 2, but correct one doesn't work yet - HAS TO COME BEFORE class-properties
		[require.resolve('@babel/plugin-proposal-decorators'), {legacy: true}],
		// class { handleClick = () => { } }
		require.resolve('@babel/plugin-proposal-class-properties'),
		// { ...todo, completed: true }
		require.resolve('@babel/plugin-proposal-object-rest-spread'),
		// Support import() syntax
		require.resolve('@babel/plugin-syntax-dynamic-import'),

		// Support for HMR - keep below transform-regenerator
		// https://github.com/gaearon/react-hot-loader/issues/391
		reactHot && [require.resolve('react-hot-loader/babel')],
	].filter(Boolean)

	const presets = [
		// Latest stable ECMAScript features
		// But turn off modules so webpack can handle them
		// in dev, compile for our dev targets only
		[
			require.resolve('@babel/preset-env'),

			{
				targets: opts.isBrowser
					? {
							browsers: chromeOnly
								? ['last 1 Chrome version']
								: ['> 0.5% in BE', 'IE >= 11', 'Safari >= 9.1'],
					  }
					: // Default to node 8.11.3 in prod; nixpkgs-stable
					  {node: isDev ? true : '8.11.3'},
				// this is either `false` or `undefined`
				modules: !noModules && undefined,
				useBuiltIns: isDev ? undefined : 'entry',
				debug: process.env.NODE_ENV !== 'test',
			},
		],
		// JSX, Flow
		require.resolve('@babel/preset-react'),
		// This crashes on build :(
		// !isDev && require.resolve('babel-preset-minify'),
	].filter(Boolean)

	return {
		presets,
		plugins,
	}
}

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.

globalThis.foo
eslint

What did you expect to happen?

globalThis is accepted as a global, since it's stage 3 and enabled in Chrome 71 https://github.com/tc39/proposal-global

What actually happened? Please include the actual, raw output from ESLint.

  8:21  error  'globalThis' is not defined  no-undef

Are you willing to submit a pull request to fix this bug?

Yes but not sure where to start.

@wmertens wmertens added bug ESLint is working incorrectly triage An ESLint team member will look at this issue soon labels Mar 26, 2019
@aladdin-add
Copy link
Member

aladdin-add commented Mar 26, 2019

globalThis is at stage-3, while ESLint only officially supports the latest final ECMAScript standard.

you can use /*global globalThis*/.

@aladdin-add aladdin-add added question This issue asks a question about ESLint and removed bug ESLint is working incorrectly triage An ESLint team member will look at this issue soon labels Mar 26, 2019
@wmertens
Copy link
Author

wmertens commented Mar 26, 2019 via email

@aladdin-add
Copy link
Member

aladdin-add commented Mar 26, 2019

you can add globals in your eslint config:

{
  "globals": {
    "globalThis": false, // means it is not writeable
  }
}

refs: https://eslint.org/docs/user-guide/configuring.html#specifying-globals

@wmertens
Copy link
Author

Thanks! I couldn't find that :-/

@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Sep 23, 2019
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Sep 23, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion question This issue asks a question about ESLint
Projects
None yet
Development

No branches or pull requests

2 participants