Skip to content

Commit a9e0a49

Browse files
authored
Add support for defineOptions to vue/no-restricted-component-options rule (#2162)
1 parent 70b88a2 commit a9e0a49

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

Diff for: lib/rules/no-restricted-component-options.js

+18-6
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,25 @@ module.exports = {
173173
/** @type {ParsedOption[]} */
174174
const options = context.options.map(parseOption)
175175

176-
return utils.defineVueVisitor(context, {
177-
onVueObjectEnter(node) {
178-
for (const option of options) {
179-
verify(node, option.test, option.message)
176+
return utils.compositingVisitors(
177+
utils.defineVueVisitor(context, {
178+
onVueObjectEnter(node) {
179+
for (const option of options) {
180+
verify(node, option.test, option.message)
181+
}
180182
}
181-
}
182-
})
183+
}),
184+
utils.defineScriptSetupVisitor(context, {
185+
onDefineOptionsEnter(node) {
186+
if (node.arguments.length === 0) return
187+
const define = node.arguments[0]
188+
if (define.type !== 'ObjectExpression') return
189+
for (const option of options) {
190+
verify(define, option.test, option.message)
191+
}
192+
}
193+
})
194+
)
183195

184196
/**
185197
* @param {ObjectExpression} node

Diff for: tests/lib/rules/no-restricted-component-options.js

+16
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ tester.run('no-restricted-component-options', rule, {
101101
</script>
102102
`,
103103
options: [['foo', 'bar']]
104+
},
105+
{
106+
filename: 'test.vue',
107+
code: `<script setup> defineOptions({ name: 'Foo' }) </script>`,
108+
options: ['Foo']
104109
}
105110
],
106111
invalid: [
@@ -304,6 +309,17 @@ tester.run('no-restricted-component-options', rule, {
304309
line: 5
305310
}
306311
]
312+
},
313+
{
314+
filename: 'test.vue',
315+
code: `<script setup> defineOptions({ Foo: 'Foo' }) </script>`,
316+
options: ['Foo'],
317+
errors: [
318+
{
319+
message: 'Using `Foo` is not allowed.',
320+
line: 1
321+
}
322+
]
307323
}
308324
]
309325
})

0 commit comments

Comments
 (0)