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

prefer-await-to-then should flag promise.catch/finally as well #188

Merged
merged 1 commit into from
Jul 8, 2020

Conversation

jp7837
Copy link
Contributor

@jp7837 jp7837 commented May 9, 2020

What is the purpose of this pull request?

  • Documentation update
  • Bug fix
  • New rule
  • Changes an existing rule
  • Add autofixing to a rule
  • Other, please explain:

What changes did you make? (Give an overview)
Flag catch() and finally() usages in the prefer-await-to-then rule

@jp7837
Copy link
Contributor Author

jp7837 commented May 9, 2020

Fixes #187

@jp7837
Copy link
Contributor Author

jp7837 commented May 25, 2020

@xjamundx thoughts on this one?

@xjamundx xjamundx merged commit 932123e into eslint-community:master Jul 8, 2020
@xjamundx
Copy link
Contributor

xjamundx commented Jul 8, 2020

Yeah seems fine.

@xjamundx
Copy link
Contributor

xjamundx commented Jul 8, 2020

Actually.....Let me take this back (sorry).

.catch() really is an error handling mechanism and not really the same as await.

For example I prefer .catch() to try/catch as in let val = await whatever().catch() vs

let val;
try {
   val = await whatever();
} catch (e) {
   val = default;
}

So, sorry I am not going to include this.

@jp7837
Copy link
Contributor Author

jp7837 commented Jul 8, 2020

@xjamundx yeah, that makes sense, it is cleaner to use catch() in that case. I just used the below instead. And I was actually just applying it to Jest code in combination with no-try-expect to get more reliable and cleaner error assertions.

"no-restricted-properties": [
	"error",
	{
		property: "catch",
		message: "Use async/await instead of catch"
	},
	{
		property: "finally",
		message: "Use async/await instead of finally"
	},
	{
		property: "then",
		message: "Use async/await instead of then"
	},
]

@brettz9 brettz9 mentioned this pull request Apr 9, 2021
6 tasks
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 this pull request may close these issues.

2 participants