From 16aba2c7d7ac7e1fa657e951727c3b596c072def Mon Sep 17 00:00:00 2001 From: KG Date: Mon, 19 Feb 2024 01:59:15 +0200 Subject: [PATCH] fix(no-setup-props-reactivity-loss): false negative for conditional expressions (#2394) Co-authored-by: Flo Edelmann --- lib/rules/no-setup-props-reactivity-loss.js | 11 +++++- .../rules/no-setup-props-reactivity-loss.js | 37 +++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/lib/rules/no-setup-props-reactivity-loss.js b/lib/rules/no-setup-props-reactivity-loss.js index fc0406ba9..b8e896075 100644 --- a/lib/rules/no-setup-props-reactivity-loss.js +++ b/lib/rules/no-setup-props-reactivity-loss.js @@ -78,7 +78,8 @@ module.exports = { if ( left.type !== 'ArrayPattern' && left.type !== 'ObjectPattern' && - rightNode.type !== 'MemberExpression' + rightNode.type !== 'MemberExpression' && + rightNode.type !== 'ConditionalExpression' ) { return } @@ -91,6 +92,14 @@ module.exports = { if (rightId.type === 'Identifier' && propsReferences.refs.has(rightId)) { report(left, 'getProperty', propsReferences.scopeName) } + if ( + rightId.type === 'ConditionalExpression' && + (isPropsMemberAccessed(rightId.test, propsReferences) || + isPropsMemberAccessed(rightId.consequent, propsReferences) || + isPropsMemberAccessed(rightId.alternate, propsReferences)) + ) { + report(right, 'getProperty', propsReferences.scopeName) + } } /** diff --git a/tests/lib/rules/no-setup-props-reactivity-loss.js b/tests/lib/rules/no-setup-props-reactivity-loss.js index 408ccb09e..6321ea573 100644 --- a/tests/lib/rules/no-setup-props-reactivity-loss.js +++ b/tests/lib/rules/no-setup-props-reactivity-loss.js @@ -113,6 +113,28 @@ tester.run('no-setup-props-reactivity-loss', rule, { ` }, + { + filename: 'test.vue', + code: ` + + ` + }, { filename: 'test.vue', code: ` @@ -680,6 +702,21 @@ tester.run('no-setup-props-reactivity-loss', rule, { line: 6 } ] + }, + { + filename: 'test.vue', + code: ` + + `, + errors: [ + { + messageId: 'getProperty', + line: 4 + } + ] } ] })