@@ -12,6 +12,9 @@ const tester = new RuleTester({
1212 languageOptions : { parser : require ( 'vue-eslint-parser' ) , ecmaVersion : 2015 }
1313} )
1414
15+ const expectedShorthand = 'Expected shorthand same name.'
16+ const unexpectedShorthand = 'Unexpected shorthand same name.'
17+
1518tester . run ( 'v-bind-style' , rule , {
1619 valid : [
1720 {
@@ -34,7 +37,7 @@ tester.run('v-bind-style', rule, {
3437 {
3538 filename : 'test.vue' ,
3639 code : '<template><div v-bind:foo="foo"></div></template>' ,
37- options : [ 'longform' ]
40+ options : [ 'longform' , { sameNameShorthand : 'ignore' } ]
3841 } ,
3942
4043 // Don't enforce `.prop` shorthand because of experimental.
@@ -55,6 +58,72 @@ tester.run('v-bind-style', rule, {
5558 filename : 'test.vue' ,
5659 code : '<template><div .foo="foo"></div></template>' ,
5760 options : [ 'shorthand' ]
61+ } ,
62+ // same-name shorthand: never
63+ {
64+ filename : 'test.vue' ,
65+ code : '<template><div :foo="foo" /></template>' ,
66+ options : [ 'shorthand' , { sameNameShorthand : 'never' } ]
67+ } ,
68+ {
69+ filename : 'test.vue' ,
70+ code : '<template><div v-bind:foo="foo" /></template>' ,
71+ options : [ 'longform' , { sameNameShorthand : 'never' } ]
72+ } ,
73+ {
74+ // modifier
75+ filename : 'test.vue' ,
76+ code : `
77+ <template>
78+ <div :foo.prop="foo" />
79+ <div .foo="foo" />
80+ </template>
81+ ` ,
82+ options : [ 'shorthand' , { sameNameShorthand : 'never' } ]
83+ } ,
84+ {
85+ filename : 'test.vue' ,
86+ code : '<template><div v-bind:foo.prop="foo" /></template>' ,
87+ options : [ 'longform' , { sameNameShorthand : 'never' } ]
88+ } ,
89+ {
90+ // camel case
91+ filename : 'test.vue' ,
92+ code : '<template><div :foo-bar="fooBar" /></template>' ,
93+ options : [ 'shorthand' , { sameNameShorthand : 'never' } ]
94+ } ,
95+ // same-name shorthand: always
96+ {
97+ filename : 'test.vue' ,
98+ code : '<template><div :foo /></template>' ,
99+ options : [ 'shorthand' , { sameNameShorthand : 'always' } ]
100+ } ,
101+ {
102+ filename : 'test.vue' ,
103+ code : '<template><div v-bind:foo /></template>' ,
104+ options : [ 'longform' , { sameNameShorthand : 'always' } ]
105+ } ,
106+ {
107+ // modifier
108+ filename : 'test.vue' ,
109+ code : `
110+ <template>
111+ <div :foo.prop />
112+ <div .foo />
113+ </template>
114+ ` ,
115+ options : [ 'shorthand' , { sameNameShorthand : 'always' } ]
116+ } ,
117+ {
118+ filename : 'test.vue' ,
119+ code : '<template><div v-bind:foo.prop /></template>' ,
120+ options : [ 'longform' , { sameNameShorthand : 'always' } ]
121+ } ,
122+ {
123+ // camel case
124+ filename : 'test.vue' ,
125+ code : '<template><div :foo-bar/></template>' ,
126+ options : [ 'shorthand' , { sameNameShorthand : 'always' } ]
58127 }
59128 ] ,
60129 invalid : [
@@ -120,6 +189,89 @@ tester.run('v-bind-style', rule, {
120189 output : '<template><div v-bind:foo /></template>' ,
121190 options : [ 'longform' ] ,
122191 errors : [ "Expected 'v-bind' before ':'." ]
192+ } ,
193+ // same-name shorthand: never
194+ {
195+ filename : 'test.vue' ,
196+ code : '<template><div :foo /></template>' ,
197+ output : '<template><div :foo="foo" /></template>' ,
198+ options : [ 'shorthand' , { sameNameShorthand : 'never' } ] ,
199+ errors : [ unexpectedShorthand ]
200+ } ,
201+ {
202+ filename : 'test.vue' ,
203+ code : '<template><div v-bind:foo /></template>' ,
204+ output : '<template><div v-bind:foo="foo" /></template>' ,
205+ options : [ 'longform' , { sameNameShorthand : 'never' } ] ,
206+ errors : [ unexpectedShorthand ]
207+ } ,
208+ {
209+ // modifier
210+ filename : 'test.vue' ,
211+ code : '<template><div :foo.prop /></template>' ,
212+ output : '<template><div :foo.prop="foo" /></template>' ,
213+ options : [ 'shorthand' , { sameNameShorthand : 'never' } ] ,
214+ errors : [ unexpectedShorthand ]
215+ } ,
216+ {
217+ filename : 'test.vue' ,
218+ code : '<template><div .foo /></template>' ,
219+ output : '<template><div .foo="foo" /></template>' ,
220+ options : [ 'shorthand' , { sameNameShorthand : 'never' } ] ,
221+ errors : [ unexpectedShorthand ]
222+ } ,
223+ {
224+ filename : 'test.vue' ,
225+ code : '<template><div .foo /></template>' ,
226+ output : '<template><div v-bind:foo.prop /></template>' ,
227+ options : [ 'longform' , { sameNameShorthand : 'never' } ] ,
228+ errors : [ unexpectedShorthand , "Expected 'v-bind:' instead of '.'." ]
229+ } ,
230+ {
231+ // camel case
232+ filename : 'test.vue' ,
233+ code : '<template><div :foo-bar /></template>' ,
234+ output : '<template><div :foo-bar="fooBar" /></template>' ,
235+ options : [ 'shorthand' , { sameNameShorthand : 'never' } ] ,
236+ errors : [ unexpectedShorthand ]
237+ } ,
238+ // same-name shorthand: always
239+ {
240+ filename : 'test.vue' ,
241+ code : '<template><div :foo="foo" /></template>' ,
242+ output : '<template><div :foo /></template>' ,
243+ options : [ 'shorthand' , { sameNameShorthand : 'always' } ] ,
244+ errors : [ expectedShorthand ]
245+ } ,
246+ {
247+ filename : 'test.vue' ,
248+ code : '<template><div v-bind:foo="foo" /></template>' ,
249+ output : '<template><div v-bind:foo /></template>' ,
250+ options : [ 'longform' , { sameNameShorthand : 'always' } ] ,
251+ errors : [ expectedShorthand ]
252+ } ,
253+ {
254+ // modifier
255+ filename : 'test.vue' ,
256+ code : '<template><div :foo.prop="foo" /></template>' ,
257+ output : '<template><div :foo.prop /></template>' ,
258+ options : [ 'shorthand' , { sameNameShorthand : 'always' } ] ,
259+ errors : [ expectedShorthand ]
260+ } ,
261+ {
262+ filename : 'test.vue' ,
263+ code : '<template><div .foo="foo" /></template>' ,
264+ output : '<template><div .foo /></template>' ,
265+ options : [ 'shorthand' , { sameNameShorthand : 'always' } ] ,
266+ errors : [ expectedShorthand ]
267+ } ,
268+ {
269+ // camel case
270+ filename : 'test.vue' ,
271+ code : '<template><div :foo-bar="fooBar" /></template>' ,
272+ output : '<template><div :foo-bar /></template>' ,
273+ options : [ 'shorthand' , { sameNameShorthand : 'always' } ] ,
274+ errors : [ expectedShorthand ]
123275 }
124276 ]
125277} )
0 commit comments