Skip to content

prefer-async-await rule #123

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

Closed
sindresorhus opened this issue Jun 29, 2016 · 7 comments · Fixed by #134
Closed

prefer-async-await rule #123

sindresorhus opened this issue Jun 29, 2016 · 7 comments · Fixed by #134

Comments

@sindresorhus
Copy link
Member

I see a lot of people doing:

test(t => {
  return fetch().then(data => {
    t.is(data, 'foo');
  });
});

When this would be much succinct:

test(async t => {
  t.is(await fetch(), 'foo');
});

Would be useful to have a rule to enforce using async/await.

@jfmengels
Copy link
Contributor

How would we want to detect that? See if there's a .then() call somewhere in a normal function and there is a return statement? Don't know if it's that simple.

@sindresorhus
Copy link
Member Author

I was thinking checking whether there's a .then() that is return'ed.

@jfmengels
Copy link
Contributor

jfmengels commented Jun 29, 2016

That could work well, only if we attempt to check the value of a variable if it's returned. This should be reported for instance

test(t => {
  var foo = fetch().then(data => {
    t.is(data, 'foo');
  });
  return foo;
});
// or more realistically
test(t => {
  var foo = fetch().then(fn);
  var bar = foo.then(baz);
  return bar;
});

I'm starting to use context.getScope() in other projects. It's terribly undocumented, but even without code path analysis (though that'd be better probably), you can try and determine the value of a Node. When i have more time, I'll try to add it to this plugin. (I actually started working on it to make it work with macros, but then my computer crashed and I lost what I did ^^')

@sindresorhus
Copy link
Member Author

(I actually started working on it to make it work with macros, but then my computer crashed and I lost what I did ^^')

Oh man. That sucks. Backup though? 😜

@jfmengels
Copy link
Contributor

Backup though?

I wish ^^'
Apparently I don't have the habit of pushing my local work-in-progress branches to a repo, so... All in all, I only lost work on that macro thing for this repo, and some work in eslint-plugin-lodash-fp (a lot more unfortunately), don't think I really lost anything else except for the configuration for my computer. This should serve as a lesson I guess ^^' (and I should create a dotfiles project, soon)

@sindresorhus
Copy link
Member Author

I don't usually push local work either, but I do have a close to real-time backup of my system using BackBlaze. It has saved me many times.

@jfmengels
Copy link
Contributor

jfmengels commented Jun 29, 2016

"Backup your Mac or PC just $5/month"

Linux :(
I may take a look at similar solutions soon though. Can be pretty useful 👍
but let's get back on topic ;)

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

Successfully merging a pull request may close this issue.

2 participants