From ec0276ba0cd570e7a83406195c36288528c42aa4 Mon Sep 17 00:00:00 2001 From: kurageso <63407106+kurageso@users.noreply.github.com> Date: Thu, 24 Nov 2022 08:26:40 +0900 Subject: [PATCH] Disable autofix in `vue/attribute-hyphenation` for attributes with underscore (#2045) --- lib/rules/attribute-hyphenation.js | 12 +++- tests/lib/rules/attribute-hyphenation.js | 88 ++++++++++++++++++++++++ 2 files changed, 98 insertions(+), 2 deletions(-) diff --git a/lib/rules/attribute-hyphenation.js b/lib/rules/attribute-hyphenation.js index d2ae0ccac..24bacffc2 100644 --- a/lib/rules/attribute-hyphenation.js +++ b/lib/rules/attribute-hyphenation.js @@ -94,8 +94,16 @@ module.exports = { data: { text }, - fix: (fixer) => - fixer.replaceText(node.key, text.replace(name, caseConverter(name))) + fix: (fixer) => { + if (text.includes('_')) { + return null + } + + return fixer.replaceText( + node.key, + text.replace(name, caseConverter(name)) + ) + } }) } diff --git a/tests/lib/rules/attribute-hyphenation.js b/tests/lib/rules/attribute-hyphenation.js index 002254dd0..146c25658 100644 --- a/tests/lib/rules/attribute-hyphenation.js +++ b/tests/lib/rules/attribute-hyphenation.js @@ -58,6 +58,16 @@ ruleTester.run('attribute-hyphenation', rule, { filename: 'test.vue', code: '', options: ['never'] + }, + { + filename: 'test.vue', + code: '', + options: ['always'] + }, + { + filename: 'test.vue', + code: '', + options: ['never'] } ], @@ -280,6 +290,84 @@ ruleTester.run('attribute-hyphenation', rule, { line: 1 } ] + }, + { + filename: 'test.vue', + code: '', + output: null, + options: ['always'], + errors: [ + { + message: "Attribute ':attr_Gg' must be hyphenated.", + type: 'VDirectiveKey', + line: 1 + } + ] + }, + { + filename: 'test.vue', + code: '', + output: null, + options: ['always'], + errors: [ + { + message: "Attribute ':Attr_Hh' must be hyphenated.", + type: 'VDirectiveKey', + line: 1 + } + ] + }, + { + filename: 'test.vue', + code: '', + output: null, + options: ['always'], + errors: [ + { + message: "Attribute ':_attr_Jj' must be hyphenated.", + type: 'VDirectiveKey', + line: 1 + } + ] + }, + { + filename: 'test.vue', + code: '', + output: null, + options: ['always'], + errors: [ + { + message: "Attribute ':_attrKk' must be hyphenated.", + type: 'VDirectiveKey', + line: 1 + } + ] + }, + { + filename: 'test.vue', + code: '', + output: null, + options: ['always'], + errors: [ + { + message: "Attribute ':_AttrLl' must be hyphenated.", + type: 'VDirectiveKey', + line: 1 + } + ] + }, + { + filename: 'test.vue', + code: '', + output: null, + options: ['never'], + errors: [ + { + message: "Attribute ':my-custom_prop' can't be hyphenated.", + type: 'VDirectiveKey', + line: 1 + } + ] } ] })