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

Allow await examples without a wrapping async function #31

Open
gr2m opened this issue Oct 21, 2018 · 7 comments
Open

Allow await examples without a wrapping async function #31

gr2m opened this issue Oct 21, 2018 · 7 comments

Comments

@gr2m
Copy link

gr2m commented Oct 21, 2018

Browsers have await in the global space so it would be nice when showing examples in the README to allow something like this

const result = await octokitRequest('GET /orgs/:org/repos', {
  headers: {
    authorization: 'token 0000000000000000000000000000000000000001'
  },
  org: 'octokit',
  type: 'private'
})

I looked for an option to add the package.json but no luck. Is there a way to workaround it or could that even be allowed by default?

@zeke
Copy link
Owner

zeke commented Oct 22, 2018

Hi @gr2m! I would happily accept and release a pull request that adds this, but I may not be able to implement it myself very soon.

@gr2m
Copy link
Author

gr2m commented Oct 22, 2018

sorry I think that browser actually don’t have the await in the global space, only in the web console 🤦‍♂️

But would still like to be able to show simplified example codes without wrapping async code into functions

@zeke
Copy link
Owner

zeke commented Oct 22, 2018

Yeah let's add support for that by default. Is there an eslint rule for it?

@zeke
Copy link
Owner

zeke commented Oct 22, 2018

Comments on this issue seem to be disappearing (at least for me)... emailing [email protected].

@gr2m
Copy link
Author

gr2m commented Oct 22, 2018

I’ve researched a bit but couldn’t find any rule. I’m not very familiar with eslint, do you know someone we could ask for help?

@zeke
Copy link
Owner

zeke commented Oct 22, 2018

Maybe @feross or @Flet? 👋 👋

@feross
Copy link

feross commented Aug 13, 2019

Hey folks! Sorry for the delay!! (I was taking a much-needed break from OSS). I totally agree that top-level await in readme docs is great!

I think that for top-level await support, the most obvious route would be to wait for ESLint to support it. They have a policy of supporting any JS feature that is at least Stage 4. Currently top-level await is Stage 3. https://github.com/tc39/proposal-top-level-await

But maybe if you're using babel with the babel-eslint parser already, there's a transform that you could install to handle this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants