diff --git a/lib/rules/no-duplicate-attr-inheritance.js b/lib/rules/no-duplicate-attr-inheritance.js index eea2bf765..a8661b091 100644 --- a/lib/rules/no-duplicate-attr-inheritance.js +++ b/lib/rules/no-duplicate-attr-inheritance.js @@ -26,12 +26,23 @@ module.exports = { /** @type {string | number | boolean | RegExp | BigInt | null} */ let inheritsAttrs = true - return Object.assign( - utils.executeOnVue(context, (node) => { - const inheritAttrsProp = utils.findProperty(node, 'inheritAttrs') + /** @param {ObjectExpression} node */ + function processOptions(node) { + const inheritAttrsProp = utils.findProperty(node, 'inheritAttrs') - if (inheritAttrsProp && inheritAttrsProp.value.type === 'Literal') { - inheritsAttrs = inheritAttrsProp.value.value + if (inheritAttrsProp && inheritAttrsProp.value.type === 'Literal') { + inheritsAttrs = inheritAttrsProp.value.value + } + } + + return utils.compositingVisitors( + utils.executeOnVue(context, processOptions), + utils.defineScriptSetupVisitor(context, { + onDefineOptionsEnter(node) { + if (node.arguments.length === 0) return + const define = node.arguments[0] + if (define.type !== 'ObjectExpression') return + processOptions(define) } }), utils.defineTemplateBodyVisitor(context, { diff --git a/tests/lib/rules/no-duplicate-attr-inheritance.js b/tests/lib/rules/no-duplicate-attr-inheritance.js index b4a00c228..7fc112123 100644 --- a/tests/lib/rules/no-duplicate-attr-inheritance.js +++ b/tests/lib/rules/no-duplicate-attr-inheritance.js @@ -79,6 +79,26 @@ ruleTester.run('no-duplicate-attr-inheritance', rule, { export default { } ` + }, + { + filename: 'test.vue', + code: ` + + + + ` + }, + { + filename: 'test.vue', + code: ` + + + ` } ], @@ -99,6 +119,38 @@ ruleTester.run('no-duplicate-attr-inheritance', rule, { `, errors: ['Set "inheritAttrs" to false.'] + }, + { + filename: 'test.vue', + code: ` + + + + `, + errors: [ + { + message: 'Set "inheritAttrs" to false.', + line: 7 + } + ] + }, + { + filename: 'test.vue', + code: ` + + + `, + errors: [ + { + message: 'Set "inheritAttrs" to false.', + line: 5 + } + ] } ] })