Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

fix(eslint-plugin): [no-misused-promises] fix incorrect detection of void functions in JSX attributes #6638

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

Merged
merged 2 commits into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions 21 packages/eslint-plugin/src/rules/no-misused-promises.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,20 +365,27 @@ export default util.createRule<Options, MessageId>({
}

function checkJSXAttribute(node: TSESTree.JSXAttribute): void {
const tsNode = parserServices.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 = parserServices.esTreeNodeToTSNodeMap.get(
node.value,
);
const expression = parserServices.esTreeNodeToTSNodeMap.get(
node.value.expression,
);
const contextualType = checker.getContextualType(expressionContainer);
if (
contextualType !== undefined &&
isVoidReturningFunctionType(checker, value, contextualType)
isVoidReturningFunctionType(
checker,
expressionContainer,
contextualType,
) &&
returnsThenable(checker, expression)
) {
context.report({
messageId: 'voidReturnAttribute',
Expand Down
17 changes: 17 additions & 0 deletions 17 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
Morty Proxy This is a proxified and sanitized view of the page, visit original site.