From c23d54925800cf98f4afe570ea4899c24ac46843 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 23 Sep 2024 13:07:01 -0700 Subject: [PATCH] [Tests] failing tests for #3828 --- lib/rules/destructuring-assignment.js | 1 + tests/lib/rules/destructuring-assignment.js | 37 ++++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/lib/rules/destructuring-assignment.js b/lib/rules/destructuring-assignment.js index b4aa3da159..d537cca3b9 100644 --- a/lib/rules/destructuring-assignment.js +++ b/lib/rules/destructuring-assignment.js @@ -257,6 +257,7 @@ module.exports = { if (!propsRefs) { return; } + // Skip if props is used elsewhere if (propsRefs.length > 1) { return; diff --git a/tests/lib/rules/destructuring-assignment.js b/tests/lib/rules/destructuring-assignment.js index e1f8e85b08..80bf99dd7d 100644 --- a/tests/lib/rules/destructuring-assignment.js +++ b/tests/lib/rules/destructuring-assignment.js @@ -872,6 +872,41 @@ ${' '} `, features: ['ts', 'no-babel'], }, - ] : [] + ] : [], + { + code: ` + type Props = { text: string }; + export const MyComponent: React.FC = (props) => { + type MyType = typeof props.text; + return
{props.text as MyType}
; + }; + `, + options: ['always', { destructureInSignature: 'always' }], + features: ['types'], + errors: [ + { + messageId: 'useDestructAssignment', + data: { type: 'props' }, + }, + ], + }, + { + code: ` + type Props = { text: string }; + export const MyOtherComponent: React.FC = (props) => { + const { text } = props; + type MyType = typeof props.text; + return
{text as MyType}
; + }; + `, + options: ['always', { destructureInSignature: 'always' }], + features: ['types'], + errors: [ + { + messageId: 'destructureInSignature', + data: { type: 'props' }, + }, + ], + } )), });