Skip to content

Commit

Permalink
Check array/object expressions too
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmyersdev committed Jul 28, 2023
1 parent db8717f commit ce36f18
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/rules/no-setup-props-destructure.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ module.exports = {
*/
/** @type {Map<FunctionDeclaration | FunctionExpression | ArrowFunctionExpression | Program, ScopePropsReferences>} */
const setupScopePropsReferenceIds = new Map()
const outerExpressionTypes = new Set([
'ArrayExpression',
'CallExpression',
'ObjectExpression'
])

/**
* @param {ESNode} node
Expand Down Expand Up @@ -63,7 +68,7 @@ module.exports = {

const rightNode = utils.skipChainExpression(right)

if (rightNode.type === 'CallExpression') {
if (outerExpressionTypes.has(rightNode.type)) {
const propRefs = [...propsReferences.refs.values()]
const isPropsMemberAccessed = propRefs.some((props) => {
const isPropsInCallExpression = utils.inRange(rightNode.range, props)
Expand Down
60 changes: 60 additions & 0 deletions tests/lib/rules/no-setup-props-destructure.js
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,66 @@ tester.run('no-setup-props-destructure', rule, {
line: 5
}
]
},
{
filename: 'test.vue',
code: `
<script setup>
const props = defineProps({ count: Number })
const newProps = ref({ count: props.count })
</script>
`,
errors: [
{
messageId: 'getProperty',
line: 4
}
]
},
{
filename: 'test.vue',
code: `
<script setup>
const props = defineProps({ count: Number })
const counts = [props.count]
</script>
`,
errors: [
{
messageId: 'getProperty',
line: 4
}
]
},
{
filename: 'test.vue',
code: `
<script setup>
const props = defineProps({ count: Number })
const counter = { count: props.count }
</script>
`,
errors: [
{
messageId: 'getProperty',
line: 4
}
]
},
{
filename: 'test.vue',
code: `
<script setup>
const props = defineProps({ count: Number })
const counters = [{ count: [props.count] }]
</script>
`,
errors: [
{
messageId: 'getProperty',
line: 4
}
]
}
]
})

0 comments on commit ce36f18

Please sign in to comment.