Skip to content

Commit ce36f18

Browse files
committed
Check array/object expressions too
1 parent db8717f commit ce36f18

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

0 commit comments

Comments
 (0)