From 460e57434dcb24d03fb76ec3389e9bfc56cd7ff7 Mon Sep 17 00:00:00 2001
From: kurageso <63407106+kurageso@users.noreply.github.com>
Date: Wed, 23 Nov 2022 19:09:13 +0900
Subject: [PATCH 1/6] fix(vue/attribute-hyphenation): disable autofix to kebab
case if attribute name contains `_`
---
lib/rules/attribute-hyphenation.js | 12 ++-
tests/lib/rules/attribute-hyphenation.js | 94 ++++++++++++++++++++++++
2 files changed, 104 insertions(+), 2 deletions(-)
diff --git a/lib/rules/attribute-hyphenation.js b/lib/rules/attribute-hyphenation.js
index d2ae0ccac..87a398e4f 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 (useHyphenated && 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..a2b997af8 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: ['always']
}
],
@@ -280,6 +290,90 @@ ruleTester.run('attribute-hyphenation', rule, {
line: 1
}
]
+ },
+ {
+ filename: 'test.vue',
+ code: '
',
+ output:
+ '
',
+ options: ['always'],
+ errors: [
+ {
+ message: "Attribute ':AttrEe' must be hyphenated.",
+ type: 'VDirectiveKey',
+ line: 1
+ }
+ ]
+ },
+ {
+ filename: 'test.vue',
+ code: '
',
+ output:
+ '
',
+ options: ['always'],
+ errors: [
+ {
+ message: "Attribute ':attr_Gg' must be hyphenated.",
+ type: 'VDirectiveKey',
+ line: 1
+ }
+ ]
+ },
+ {
+ filename: 'test.vue',
+ code: '
',
+ output:
+ '
',
+ options: ['always'],
+ errors: [
+ {
+ message: "Attribute ':Attr_Hh' must be hyphenated.",
+ type: 'VDirectiveKey',
+ line: 1
+ }
+ ]
+ },
+ {
+ filename: 'test.vue',
+ code: '
',
+ output:
+ '
',
+ options: ['always'],
+ errors: [
+ {
+ message: "Attribute ':_attr_Jj' must be hyphenated.",
+ type: 'VDirectiveKey',
+ line: 1
+ }
+ ]
+ },
+ {
+ filename: 'test.vue',
+ code: '
',
+ output:
+ '
',
+ options: ['always'],
+ errors: [
+ {
+ message: "Attribute ':_attrKk' must be hyphenated.",
+ type: 'VDirectiveKey',
+ line: 1
+ }
+ ]
+ },
+ {
+ filename: 'test.vue',
+ code: '
',
+ output:
+ '
',
+ options: ['always'],
+ errors: [
+ {
+ message: "Attribute ':_AttrLl' must be hyphenated.",
+ type: 'VDirectiveKey',
+ line: 1
+ }
+ ]
}
]
})
From 5b2d44a298ab552dedb05c83d498fd3d3711fb5a Mon Sep 17 00:00:00 2001
From: kurageso <63407106+kurageso@users.noreply.github.com>
Date: Wed, 23 Nov 2022 20:22:35 +0900
Subject: [PATCH 2/6] use `output: null`
---
tests/lib/rules/attribute-hyphenation.js | 15 +++++----------
1 file changed, 5 insertions(+), 10 deletions(-)
diff --git a/tests/lib/rules/attribute-hyphenation.js b/tests/lib/rules/attribute-hyphenation.js
index a2b997af8..feee4068b 100644
--- a/tests/lib/rules/attribute-hyphenation.js
+++ b/tests/lib/rules/attribute-hyphenation.js
@@ -308,8 +308,7 @@ ruleTester.run('attribute-hyphenation', rule, {
{
filename: 'test.vue',
code: '
',
- output:
- '
',
+ output: null,
options: ['always'],
errors: [
{
@@ -322,8 +321,7 @@ ruleTester.run('attribute-hyphenation', rule, {
{
filename: 'test.vue',
code: '
',
- output:
- '
',
+ output: null,
options: ['always'],
errors: [
{
@@ -336,8 +334,7 @@ ruleTester.run('attribute-hyphenation', rule, {
{
filename: 'test.vue',
code: '
',
- output:
- '
',
+ output: null,
options: ['always'],
errors: [
{
@@ -350,8 +347,7 @@ ruleTester.run('attribute-hyphenation', rule, {
{
filename: 'test.vue',
code: '
',
- output:
- '
',
+ output: null,
options: ['always'],
errors: [
{
@@ -364,8 +360,7 @@ ruleTester.run('attribute-hyphenation', rule, {
{
filename: 'test.vue',
code: '
',
- output:
- '
',
+ output: null,
options: ['always'],
errors: [
{
From 321ea51ba510ffb5adb2be61607c1ac290c6b432 Mon Sep 17 00:00:00 2001
From: kurageso <63407106+kurageso@users.noreply.github.com>
Date: Wed, 23 Nov 2022 20:27:42 +0900
Subject: [PATCH 3/6] remove a redundant test
---
tests/lib/rules/attribute-hyphenation.js | 5 -----
1 file changed, 5 deletions(-)
diff --git a/tests/lib/rules/attribute-hyphenation.js b/tests/lib/rules/attribute-hyphenation.js
index feee4068b..5bcdb5745 100644
--- a/tests/lib/rules/attribute-hyphenation.js
+++ b/tests/lib/rules/attribute-hyphenation.js
@@ -63,11 +63,6 @@ ruleTester.run('attribute-hyphenation', rule, {
filename: 'test.vue',
code: '
',
options: ['always']
- },
- {
- filename: 'test.vue',
- code: '
',
- options: ['always']
}
],
From 9fefd1f41d2b7e6d5df28c36f74ec0fd97bab552 Mon Sep 17 00:00:00 2001
From: kurageso <63407106+kurageso@users.noreply.github.com>
Date: Wed, 23 Nov 2022 20:29:10 +0900
Subject: [PATCH 4/6] remove a redundant test
---
tests/lib/rules/attribute-hyphenation.js | 14 --------------
1 file changed, 14 deletions(-)
diff --git a/tests/lib/rules/attribute-hyphenation.js b/tests/lib/rules/attribute-hyphenation.js
index 5bcdb5745..faef29f11 100644
--- a/tests/lib/rules/attribute-hyphenation.js
+++ b/tests/lib/rules/attribute-hyphenation.js
@@ -286,20 +286,6 @@ ruleTester.run('attribute-hyphenation', rule, {
}
]
},
- {
- filename: 'test.vue',
- code: '
',
- output:
- '
',
- options: ['always'],
- errors: [
- {
- message: "Attribute ':AttrEe' must be hyphenated.",
- type: 'VDirectiveKey',
- line: 1
- }
- ]
- },
{
filename: 'test.vue',
code: '
',
From e8c35634a5568116d6ae2c6f4f5bb8f8da7c12db Mon Sep 17 00:00:00 2001
From: kurageso <63407106+kurageso@users.noreply.github.com>
Date: Wed, 23 Nov 2022 23:29:09 +0900
Subject: [PATCH 5/6] add test cases with current spec
---
tests/lib/rules/attribute-hyphenation.js | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/tests/lib/rules/attribute-hyphenation.js b/tests/lib/rules/attribute-hyphenation.js
index faef29f11..01663bfaa 100644
--- a/tests/lib/rules/attribute-hyphenation.js
+++ b/tests/lib/rules/attribute-hyphenation.js
@@ -63,6 +63,11 @@ ruleTester.run('attribute-hyphenation', rule, {
filename: 'test.vue',
code: '
',
options: ['always']
+ },
+ {
+ filename: 'test.vue',
+ code: '
',
+ options: ['never']
}
],
@@ -350,6 +355,20 @@ ruleTester.run('attribute-hyphenation', rule, {
line: 1
}
]
+ },
+ {
+ filename: 'test.vue',
+ code: '
',
+ output:
+ '
',
+ options: ['never'],
+ errors: [
+ {
+ message: "Attribute ':my-custom_prop' can't be hyphenated.",
+ type: 'VDirectiveKey',
+ line: 1
+ }
+ ]
}
]
})
From 38d6e1bedcab702c052fae9039532a260f82e934 Mon Sep 17 00:00:00 2001
From: kurageso <63407106+kurageso@users.noreply.github.com>
Date: Wed, 23 Nov 2022 23:34:21 +0900
Subject: [PATCH 6/6] fixed a problem when converting to CamelCase
---
lib/rules/attribute-hyphenation.js | 2 +-
tests/lib/rules/attribute-hyphenation.js | 3 +--
2 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/lib/rules/attribute-hyphenation.js b/lib/rules/attribute-hyphenation.js
index 87a398e4f..24bacffc2 100644
--- a/lib/rules/attribute-hyphenation.js
+++ b/lib/rules/attribute-hyphenation.js
@@ -95,7 +95,7 @@ module.exports = {
text
},
fix: (fixer) => {
- if (useHyphenated && text.includes('_')) {
+ if (text.includes('_')) {
return null
}
diff --git a/tests/lib/rules/attribute-hyphenation.js b/tests/lib/rules/attribute-hyphenation.js
index 01663bfaa..146c25658 100644
--- a/tests/lib/rules/attribute-hyphenation.js
+++ b/tests/lib/rules/attribute-hyphenation.js
@@ -359,8 +359,7 @@ ruleTester.run('attribute-hyphenation', rule, {
{
filename: 'test.vue',
code: '
',
- output:
- '
',
+ output: null,
options: ['never'],
errors: [
{