-
-
Notifications
You must be signed in to change notification settings - Fork 5
dev: enable rule warn no-floating-promises and no-misused-promises #3391
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
base: master
Are you sure you want to change the base?
Conversation
This PR turns on eslint warnings for rules no-floating-promises and no-misused-promises. Consider this code: async myMethod(): Promise<void> {
mkdir('/data');
await writeFile('/data/hello.txt', 'Hello, world!');
} The call to async function Or consider this code, async function risk(): Promise<void> {
throw new Error("Problem!");
}
async function click(): Promise<void> {
try {
console.log("Trying something!");
risk();
} catch (e) {
console.log("It was a problem!");
}
console.log("Phew!");
}
await click(); When this code runs, will it print "It was a problem!"? Nope! You need to Consider this code: async click(): Promise<void> {
navigate('/destination');
} Some calls to async methods might not be important to await. You fire it and it will happen when (and if) it happens. You can prefix Our codebase has a lot of these occurrences, so I am having eslint mark them as warnings rather than errors. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3391 +/- ##
=======================================
Coverage 82.59% 82.59%
=======================================
Files 608 608
Lines 35966 35966
Branches 5842 5842
=======================================
Hits 29705 29705
Misses 5399 5399
Partials 862 862 ☔ View full report in Codecov by Sentry. |
The rules are not enabled for spec and stories files. It may also be useful to have the rules on in those files, but (1) calls to async methods in fakeAsync do not need awaited, and (2) the IDE understands toBe, toEqual, etc to return Promises. Ideally the rules would mark occurrences as errors, but there are many occurrences that first need to be cleaned up.
8ad75fc
to
76c0c54
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So many warnings!
The warnings I investigated looked like they were intended by the developer to be floating or misused.
I'd be interested in getting wider consensus/feedback form the team before merging. Should we discuss this in the planning meeting tomorrow?
@pmachapman reviewed 2 of 2 files at r1, all commit messages.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on @marksvc)
Sounds good. |
The rules are not enabled for spec and stories files. It may also be
useful to have the rules on in those files, but (1) calls to async
methods in fakeAsync do not need awaited, and (2) the IDE understands
toBe, toEqual, etc to return Promises.
Ideally the rules would mark occurrences as errors, but there are many
occurrences that first need to be cleaned up.
This change is