Skip to content

Commit 6498a89

Browse files
committed
Modify test ofvue/v-on-handler-style (vuejs#2538)
1 parent d166023 commit 6498a89

File tree

2 files changed

+13
-54
lines changed

2 files changed

+13
-54
lines changed

lib/rules/v-on-handler-style.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ module.exports = {
315315
}
316316
const paramCount = methodParamCountMap.get(idCallExpr.callee.name)
317317
// disable the auto-fixed when the node does't have params
318-
if (paramCount == 0) {
318+
if (idCallExpr.arguments.length === 0 || paramCount === 0) {
319319
return null
320320
}
321321
if (paramCount != null && paramCount > 0) {

tests/lib/rules/v-on-handler-style.js

+12-53
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,7 @@ tester.run('v-on-handler-style', rule, {
8181
<button @click="foo()" />
8282
<button @click="() => foo()" />
8383
</template>`,
84-
output: `<template>
85-
<button @click="foo" />
86-
<button @click="foo" />
87-
<button @click="foo" />
88-
</template>`,
84+
output: null,
8985
options: [['method', 'inline-function']],
9086
errors: [
9187
{
@@ -107,11 +103,7 @@ tester.run('v-on-handler-style', rule, {
107103
<button @click="foo()" />
108104
<button @click="() => foo()" />
109105
</template>`,
110-
output: `<template>
111-
<button @click="foo" />
112-
<button @click="foo" />
113-
<button @click="foo" />
114-
</template>`,
106+
output: null,
115107
errors: [
116108
{
117109
message: 'Prefer method handler over inline handler in v-on.',
@@ -181,7 +173,7 @@ tester.run('v-on-handler-style', rule, {
181173
{
182174
filename: 'test.vue',
183175
code: '<template><div @click="foo( )" /></template>',
184-
output: `<template><div @click="foo" /></template>`,
176+
output: null,
185177
options: [['method', 'inline-function']],
186178
errors: [
187179
{
@@ -266,13 +258,7 @@ tester.run('v-on-handler-style', rule, {
266258
<button @click="{ fn(); }" />
267259
<button @click="{(fn());;;}" />
268260
</template>`,
269-
output: `
270-
<template>
271-
<button @click="fn" />
272-
<button @click="fn" />
273-
<button @click="fn" />
274-
<button @click="fn" />
275-
</template>`,
261+
output: null,
276262
options: [['method', 'inline-function']],
277263
errors: [
278264
{
@@ -304,11 +290,7 @@ tester.run('v-on-handler-style', rule, {
304290
<div @click=" beforeSpace()" />
305291
<div @click='afterSpace() ' />
306292
</template>`,
307-
output: `
308-
<template>
309-
<div @click="beforeSpace" />
310-
<div @click='afterSpace' />
311-
</template>`,
293+
output: null,
312294
options: [['method', 'inline-function']],
313295
errors: [
314296
{
@@ -329,10 +311,7 @@ tester.run('v-on-handler-style', rule, {
329311
<template>
330312
<button @click=" &#x66;oo ( ) " />
331313
</template>`,
332-
output: `
333-
<template>
334-
<button @click="&#x66;oo" />
335-
</template>`,
314+
output: null,
336315
options: [['method', 'inline-function']],
337316
errors: [
338317
{
@@ -353,15 +332,7 @@ tester.run('v-on-handler-style', rule, {
353332
}
354333
}
355334
</script>`,
356-
output: `
357-
<template><button @click="foo" /></template>
358-
<script>
359-
export default {
360-
methods: {
361-
foo() {}
362-
}
363-
}
364-
</script>`,
335+
output: null,
365336
options: [['method', 'inline-function']],
366337
errors: [
367338
{
@@ -382,15 +353,7 @@ tester.run('v-on-handler-style', rule, {
382353
}
383354
}
384355
</script>`,
385-
output: `
386-
<template><button @click="foo" /></template>
387-
<script>
388-
export default {
389-
methods: {
390-
foo: () => {}
391-
}
392-
}
393-
</script>`,
356+
output: null,
394357
options: [['method', 'inline-function']],
395358
errors: [
396359
{
@@ -545,11 +508,7 @@ tester.run('v-on-handler-style', rule, {
545508
<button @click="e()" />
546509
</template>
547510
</template>`,
548-
output: `<template>
549-
<template v-for="e in list">
550-
<button @click="e" />
551-
</template>
552-
</template>`,
511+
output: null,
553512
options: [['method', 'inline-function']],
554513
errors: [
555514
{
@@ -716,9 +675,9 @@ tester.run('v-on-handler-style', rule, {
716675
<button @click="() => { foo() }" />
717676
</template>`,
718677
output: `<template>
678+
<button @click="() => foo()" />
719679
<button @click="foo" />
720-
<button @click="foo" />
721-
<button @click="foo" />
680+
<button @click="() => { foo() }" />
722681
</template>`,
723682
options: [['method', 'inline']],
724683
errors: [
@@ -1008,7 +967,7 @@ tester.run('v-on-handler-style', rule, {
1008967
</template>`,
1009968
output: `<template>
1010969
<template v-for="e in list">
1011-
<button @click="e" />
970+
<button @click="() => e()" />
1012971
<button @click="e" />
1013972
<button @click="e" />
1014973
</template>

0 commit comments

Comments
 (0)