From 354c0de249b4cc21566bcd09932461863fe61ee7 Mon Sep 17 00:00:00 2001 From: Wayne Zhang Date: Mon, 2 Sep 2024 18:02:44 +0800 Subject: [PATCH] fix(attribute-hyphenation): apply to v-model directive (#2511) --- lib/rules/attribute-hyphenation.js | 2 +- tests/lib/rules/attribute-hyphenation.js | 47 ++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/lib/rules/attribute-hyphenation.js b/lib/rules/attribute-hyphenation.js index 54ac77791..35519d231 100644 --- a/lib/rules/attribute-hyphenation.js +++ b/lib/rules/attribute-hyphenation.js @@ -18,7 +18,7 @@ function getAttributeName(node) { } if ( - node.key.name.name === 'bind' && + (node.key.name.name === 'bind' || node.key.name.name === 'model') && node.key.argument && node.key.argument.type === 'VIdentifier' ) { diff --git a/tests/lib/rules/attribute-hyphenation.js b/tests/lib/rules/attribute-hyphenation.js index 16f6e4e10..18d60e19c 100644 --- a/tests/lib/rules/attribute-hyphenation.js +++ b/tests/lib/rules/attribute-hyphenation.js @@ -26,6 +26,11 @@ ruleTester.run('attribute-hyphenation', rule, { code: '', options: ['always'] }, + { + filename: 'test.vue', + code: '', + options: ['always'] + }, { filename: 'test.vue', code: '', @@ -219,6 +224,48 @@ ruleTester.run('attribute-hyphenation', rule, { } ] }, + { + // https://github.com/vuejs/eslint-plugin-vue/issues/2510 + filename: 'test.vue', + code: '', + output: + '', + options: ['never'], + errors: [ + { + message: "Attribute 'v-model:my-prop' can't be hyphenated.", + type: 'VDirectiveKey', + line: 1 + } + ] + }, + { + filename: 'test.vue', + code: '', + output: + '', + options: ['always'], + errors: [ + { + message: "Attribute 'v-model:myProp' must be hyphenated.", + type: 'VDirectiveKey', + line: 1 + } + ] + }, + { + filename: 'test.vue', + code: '', + output: null, + options: ['always'], + errors: [ + { + message: "Attribute 'v-model:MyProp' must be hyphenated.", + type: 'VDirectiveKey', + line: 1 + } + ] + }, { filename: 'test.vue', code: `