|
| 1 | +/** |
| 2 | + * @author Yosuke Ota |
| 3 | + */ |
| 4 | +'use strict' |
| 5 | + |
| 6 | +const RuleTester = require('eslint').RuleTester |
| 7 | +const rule = require('../../../lib/rules/prefer-template') |
| 8 | + |
| 9 | +const tester = new RuleTester({ |
| 10 | + parser: require.resolve('vue-eslint-parser'), |
| 11 | + parserOptions: { ecmaVersion: 2020 } |
| 12 | +}) |
| 13 | + |
| 14 | +tester.run('prefer-template', rule, { |
| 15 | + valid: [ |
| 16 | + ` |
| 17 | + <template> |
| 18 | + <div :class="[\`foo-\${bar}\`]" /> |
| 19 | + </template> |
| 20 | + `, |
| 21 | + ` |
| 22 | + <template> |
| 23 | + <div :[\`foo\${bar}\`]="value" /> |
| 24 | + </template> |
| 25 | + ` |
| 26 | + ], |
| 27 | + invalid: [ |
| 28 | + { |
| 29 | + code: ` |
| 30 | + <template> |
| 31 | + <div :class="['foo-' + bar]" /> |
| 32 | + </template> |
| 33 | + `, |
| 34 | + output: ` |
| 35 | + <template> |
| 36 | + <div :class="[\`foo-\${ bar}\`]" /> |
| 37 | + </template> |
| 38 | + `, |
| 39 | + errors: [ |
| 40 | + { |
| 41 | + message: 'Unexpected string concatenation.', |
| 42 | + line: 3 |
| 43 | + } |
| 44 | + ] |
| 45 | + }, |
| 46 | + { |
| 47 | + code: ` |
| 48 | + <template> |
| 49 | + <div :['foo'+bar]="value" /> |
| 50 | + </template>`, |
| 51 | + output: ` |
| 52 | + <template> |
| 53 | + <div :[\`foo\${bar}\`]="value" /> |
| 54 | + </template>`, |
| 55 | + errors: [ |
| 56 | + { |
| 57 | + message: 'Unexpected string concatenation.', |
| 58 | + line: 3 |
| 59 | + } |
| 60 | + ] |
| 61 | + } |
| 62 | + ] |
| 63 | +}) |
0 commit comments