Skip to content

Commit

Permalink
Modify test ofvue/v-on-handler-style (vuejs#2538)
Browse files Browse the repository at this point in the history
  • Loading branch information
heggria committed Aug 30, 2024
1 parent d166023 commit 6498a89
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 54 deletions.
2 changes: 1 addition & 1 deletion lib/rules/v-on-handler-style.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ module.exports = {
}
const paramCount = methodParamCountMap.get(idCallExpr.callee.name)
// disable the auto-fixed when the node does't have params
if (paramCount == 0) {
if (idCallExpr.arguments.length === 0 || paramCount === 0) {
return null
}
if (paramCount != null && paramCount > 0) {
Expand Down
65 changes: 12 additions & 53 deletions tests/lib/rules/v-on-handler-style.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,7 @@ tester.run('v-on-handler-style', rule, {
<button @click="foo()" />
<button @click="() => foo()" />
</template>`,
output: `<template>
<button @click="foo" />
<button @click="foo" />
<button @click="foo" />
</template>`,
output: null,
options: [['method', 'inline-function']],
errors: [
{
Expand All @@ -107,11 +103,7 @@ tester.run('v-on-handler-style', rule, {
<button @click="foo()" />
<button @click="() => foo()" />
</template>`,
output: `<template>
<button @click="foo" />
<button @click="foo" />
<button @click="foo" />
</template>`,
output: null,
errors: [
{
message: 'Prefer method handler over inline handler in v-on.',
Expand Down Expand Up @@ -181,7 +173,7 @@ tester.run('v-on-handler-style', rule, {
{
filename: 'test.vue',
code: '<template><div @click="foo( )" /></template>',
output: `<template><div @click="foo" /></template>`,
output: null,
options: [['method', 'inline-function']],
errors: [
{
Expand Down Expand Up @@ -266,13 +258,7 @@ tester.run('v-on-handler-style', rule, {
<button @click="{ fn(); }" />
<button @click="{(fn());;;}" />
</template>`,
output: `
<template>
<button @click="fn" />
<button @click="fn" />
<button @click="fn" />
<button @click="fn" />
</template>`,
output: null,
options: [['method', 'inline-function']],
errors: [
{
Expand Down Expand Up @@ -304,11 +290,7 @@ tester.run('v-on-handler-style', rule, {
<div @click=" beforeSpace()" />
<div @click='afterSpace() ' />
</template>`,
output: `
<template>
<div @click="beforeSpace" />
<div @click='afterSpace' />
</template>`,
output: null,
options: [['method', 'inline-function']],
errors: [
{
Expand All @@ -329,10 +311,7 @@ tester.run('v-on-handler-style', rule, {
<template>
<button @click=" &#x66;oo ( ) " />
</template>`,
output: `
<template>
<button @click="&#x66;oo" />
</template>`,
output: null,
options: [['method', 'inline-function']],
errors: [
{
Expand All @@ -353,15 +332,7 @@ tester.run('v-on-handler-style', rule, {
}
}
</script>`,
output: `
<template><button @click="foo" /></template>
<script>
export default {
methods: {
foo() {}
}
}
</script>`,
output: null,
options: [['method', 'inline-function']],
errors: [
{
Expand All @@ -382,15 +353,7 @@ tester.run('v-on-handler-style', rule, {
}
}
</script>`,
output: `
<template><button @click="foo" /></template>
<script>
export default {
methods: {
foo: () => {}
}
}
</script>`,
output: null,
options: [['method', 'inline-function']],
errors: [
{
Expand Down Expand Up @@ -545,11 +508,7 @@ tester.run('v-on-handler-style', rule, {
<button @click="e()" />
</template>
</template>`,
output: `<template>
<template v-for="e in list">
<button @click="e" />
</template>
</template>`,
output: null,
options: [['method', 'inline-function']],
errors: [
{
Expand Down Expand Up @@ -716,9 +675,9 @@ tester.run('v-on-handler-style', rule, {
<button @click="() => { foo() }" />
</template>`,
output: `<template>
<button @click="() => foo()" />
<button @click="foo" />
<button @click="foo" />
<button @click="foo" />
<button @click="() => { foo() }" />
</template>`,
options: [['method', 'inline']],
errors: [
Expand Down Expand Up @@ -1008,7 +967,7 @@ tester.run('v-on-handler-style', rule, {
</template>`,
output: `<template>
<template v-for="e in list">
<button @click="e" />
<button @click="() => e()" />
<button @click="e" />
<button @click="e" />
</template>
Expand Down

0 comments on commit 6498a89

Please sign in to comment.