8000 Add support for `defineOptions` to `vue/no-duplicate-attr-inheritance… · Demivan/eslint-plugin-vue@30931f0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 30931f0

Browse files
authored
Add support for defineOptions to vue/no-duplicate-attr-inheritance rule (vuejs#2178)
1 parent 8494cd5 commit 30931f0

File tree

2 files changed

+68
-5
lines changed

2 files changed

+68
-5
lines changed

lib/rules/no-duplicate-attr-inheritance.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,23 @@ module.exports = {
2626
/** @type {string | number | boolean | RegExp | BigInt | null} */
2727
let inheritsAttrs = true
2828

29-
return Object.assign(
30-
utils.executeOnVue(context, (node) => {
31-
const inheritAttrsProp = utils.findProperty(node, 'inheritAttrs')
29+
/** @param {ObjectExpression} node */
30+
function processOptions(node) {
31+
const inheritAttrsProp = utils.findProperty(node, 'inheritAttrs')
3232

33-
if (inheritAttrsProp && inheritAttrsProp.value.type === 'Literal') {
34-
inheritsAttrs = inheritAttrsProp.value.value
33+
if (inheritAttrsProp && inheritAttrsProp.value.type === 'Literal') {
34+
inheritsAttrs = inheritAttrsProp.value.value
35+
}
36+
}
37+
38+
return utils.compositingVisitors(
39+
utils.executeOnVue(context, processOptions),
40+
utils.defineScriptSetupVisitor(context, {
41+
onDefineOptionsEnter(node) {
42+
if (node.arguments.length === 0) return
43+
const define = node.arguments[0]
44+
if (define.type !== 'ObjectExpression') return
45+
processOptions(define)
3546
}
3647
}),
3748
utils.defineTemplateBodyVisitor(context, {

tests/lib/rules/no-duplicate-attr-inheritance.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,26 @@ ruleTester.run('no-duplicate-attr-inheritance', rule, {
7979
export default { }
8080
</script>
8181
`
82+
},
83+
{
84+
filename: 'test.vue',
85+
code: `
86+
<script>
87+
export default { inheritAttrs: false }
88+
</script>
89+
<script setup>
90+
</script>
91+
<template><div v-bind="$attrs" /></template>
92+
`
93+
},
94+
{
95+
filename: 'test.vue',
96+
code: `
97+
<script setup>
98+
defineOptions({ inheritAttrs: false })
99+
</script>
100+
<template><div v-bind="$attrs" /></template>
101+
`
82102
}
83103
],
84104

@@ -99,6 +119,38 @@ ruleTester.run('no-duplicate-attr-inheritance', rule, {
99119
</script>
100120
`,
101121
errors: ['Set "inheritAttrs" to false.']
122+
},
123+
{
124+
filename: 'test.vue',
125+
code: `
126+
<script>
127+
export default { inheritAttrs: true }
128+
</script>
129+
<script setup>
130+
</script>
131+
<template><div v-bind="$attrs" /></template>
132+
`,
133+
errors: [
134+
{
135+
message: 'Set "inheritAttrs" to false.',
136+
line: 7
137+
}
138+
]
139+
},
140+
{
141+
filename: 'test.vue',
142+
code: `
143+
<script setup>
144+
defineOptions({ inheritAttrs: true })
145+
</script>
146+
<template><div v-bind="$attrs" /></template>
147+
`,
148+
errors: [
149+
{
150+
message: 'Set "inheritAttrs" to false.',
151+
line: 5
152+
}
153+
]
102154
}
103155
]
104156
})

0 commit comments

Comments
 (0)
0