-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat(eslint-plugin): [no-float-prom] fixer + msg for ignoreVoid #1473
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
feat(eslint-plugin): [no-float-prom] fixer + msg for ignoreVoid #1473
Conversation
Thanks for the PR, @phaux! typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community. The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately. Thanks again! 🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint. As a thank you, your profile/company logo will be added to our main README which receives thousands of unique visitors per day. |
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.
LGTM - I think this would be even better as a suggestion fixer.
@@ -48,7 +50,7 @@ export default util.createRule<Options, 'floating'>({ | |||
|
|||
if (isUnhandledPromise(checker, expression)) { | |||
context.report({ | |||
messageId: 'floating', | |||
messageId: options.ignoreVoid ? 'floatingVoid' : 'floating', |
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.
This would probably be better as a suggestion fixer, to make it easy to fix to.
messageId: options.ignoreVoid ? 'floatingVoid' : 'floating', | |
messageId: options.ignoreVoid ? 'floatingVoid' : 'floating', | |
suggest: options.ignoreVoid ? [ | |
{ | |
messageId: 'xxx', // Consider explicitly marking | |
fix(fixer) { /* ... */ } | |
}, | |
] : [], |
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.
But won't that autofix with the --fix
eslint argument? Or eslint.fixAll
code action in vscode? That would suck because I think it should be the developer's conscious decision.
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.
Nope, that's the beauty of eslint suggestions!
For fixers, there is exactly 0 or 1 fixers for each report. A fixer will be applied by eslint's --fix
mode, if it exists for a report.
For suggestion fixers, on the other hand, can have 0..n suggestions for each report. Each suggestion has its own message which is used to communicate what it does to the user. Each suggestion is not automatically applied by eslint's --fix
mode.
Suggestions were added relatively recently, and are great for doing these sorts of fixes - ones that might break code, or require conscious decisions from the user. And the fact that you can present multiple for a report means that you can present the user with options for correcting the error.
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.
Done!
Codecov Report
@@ Coverage Diff @@
## master #1473 +/- ##
==========================================
- Coverage 95.56% 95.51% -0.05%
==========================================
Files 145 141 -4
Lines 6577 6450 -127
Branches 1879 1841 -38
==========================================
- Hits 6285 6161 -124
+ Misses 111 105 -6
- Partials 181 184 +3
|
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.
LGTM - thanks for this.
I added an alternative message for when the
ignoreVoid
option is enabled so that the feature is more discoverable.When the option is enabled the message is: