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

Environment for the intersection of browser and node #3599

Closed
TheSavior opened this issue Aug 30, 2015 · 20 comments
Closed

Environment for the intersection of browser and node #3599

TheSavior opened this issue Aug 30, 2015 · 20 comments
Assignees
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion core Relates to ESLint's core APIs and features enhancement This change enhances an existing feature of ESLint

Comments

@TheSavior
Copy link
Contributor

The addition of the new commonjs environment was very useful to not allow node only globals in our browser specific code. However, we have a folder of files that are used on both the server and client.

It doesn't make sense to provide the env key browser since in node you don't have access to HTMLElement (as an example), and in the browser you don't have access to the node globals.

However, when you are in both environments you have access to the intersection of the two such as the setInterval family of functions.

How can we handle this case?

@eslintbot
Copy link

Thanks for the issue! We get a lot of issues, so this message is automatically posted to each one to help you check that you've included all of the information we need to help you.

Reporting a bug? Please be sure to include:

  1. The version of ESLint you are using (run eslint -v)
  2. The source code that caused the problem
  3. The configuration you're using (for the rule or your entire config file)
  4. The actual ESLint output complete with line numbers

Requesting a new rule? Please be sure to include:

  1. The use case for the rule - what is it trying to prevent or flag?
  2. Whether the rule is trying to prevent an error or is purely stylistic
  3. Why you believe this rule is generic enough to be included

Requesting a feature? Please be sure to include:

  1. The problem you want to solve (don't mention the solution)
  2. Your take on the correct solution to problem

Including this information in your issue helps us to triage it and get you a response as quickly as possible.

Thanks!

@eslintbot eslintbot added the triage An ESLint team member will look at this issue soon label Aug 30, 2015
@nzakas
Copy link
Member

nzakas commented Aug 31, 2015

I'm having trouble understanding what you're asking. If a file is going to be used in both the browser and the server, why don't you enable both environments?

@btmills
Copy link
Member

btmills commented Aug 31, 2015

If I'm reading this correctly, the goal is to allow only the globals that are common to both to guarantee that the code can run safely in either environment. Is that it?

@TheSavior
Copy link
Contributor Author

@btmills correct.

Code needs to work correctly in both environments, so they should only have access to the things that are common to both.

@BYK
Copy link
Member

BYK commented Aug 31, 2015

We achieved this by disabling both and hand picking the few globals that
are shared such as setTimeout on our project. Not great, but not messy
either. Just can't use the nifty env.

May be we can add a "isomorphic" (or please a better name) environment to
the globals project.

On Mon, Aug 31, 2015, 06:02 Eli White notifications@github.com wrote:

@btmills https://github.com/btmills correct. Code needs to work
correctly in both environments, so they should only have access to the
things that are common to both.


Reply to this email directly or view it on GitHub
#3599 (comment).

@mysticatea
Copy link
Member

Recently, I read this article: http://www.2ality.com/2015/08/isomorphic-javascript.html

Is universal good?

@BYK
Copy link
Member

BYK commented Aug 31, 2015

👍 for universal. That said it may sound a bit too broad since this is mostly browser & node right?

@nzakas
Copy link
Member

nzakas commented Aug 31, 2015

I'm still not sure I understand why we need this. What are we really taking about here? setTimeout and setInterval?

@TheSavior
Copy link
Contributor Author

The intersection between node and browser as specified by: https://github.com/sindresorhus/globals/blob/master/globals.json

is currently:

    "clearInterval": false,
    "clearTimeout": false,
    "console": false,
    "setInterval": false,
    "setTimeout": false,

@nzakas nzakas added enhancement This change enhances an existing feature of ESLint core Relates to ESLint's core APIs and features accepted There is consensus among the team that this change meets the criteria for inclusion and removed triage An ESLint team member will look at this issue soon labels Aug 31, 2015
@nzakas
Copy link
Member

nzakas commented Aug 31, 2015

Hmm okay. @sindresorhus do you think it's worth adding this to globals?

@sindresorhus
Copy link
Contributor

👍

@BYK
Copy link
Member

BYK commented Sep 5, 2015

@sindresorhus any suggestions for the name? Are you okay with universal? If so I'll make PR to globals.

@IanVS
Copy link
Member

IanVS commented Sep 9, 2015

Unimorphic Isoversal? :trollface:

@nzakas
Copy link
Member

nzakas commented Sep 9, 2015

I think universal is the best of the terrible options.

@TheSavior
Copy link
Contributor Author

Agreed that universal is best of the worst and if we choose anything else people would just complain about our naming anyways.

@IanVS
Copy link
Member

IanVS commented Sep 9, 2015

To me, universal sounds way too broad, as if it would encompass all globals. Is there really no better name?

@TheSavior
Copy link
Contributor Author

universal-javascript, universal-js?

@BYK
Copy link
Member

BYK commented Sep 9, 2015

Okay, gonna go with universal.

@BYK
Copy link
Member

BYK commented Sep 9, 2015

@sindresorhus - Sent sindresorhus/globals#50. Hope you don't hate us for the name.

@sindresorhus
Copy link
Contributor

This was added in globals as shared-node-browser.
Someone submit a pull request on ESLint to add it ;)

@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 7, 2018
@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 Feb 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion core Relates to ESLint's core APIs and features enhancement This change enhances an existing feature of ESLint
Projects
None yet
Development

No branches or pull requests

8 participants