From 44a9b978876fa1e6ed903f757dbea1f0ba1ab8dc Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Wed, 17 May 2023 07:40:13 +0900 Subject: [PATCH 1/2] Add support for `defineOptions` to `vue/no-duplicate-attr-inheritance` rule --- lib/rules/no-duplicate-attr-inheritance.js | 21 ++++++++++++++----- .../rules/no-duplicate-attr-inheritance.js | 20 ++++++++++++++++++ 2 files changed, 36 insertions(+), 5 deletions(-) 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..b73fbe4a0 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: ` + + + ` } ], From 43d287c52f63de26e473583c5a547139c9b49255 Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Wed, 17 May 2023 07:42:02 +0900 Subject: [PATCH 2/2] add tests --- .../rules/no-duplicate-attr-inheritance.js | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/lib/rules/no-duplicate-attr-inheritance.js b/tests/lib/rules/no-duplicate-attr-inheritance.js index b73fbe4a0..7fc112123 100644 --- a/tests/lib/rules/no-duplicate-attr-inheritance.js +++ b/tests/lib/rules/no-duplicate-attr-inheritance.js @@ -119,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 + } + ] } ] })