Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
fix(eslint-plugin): [no-misused-promises] improve report loc for methods#10216
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
JoshuaKGoldberg merged 22 commits intotypescript-eslint:mainfromgyumong:fix-no-misused-promisesNov 10, 2024
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
22 commits Select commitHold shift + click to select a range
359e052 fix(eslint-plugin): correctly report errors for async methods returni…
gyumongd8c6635 test add coverage
gyumong3d26e12 fix: remove unreachable code
gyumonga5dbd87 fix: simplify redundant if checks in context.report logic
gyumonga762f40 test: specify error location in voidReturnProperty test cases
gyumong8b1393c Merge branch 'main' into fix-no-misused-promises
gyumong432b792 fix lint
gyumong2207c17 Merge branch 'main' into fix-no-misused-promises
gyumongaa8f8c6 Merge branch 'main' into fix-no-misused-promises
gyumong4c7d787 test: add full loc (line, endLine, column, endColumn) to existing tes…
gyumong65ae628 test: add new invalid test cases for promise-returning methods withou…
gyumong801bf4c fix : test col
gyumongf367c20 fix: log
gyumong09be707 Merge branch 'main' into fix-no-misused-promises
gyumonge79283c Update packages/eslint-plugin/src/rules/no-misused-promises.ts
gyumong1278e3d Merge branch 'main' into fix-no-misused-promises
gyumong2bc7666 refactor(no-misused-promises): improve function type checking in void…
gyumong2da0b5c test(no-misused-promises): add test cases for isFunction utility usage
gyumongac34e36 Merge branch 'main' into fix-no-misused-promises
gyumongc7ac4e6 test(no-misused-promises): add test cases
gyumong50a6252 Merge branch 'main' into fix-no-misused-promises
gyumongeb66dbd Merge branch 'main' into fix-no-misused-promises
gyumongFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
42 changes: 34 additions & 8 deletionspackages/eslint-plugin/src/rules/no-misused-promises.ts
gyumong marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -6,6 +6,7 @@ import * as ts from 'typescript'; | ||
| import { | ||
| createRule, | ||
| getFunctionHeadLoc, | ||
| getParserServices, | ||
| isArrayMethodCallWithPredicate, | ||
| isFunction, | ||
| @@ -436,10 +437,25 @@ export default createRule<Options, MessageId>({ | ||
| ) && | ||
| returnsThenable(checker, tsNode.initializer) | ||
| ) { | ||
| if (isFunction(node.value)) { | ||
| const functionNode = node.value; | ||
| if (functionNode.returnType) { | ||
| context.report({ | ||
| node: functionNode.returnType.typeAnnotation, | ||
| messageId: 'voidReturnProperty', | ||
| }); | ||
| } else { | ||
| context.report({ | ||
| loc: getFunctionHeadLoc(functionNode, context.sourceCode), | ||
| messageId: 'voidReturnProperty', | ||
| }); | ||
| } | ||
| } else { | ||
| context.report({ | ||
| node: node.value, | ||
| messageId: 'voidReturnProperty', | ||
| }); | ||
| } | ||
| } | ||
| } else if (ts.isShorthandPropertyAssignment(tsNode)) { | ||
| const contextualType = checker.getContextualType(tsNode.name); | ||
| @@ -490,10 +506,19 @@ export default createRule<Options, MessageId>({ | ||
| ); | ||
| if (isVoidReturningFunctionType(checker, tsNode.name, contextualType)) { | ||
| const functionNode = node.value as TSESTree.FunctionExpression; | ||
| if (functionNode.returnType) { | ||
| context.report({ | ||
| node: functionNode.returnType.typeAnnotation, | ||
| messageId: 'voidReturnProperty', | ||
| }); | ||
| } else { | ||
| context.report({ | ||
| loc: getFunctionHeadLoc(functionNode, context.sourceCode), | ||
| messageId: 'voidReturnProperty', | ||
| }); | ||
| } | ||
kirkwaiblinger marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| } | ||
| return; | ||
| } | ||
| @@ -513,6 +538,7 @@ export default createRule<Options, MessageId>({ | ||
| } | ||
| return nullThrows(current, NullThrowsReasons.MissingParent); | ||
| })(); | ||
| if ( | ||
| functionNode.returnType && | ||
| !isPossiblyFunctionType(functionNode.returnType) | ||
149 changes: 148 additions & 1 deletionpackages/eslint-plugin/tests/rules/no-misused-promises.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.