Skip to content

Commit 17f7be5

Browse files
committed
Check array/object expressions too
1 parent 4139e76 commit 17f7be5

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

lib/rules/no-setup-props-destructure.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ module.exports = {
3535
*/
3636
/** @type {Map<FunctionDeclaration | FunctionExpression | ArrowFunctionExpression | Program, ScopePropsReferences>} */
3737
const setupScopePropsReferenceIds = new Map()
38+
const outerExpressionTypes = new Set([
39+
'ArrayExpression',
40+
'CallExpression',
41+
'ObjectExpression'
42+
])
3843

3944
/**
4045
* @param {ESNode} node
@@ -63,7 +68,7 @@ module.exports = {
6368

6469
const rightNode = utils.skipChainExpression(right)
6570

66-
if (rightNode.type === 'CallExpression') {
71+
if (outerExpressionTypes.has(rightNode.type)) {
6772
const propRefs = [...propsReferences.refs.values()]
6873
const isPropsMemberAccessed = propRefs.some((props) => {
6974
const isPropsInCallExpression = utils.inRange(rightNode.range, props)

tests/lib/rules/no-setup-props-destructure.js

+60
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,66 @@ tester.run('no-setup-props-destructure', rule, {
601601
line: 5
602602
}
603603
]
604+
},
605+
{
606+
filename: 'test.vue',
607+
code: `
608+
<script setup>
609+
const props = defineProps({ count: Number })
610+
const newProps = ref({ count: props.count })
611+
</script>
612+
`,
613+
errors: [
614+
{
615+
messageId: 'getProperty',
616+
line: 4
617+
}
618+
]
619+
},
620+
{
621+
filename: 'test.vue',
622+
code: `
623+
<script setup>
624+
const props = defineProps({ count: Number })
625+
const counts = [props.count]
626+
</script>
627+
`,
628+
errors: [
629+
{
630+
messageId: 'getProperty',
631+
line: 4
632+
}
633+
]
634+
},
635+
{
636+
filename: 'test.vue',
637+
code: `
638+
<script setup>
639+
const props = defineProps({ count: Number })
640+
const counter = { count: props.count }
641+
</script>
642+
`,
643+
errors: [
644+
{
645+
messageId: 'getProperty',
646+
line: 4
647+
}
648+
]
649+
},
650+
{
651+
filename: 'test.vue',
652+
code: `
653+
<script setup>
654+
const props = defineProps({ count: Number })
655+
const counters = [{ count: [props.count] }]
656+
</script>
657+
`,
658+
errors: [
659+
{
660+
messageId: 'getProperty',
661+
line: 4
662+
}
663+
]
604664
}
605665
]
606666
})

0 commit comments

Comments
 (0)