From a0ca7dd49a42a1c35763c79574c756dcd66eff7f Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Thu, 28 Feb 2019 22:37:42 +0900 Subject: [PATCH] Changed to not autofix, if if the element have `v-bind:slot` --- lib/rules/syntaxes/slot-scope-attribute.js | 27 ++++++++++++++----- .../no-deprecated-slot-scope-attribute.js | 15 +++++++++++ 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/lib/rules/syntaxes/slot-scope-attribute.js b/lib/rules/syntaxes/slot-scope-attribute.js index 92dddea72..87aa19d11 100644 --- a/lib/rules/syntaxes/slot-scope-attribute.js +++ b/lib/rules/syntaxes/slot-scope-attribute.js @@ -12,15 +12,28 @@ module.exports = { /** * Checks whether the given node can convert to the `v-slot`. * @param {VAttribute | null} slotAttr node of `slot` + * @param {VElement} slotAttr node of `slot` * @returns {boolean} `true` if the given node can convert to the `v-slot` */ - function canConvertToVSlot (slotAttr) { - if (!slotAttr || !slotAttr.value) { - return true + function canConvertToVSlot (slotAttr, element) { + if (slotAttr) { + if (!slotAttr.value) { + return true + } + const slotName = slotAttr.value.value + // If non-Latin characters are included it can not be converted. + return !/[^a-z]/i.test(slotName) } - const slotName = slotAttr.value.value - // If non-Latin characters are included it can not be converted. - return !/[^a-z]/i.test(slotName) + + const vBindSlotAttr = element.attributes + .find(attr => + attr.directive === true && + attr.key.name.name === 'bind' && + attr.key.argument && + attr.key.argument.name === 'slot') + // if the element have `v-bind:slot` it can not be converted. + // Conversion of `v-bind:slot` is done with `vue/no-deprecated-slot-attribute`. + return !vBindSlotAttr } /** @@ -62,7 +75,7 @@ module.exports = { const element = scopeAttr.parent const slotAttr = element.attributes .find(attr => attr.directive === false && attr.key.name === 'slot') - if (!canConvertToVSlot(slotAttr)) { + if (!canConvertToVSlot(slotAttr, element)) { return null } return fixSlotToVSlot(fixer, slotAttr, scopeAttr) diff --git a/tests/lib/rules/no-deprecated-slot-scope-attribute.js b/tests/lib/rules/no-deprecated-slot-scope-attribute.js index cbd77c35a..ab9a610ba 100644 --- a/tests/lib/rules/no-deprecated-slot-scope-attribute.js +++ b/tests/lib/rules/no-deprecated-slot-scope-attribute.js @@ -139,6 +139,21 @@ tester.run('no-deprecated-slot-scope-attribute', rule, { line: 4 } ] + }, + { + code: ` + `, + output: null, + errors: [ + { + message: '`slot-scope` are deprecated.', + line: 4 + } + ] } ] })