Skip to content

Commit

Permalink
Merge branch 'main' into v6
Browse files Browse the repository at this point in the history
  • Loading branch information
bradzacher committed Mar 15, 2023
2 parents d864691 + 9e41cee commit 957bdcb
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/eslint-plugin/docs/rules/await-thenable.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ description: 'Disallow awaiting a value that is not a Thenable.'
>
> See **https://typescript-eslint.io/rules/await-thenable** for documentation.
A "Thenable" value is an object with has a `then` method, such as a Promise.
A "Thenable" value is an object which has a `then` method, such as a Promise.
The `await` keyword is generally used to retrieve the result of calling a Thenable's `then` method.

If the `await` keyword is used on a value that is not a Thenable, the value is directly resolved immediately.
Expand Down
22 changes: 14 additions & 8 deletions packages/eslint-plugin/src/rules/no-misused-promises.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,21 +365,27 @@ export default util.createRule<Options, MessageId>({
}

function checkJSXAttribute(node: TSESTree.JSXAttribute): void {
const tsNode = services.esTreeNodeToTSNodeMap.get(node);
const value = tsNode.initializer;
if (
node.value == null ||
value === undefined ||
!ts.isJsxExpression(value) ||
value.expression === undefined
node.value.type !== AST_NODE_TYPES.JSXExpressionContainer
) {
return;
}
const contextualType = checker.getContextualType(value);
const expressionContainer = services.esTreeNodeToTSNodeMap.get(
node.value,
);
const expression = services.esTreeNodeToTSNodeMap.get(
node.value.expression,
);
const contextualType = checker.getContextualType(expressionContainer);
if (
contextualType !== undefined &&
isVoidReturningFunctionType(checker, value, contextualType) &&
returnsThenable(checker, value)
isVoidReturningFunctionType(
checker,
expressionContainer,
contextualType,
) &&
returnsThenable(checker, expression)
) {
context.report({
messageId: 'voidReturnAttribute',
Expand Down
17 changes: 17 additions & 0 deletions packages/eslint-plugin/tests/rules/no-misused-promises.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,23 @@ restTuple('Hello');
};
}
`,
// https://github.com/typescript-eslint/typescript-eslint/issues/6637
{
code: `
type OnSelectNodeFn = (node: string | null) => void;
interface ASTViewerBaseProps {
readonly onSelectNode?: OnSelectNodeFn;
}
declare function ASTViewer(props: ASTViewerBaseProps): null;
declare const onSelectFn: OnSelectNodeFn;
<ASTViewer onSelectNode={onSelectFn} />;
`,
filename: 'react.tsx',
options: [{ checksVoidReturn: { attributes: true } }],
},
],

invalid: [
Expand Down

0 comments on commit 957bdcb

Please sign in to comment.