Skip to content

Commit c0eaefa

Browse files
committed
Improve tests & detecting '-'
1 parent 8d8e3d7 commit c0eaefa

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

lib/rules/attribute-hyphenation.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ function create (context) {
1616
const options = context.options[0]
1717
const useHyphenated = options !== 'never'
1818

19-
const kebabCase = casing.getConverter('kebab-case')
2019
const caseConverter = casing.getConverter(useHyphenated ? 'kebab-case' : 'camelCase')
2120

2221
function reportIssue (node, name) {
@@ -37,7 +36,7 @@ function create (context) {
3736
if (value.indexOf('data-') !== -1 || value.indexOf('aria-') !== -1) {
3837
return true
3938
}
40-
return useHyphenated ? kebabCase(value) === value : kebabCase(value) !== value
39+
return useHyphenated ? value.toLowerCase() === value : !/-/.test(value)
4140
}
4241

4342
// ----------------------------------------------------------------------
@@ -49,11 +48,8 @@ function create (context) {
4948
if (!utils.isCustomComponent(node.parent.parent)) return
5049

5150
const name = !node.directive ? node.key.name : node.key.name === 'bind' ? node.key.argument : false
52-
if (!name) return
51+
if (!name || isIgnoredAttribute(name)) return
5352

54-
if (isIgnoredAttribute(name)) {
55-
return
56-
}
5753
reportIssue(node, name)
5854
}
5955
})

tests/lib/rules/attribute-hyphenation.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,17 @@ ruleTester.run('attribute-hyphenation', rule, {
3030
},
3131
{
3232
filename: 'test.vue',
33-
code: '<template><div><custom my-prop="prop"></custom></div></template>',
33+
code: '<template><div><custom data-id="foo" aria-test="bar" my-prop="prop"></custom></div></template>',
3434
options: ['always']
3535
},
3636
{
3737
filename: 'test.vue',
38-
code: '<template><div><a onClick="" my-prop="prop"></a></div></template>',
38+
code: '<template><div><custom data-id="foo" aria-test="bar" myProp="prop"></custom></div></template>',
39+
options: ['never']
40+
},
41+
{
42+
filename: 'test.vue',
43+
code: '<template><div data-id="foo" aria-test="bar"><a onClick="" my-prop="prop"></a></div></template>',
3944
options: ['never']
4045
}
4146
],
@@ -44,6 +49,7 @@ ruleTester.run('attribute-hyphenation', rule, {
4449
{
4550
filename: 'test.vue',
4651
code: '<template><div><custom my-prop="prop"></custom></div></template>',
52+
output: '<template><div><custom myProp="prop"></custom></div></template>',
4753
options: ['never'],
4854
errors: [{
4955
message: "Attribute 'my-prop' cann't be hyphenated.",
@@ -54,6 +60,7 @@ ruleTester.run('attribute-hyphenation', rule, {
5460
{
5561
filename: 'test.vue',
5662
code: '<template><div><custom MyProp="prop"></custom></div></template>',
63+
output: '<template><div><custom my-prop="prop"></custom></div></template>',
5764
options: ['always'],
5865
errors: [{
5966
message: "Attribute 'MyProp' must be hyphenated.",
@@ -64,6 +71,7 @@ ruleTester.run('attribute-hyphenation', rule, {
6471
{
6572
filename: 'test.vue',
6673
code: '<template><div><custom :my-prop="prop"></custom></div></template>',
74+
output: '<template><div><custom :myProp="prop"></custom></div></template>',
6775
options: ['never'],
6876
errors: [{
6977
message: "Attribute ':my-prop' cann't be hyphenated.",
@@ -74,6 +82,7 @@ ruleTester.run('attribute-hyphenation', rule, {
7482
{
7583
filename: 'test.vue',
7684
code: '<template><div><custom :MyProp="prop"></custom></div></template>',
85+
output: '<template><div><custom :my-prop="prop"></custom></div></template>',
7786
options: ['always'],
7887
errors: [{
7988
message: "Attribute ':MyProp' must be hyphenated.",
@@ -84,6 +93,7 @@ ruleTester.run('attribute-hyphenation', rule, {
8493
{
8594
filename: 'test.vue',
8695
code: '<template><div><custom v-bind:my-prop="prop"></custom></div></template>',
96+
output: '<template><div><custom v-bind:myProp="prop"></custom></div></template>',
8797
options: ['never'],
8898
errors: [{
8999
message: "Attribute 'v-bind:my-prop' cann't be hyphenated.",
@@ -94,6 +104,7 @@ ruleTester.run('attribute-hyphenation', rule, {
94104
{
95105
filename: 'test.vue',
96106
code: '<template><div><custom v-bind:MyProp="prop"></custom></div></template>',
107+
output: '<template><div><custom v-bind:my-prop="prop"></custom></div></template>',
97108
options: ['always'],
98109
errors: [{
99110
message: "Attribute 'v-bind:MyProp' must be hyphenated.",

0 commit comments

Comments
 (0)