From b58cdf85af04d4d8a0bc1e057a9c6c8f874626bd Mon Sep 17 00:00:00 2001 From: kricsleo <32707098+kricsleo@users.noreply.github.com> Date: Thu, 22 Aug 2024 11:29:52 +0800 Subject: [PATCH 1/3] fix(attribute-hyphenation): skip auto-fix when suffixed with `.sync` --- lib/rules/attribute-hyphenation.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/rules/attribute-hyphenation.js b/lib/rules/attribute-hyphenation.js index 0ef2a0420..c3b758955 100644 --- a/lib/rules/attribute-hyphenation.js +++ b/lib/rules/attribute-hyphenation.js @@ -104,6 +104,10 @@ module.exports = { if (/^[A-Z]/.test(name)) { return null } + + if(text.endsWith('.sync')) { + return null + } return fixer.replaceText( node.key, From 06fec5dd7911c31dda5254d60c815d063712326a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E5=9C=A3=E5=B3=B0?= Date: Thu, 22 Aug 2024 11:45:39 +0800 Subject: [PATCH 2/3] style: fix lint style --- lib/rules/attribute-hyphenation.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/rules/attribute-hyphenation.js b/lib/rules/attribute-hyphenation.js index c3b758955..f7fd46e50 100644 --- a/lib/rules/attribute-hyphenation.js +++ b/lib/rules/attribute-hyphenation.js @@ -104,8 +104,8 @@ module.exports = { if (/^[A-Z]/.test(name)) { return null } - - if(text.endsWith('.sync')) { + + if (text.endsWith('.sync')) { return null } From 4bd1fcb0e32e4dad23458e35dc58810ae8f10863 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E5=9C=A3=E5=B3=B0?= Date: Thu, 22 Aug 2024 12:33:24 +0800 Subject: [PATCH 3/3] chore: add tests --- lib/rules/attribute-hyphenation.js | 4 +-- tests/lib/rules/attribute-hyphenation.js | 36 ++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/lib/rules/attribute-hyphenation.js b/lib/rules/attribute-hyphenation.js index f7fd46e50..54ac77791 100644 --- a/lib/rules/attribute-hyphenation.js +++ b/lib/rules/attribute-hyphenation.js @@ -101,11 +101,11 @@ module.exports = { return null } - if (/^[A-Z]/.test(name)) { + if (text.endsWith('.sync')) { return null } - if (text.endsWith('.sync')) { + if (/^[A-Z]/.test(name)) { return null } diff --git a/tests/lib/rules/attribute-hyphenation.js b/tests/lib/rules/attribute-hyphenation.js index 4d867d15e..16f6e4e10 100644 --- a/tests/lib/rules/attribute-hyphenation.js +++ b/tests/lib/rules/attribute-hyphenation.js @@ -70,6 +70,16 @@ ruleTester.run('attribute-hyphenation', rule, { filename: 'test.vue', code: '', options: ['never'] + }, + { + filename: 'test.vue', + code: '', + options: ['always'] + }, + { + filename: 'test.vue', + code: '', + options: ['never'] } ], @@ -367,6 +377,32 @@ ruleTester.run('attribute-hyphenation', rule, { line: 1 } ] + }, + { + filename: 'test.vue', + code: '', + output: null, + options: ['always'], + errors: [ + { + message: "Attribute ':myAge.sync' must be hyphenated.", + type: 'VDirectiveKey', + line: 1 + } + ] + }, + { + filename: 'test.vue', + code: '', + output: null, + options: ['never'], + errors: [ + { + message: "Attribute ':my-age.sync' can't be hyphenated.", + type: 'VDirectiveKey', + line: 1 + } + ] } ] })