Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions lib/rules/no-restricted-component-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,25 @@ module.exports = {
/** @type {ParsedOption[]} */
const options = context.options.map(parseOption)

return utils.defineVueVisitor(context, {
onVueObjectEnter(node) {
for (const option of options) {
verify(node, option.test, option.message)
return utils.compositingVisitors(
utils.defineVueVisitor(context, {
onVueObjectEnter(node) {
for (const option of options) {
verify(node, option.test, option.message)
}
}
}
})
}),
utils.defineScriptSetupVisitor(context, {
onDefineOptionsEnter(node) {
if (node.arguments.length === 0) return
const define = node.arguments[0]
if (define.type !== 'ObjectExpression') return
for (const option of options) {
verify(define, option.test, option.message)
}
}
})
)

/**
* @param {ObjectExpression} node
Expand Down
16 changes: 16 additions & 0 deletions tests/lib/rules/no-restricted-component-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ tester.run('no-restricted-component-options', rule, {
</script>
`,
options: [['foo', 'bar']]
},
{
filename: 'test.vue',
code: `<script setup> defineOptions({ name: 'Foo' }) </script>`,
options: ['Foo']
}
],
invalid: [
Expand Down Expand Up @@ -304,6 +309,17 @@ tester.run('no-restricted-component-options', rule, {
line: 5
}
]
},
{
filename: 'test.vue',
code: `<script setup> defineOptions({ Foo: 'Foo' }) </script>`,
options: ['Foo'],
errors: [
{
message: 'Using `Foo` is not allowed.',
line: 1
}
]
}
]
})