|
| 1 | +/** |
| 2 | + * @author Yosuke Ota |
| 3 | + */ |
| 4 | +'use strict' |
| 5 | + |
| 6 | +const RuleTester = require('eslint').RuleTester |
| 7 | +const rule = require('../../../lib/rules/comma-dangle') |
| 8 | + |
| 9 | +const tester = new RuleTester({ |
| 10 | + parser: 'vue-eslint-parser', |
| 11 | + parserOptions: { ecmaVersion: 2018 } |
| 12 | +}) |
| 13 | + |
| 14 | +tester.run('comma-dangle', rule, { |
| 15 | + valid: [ |
| 16 | + `<template> |
| 17 | + <button @click="() => fn([a, b])" ></button> |
| 18 | + </template>`, |
| 19 | + { |
| 20 | + code: ` |
| 21 | + <template> |
| 22 | + <CustomButton @click="($event) => fn()" /> |
| 23 | + </template>`, |
| 24 | + options: [{ |
| 25 | + 'functions': 'never' |
| 26 | + }] |
| 27 | + }, |
| 28 | + { |
| 29 | + code: ` |
| 30 | + <template> |
| 31 | + <button @click="() => fn([a, b, ])" ></button> |
| 32 | + </template>`, |
| 33 | + options: [{ |
| 34 | + 'arrays': 'ignore' |
| 35 | + }] |
| 36 | + } |
| 37 | + ], |
| 38 | + invalid: [ |
| 39 | + { |
| 40 | + code: ` |
| 41 | + <template> |
| 42 | + <button @click="() => fn([a, b,])" ></button> |
| 43 | + </template>`, |
| 44 | + output: ` |
| 45 | + <template> |
| 46 | + <button @click="() => fn([a, b])" ></button> |
| 47 | + </template>`, |
| 48 | + errors: [ |
| 49 | + { |
| 50 | + message: 'Unexpected trailing comma.', |
| 51 | + line: 3 |
| 52 | + } |
| 53 | + ] |
| 54 | + }, |
| 55 | + { |
| 56 | + code: ` |
| 57 | + <template> |
| 58 | + <CustomButton @click="($event, ) => fn()" /> |
| 59 | + </template>`, |
| 60 | + options: [{ |
| 61 | + 'functions': 'never' |
| 62 | + }], |
| 63 | + output: ` |
| 64 | + <template> |
| 65 | + <CustomButton @click="($event ) => fn()" /> |
| 66 | + </template>`, |
| 67 | + errors: [ |
| 68 | + { |
| 69 | + message: 'Unexpected trailing comma.', |
| 70 | + line: 3 |
| 71 | + } |
| 72 | + ] |
| 73 | + }, |
| 74 | + { |
| 75 | + code: ` |
| 76 | + <template> |
| 77 | + <button @click="() => { |
| 78 | + fn([a, b, ]) |
| 79 | + fn([ |
| 80 | + a, |
| 81 | + b |
| 82 | + ]) |
| 83 | + }"></button> |
| 84 | + </template>`, |
| 85 | + options: ['always-multiline'], |
| 86 | + output: ` |
| 87 | + <template> |
| 88 | + <button @click="() => { |
| 89 | + fn([a, b ]) |
| 90 | + fn([ |
| 91 | + a, |
| 92 | + b, |
| 93 | + ]) |
| 94 | + }"></button> |
| 95 | + </template>`, |
| 96 | + errors: [ |
| 97 | + { |
| 98 | + message: 'Unexpected trailing comma.', |
| 99 | + line: 4 |
| 100 | + }, |
| 101 | + { |
| 102 | + message: 'Missing trailing comma.', |
| 103 | + line: 7 |
| 104 | + } |
| 105 | + ] |
| 106 | + } |
| 107 | + ] |
| 108 | +}) |
0 commit comments