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

Global variables in html file cause spurious eslint messages because eslint globals can not be configured #972

Closed
jhorneman opened this issue Oct 27, 2016 · 4 comments

Comments

@jhorneman
Copy link
Contributor

For reasons I have load a JavaScript file in CRA's index.html which defines a global variable.

CRA's eslint settings have "no-undef" set to error. Any use of the above-mentioned global variable will result in a compile error in the browser, preventing me from working.

Manually editing CRA's eslint settings to have "no-undef" be a warning is only a partial solution: I still get warnings in the console.

Manually editing the globals in CRA's eslint settings solves the problem, but is obviously not very elegant.

Ideally the development server would pick up on a .eslintrc file in the root of the project. (I've tried this, and it didn't work.)

@gaearon
Copy link
Contributor

gaearon commented Oct 28, 2016

Any use of the above-mentioned global variable will result in a compile error in the browser, preventing me from working.

You can read it explicitly from the window object, e.g. const $ = window.$.
This makes it obvious it's a global variable.

You can also force ESLint to ignore any line with // eslint-disable-line.

@gaearon gaearon closed this as completed Oct 28, 2016
@jhorneman
Copy link
Contributor Author

D'oh. Thanks :)

On 28 Oct 2016, at 12:53, Dan Abramov notifications@github.com wrote:

Closed #972.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.

@gaearon
Copy link
Contributor

gaearon commented Oct 28, 2016

It would be great to have this documented. Would you like to add this to the User Guide?

@jhorneman
Copy link
Contributor Author

Sure. I'll send a PR.

jhorneman added a commit to jhorneman/create-react-app that referenced this issue Oct 28, 2016
gaearon pushed a commit that referenced this issue Nov 20, 2016
* Added info on using global variables.

See issue #972.

* Fixed typo.

* Moved new section.

* Small tweaks

* Syntax highlighting
jarlef pushed a commit to jarlef/create-react-app that referenced this issue Nov 28, 2016
* Added info on using global variables.

See issue facebook#972.

* Fixed typo.

* Moved new section.

* Small tweaks

* Syntax highlighting
alexdriaguine pushed a commit to alexdriaguine/create-react-app that referenced this issue Jan 23, 2017
* Added info on using global variables.

See issue facebook#972.

* Fixed typo.

* Moved new section.

* Small tweaks

* Syntax highlighting
randycoulman pushed a commit to CodingZeal/create-react-app that referenced this issue May 8, 2017
* Added info on using global variables.

See issue facebook#972.

* Fixed typo.

* Moved new section.

* Small tweaks

* Syntax highlighting
@lock lock bot locked and limited conversation to collaborators Jan 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants