From 7050203ee42e4928844c6ad91cf8137de26d11b8 Mon Sep 17 00:00:00 2001 From: waynzh Date: Tue, 27 Feb 2024 15:05:03 +0800 Subject: [PATCH 1/2] fix(v-bind-style): only change kebabCase to camelCase --- lib/rules/v-bind-style.js | 19 +++++++++++++------ tests/lib/rules/v-bind-style.js | 14 ++++++++++++++ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/lib/rules/v-bind-style.js b/lib/rules/v-bind-style.js index 847db33a2..637ded0ca 100644 --- a/lib/rules/v-bind-style.js +++ b/lib/rules/v-bind-style.js @@ -13,6 +13,14 @@ const casing = require('../utils/casing') * @typedef { VDirective & { key: VBindDirectiveKey } } VBindDirective */ +/** + * @param {string} name + * @returns {string} + */ +function kebabCaseToCamelCase(name) { + return casing.isKebabCase(name) ? casing.camelCase(name) : name +} + /** * @param {VBindDirective} node * @returns {boolean} @@ -24,11 +32,10 @@ function isSameName(node) { node.value?.expression?.type === 'Identifier' ? node.value.expression.name : null - return Boolean( - attrName && - valueName && - casing.camelCase(attrName) === casing.camelCase(valueName) - ) + + if (!attrName || !valueName) return false + + return kebabCaseToCamelCase(attrName) === kebabCaseToCamelCase(valueName) } /** @@ -144,7 +151,7 @@ module.exports = { } else if (node.key.argument.type === 'VIdentifier') { yield fixer.insertTextAfter( node, - `="${casing.camelCase(node.key.argument.rawName)}"` + `="${kebabCaseToCamelCase(node.key.argument.rawName)}"` ) } } diff --git a/tests/lib/rules/v-bind-style.js b/tests/lib/rules/v-bind-style.js index b678bf783..f7b5d2cbf 100644 --- a/tests/lib/rules/v-bind-style.js +++ b/tests/lib/rules/v-bind-style.js @@ -124,6 +124,12 @@ tester.run('v-bind-style', rule, { filename: 'test.vue', code: '', options: ['shorthand', { sameNameShorthand: 'always' }] + }, + { + // https://github.com/vuejs/eslint-plugin-vue/issues/2409 + filename: 'test.vue', + code: '', + options: ['shorthand', { sameNameShorthand: 'always' }] } ], invalid: [ @@ -235,6 +241,14 @@ tester.run('v-bind-style', rule, { options: ['shorthand', { sameNameShorthand: 'never' }], errors: [unexpectedShorthand] }, + { + // https://github.com/vuejs/eslint-plugin-vue/issues/2409 + filename: 'test.vue', + code: '', + output: '', + options: ['shorthand', { sameNameShorthand: 'never' }], + errors: [unexpectedShorthand] + }, // same-name shorthand: always { filename: 'test.vue', From ec4f934d6b33fdaf089d95c472f832c27555d8aa Mon Sep 17 00:00:00 2001 From: waynzh Date: Tue, 27 Feb 2024 17:45:30 +0800 Subject: [PATCH 2/2] Update v-bind-style.js --- tests/lib/rules/v-bind-style.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/lib/rules/v-bind-style.js b/tests/lib/rules/v-bind-style.js index f7b5d2cbf..f65099530 100644 --- a/tests/lib/rules/v-bind-style.js +++ b/tests/lib/rules/v-bind-style.js @@ -257,6 +257,13 @@ tester.run('v-bind-style', rule, { options: ['shorthand', { sameNameShorthand: 'always' }], errors: [expectedShorthand] }, + { + filename: 'test.vue', + code: '', + output: '', + options: ['shorthand', { sameNameShorthand: 'always' }], + errors: [expectedShorthand] + }, { filename: 'test.vue', code: '',