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

feat(eslint-plugin): [no-float-prom] fixer + msg for ignoreVoid #1473

Merged
merged 3 commits into from Feb 3, 2020
Merged

feat(eslint-plugin): [no-float-prom] fixer + msg for ignoreVoid #1473

merged 3 commits into from Feb 3, 2020

Conversation

phaux
Copy link
Contributor

@phaux phaux commented Jan 19, 2020

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:

Promises must be handled appropriately or explicitly marked as ignored with the void operator

@typescript-eslint
Copy link
Contributor

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.

@armano2 armano2 added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin enhancement New feature or request labels Jan 19, 2020
Copy link
Member

@bradzacher bradzacher left a 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',
Copy link
Member

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.

Suggested change
messageId: options.ignoreVoid ? 'floatingVoid' : 'floating',
messageId: options.ignoreVoid ? 'floatingVoid' : 'floating',
suggest: options.ignoreVoid ? [
{
messageId: 'xxx', // Consider explicitly marking
fix(fixer) { /* ... */ }
},
] : [],

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@bradzacher bradzacher added the awaiting response Issues waiting for a reply from the OP or another party label Jan 21, 2020
@armano2 armano2 removed the awaiting response Issues waiting for a reply from the OP or another party label Jan 22, 2020
@bradzacher bradzacher added the awaiting response Issues waiting for a reply from the OP or another party label Jan 30, 2020
@codecov
Copy link

codecov bot commented Feb 1, 2020

Codecov Report

Merging #1473 into master will decrease coverage by 0.04%.
The diff coverage is 93.88%.

@@            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
Impacted Files Coverage Δ
...nt-plugin/src/rules/indent-new-do-not-use/index.ts 98.4% <ø> (ø) ⬆️
...s/eslint-plugin/src/rules/interface-name-prefix.ts 100% <ø> (+16.66%) ⬆️
...rimental-utils/src/ts-eslint-scope/ScopeManager.ts 100% <ø> (ø) ⬆️
...nt-plugin/src/rules/no-unused-vars-experimental.ts 91.39% <ø> (ø) ⬆️
...ges/eslint-plugin/src/rules/no-inferrable-types.ts 93.1% <ø> (ø) ⬆️
packages/eslint-plugin/src/rules/indent.ts 92.68% <ø> (ø) ⬆️
...ges/experimental-utils/src/ts-eslint/SourceCode.ts 100% <ø> (ø) ⬆️
...experimental-utils/src/ts-eslint-scope/Variable.ts 100% <ø> (ø) ⬆️
packages/eslint-plugin/src/rules/no-type-alias.ts 100% <ø> (ø) ⬆️
...es/experimental-utils/src/ts-eslint-scope/Scope.ts 100% <ø> (ø) ⬆️
... and 45 more

@phaux phaux changed the title feat(eslint-plugin): [no-float-prom] add separate message for ignoreVoid feat(eslint-plugin): [no-float-prom] add message and fixer for ignoreVoid Feb 2, 2020
@phaux phaux requested a review from bradzacher February 2, 2020 17:52
@bradzacher bradzacher removed the awaiting response Issues waiting for a reply from the OP or another party label Feb 3, 2020
Copy link
Member

@bradzacher bradzacher left a 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.

@bradzacher bradzacher changed the title feat(eslint-plugin): [no-float-prom] add message and fixer for ignoreVoid feat(eslint-plugin): [no-float-prom] fixer + msg for ignoreVoid Feb 3, 2020
@bradzacher bradzacher merged commit 159b16e into typescript-eslint:master Feb 3, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants