|
| 1 | +/** |
| 2 | + * @author Yosuke Ota |
| 3 | + */ |
| 4 | +'use strict' |
| 5 | + |
| 6 | +const RuleTester = require('eslint').RuleTester |
| 7 | +const rule = require('../../../lib/rules/operator-linebreak') |
| 8 | + |
| 9 | +const tester = new RuleTester({ |
| 10 | + parser: require.resolve('vue-eslint-parser'), |
| 11 | + parserOptions: { ecmaVersion: 2020 } |
| 12 | +}) |
| 13 | + |
| 14 | +tester.run('operator-linebreak', rule, { |
| 15 | + valid: [ |
| 16 | + ` |
| 17 | + <template> |
| 18 | + <div :foo="1 + 2" /> |
| 19 | + </template> |
| 20 | + `, |
| 21 | + { |
| 22 | + code: ` |
| 23 | + <template> |
| 24 | + <div :foo="1 + 2" /> |
| 25 | + </template> |
| 26 | + `, |
| 27 | + options: ['before'] |
| 28 | + }, |
| 29 | + { |
| 30 | + code: ` |
| 31 | + <template> |
| 32 | + <div :foo="1 + 2" /> |
| 33 | + </template> |
| 34 | + `, |
| 35 | + options: ['none'] |
| 36 | + }, |
| 37 | + ` |
| 38 | + <template> |
| 39 | + <div :[foo+bar]="value" /> |
| 40 | + </template> |
| 41 | + `, |
| 42 | + { |
| 43 | + code: ` |
| 44 | + <template> |
| 45 | + <div :[foo+bar]="value" /> |
| 46 | + </template> |
| 47 | + `, |
| 48 | + options: ['before'] |
| 49 | + }, |
| 50 | + { |
| 51 | + code: ` |
| 52 | + <template> |
| 53 | + <div :[foo+bar]="value" /> |
| 54 | + </template> |
| 55 | + `, |
| 56 | + options: ['none'] |
| 57 | + } |
| 58 | + ], |
| 59 | + invalid: [ |
| 60 | + { |
| 61 | + code: ` |
| 62 | + <template> |
| 63 | + <div :foo="1 |
| 64 | + + 2" /> |
| 65 | + </template> |
| 66 | + `, |
| 67 | + output: ` |
| 68 | + <template> |
| 69 | + <div :foo="1 + |
| 70 | + 2" /> |
| 71 | + </template> |
| 72 | + `, |
| 73 | + errors: [ |
| 74 | + { |
| 75 | + message: "'+' should be placed at the end of the line.", |
| 76 | + line: 4 |
| 77 | + } |
| 78 | + ] |
| 79 | + }, |
| 80 | + { |
| 81 | + code: ` |
| 82 | + <template> |
| 83 | + <div :foo="1 + |
| 84 | + 2" /> |
| 85 | + </template> |
| 86 | + `, |
| 87 | + output: ` |
| 88 | + <template> |
| 89 | + <div :foo="1 |
| 90 | + + 2" /> |
| 91 | + </template> |
| 92 | + `, |
| 93 | + options: ['before'], |
| 94 | + errors: [ |
| 95 | + { |
| 96 | + message: "'+' should be placed at the beginning of the line.", |
| 97 | + line: 3 |
| 98 | + } |
| 99 | + ] |
| 100 | + }, |
| 101 | + { |
| 102 | + code: ` |
| 103 | + <template> |
| 104 | + <div :foo="1 + |
| 105 | + 2" /> |
| 106 | + <div :foo="1 |
| 107 | + + 2" /> |
| 108 | + </template> |
| 109 | + `, |
| 110 | + output: ` |
| 111 | + <template> |
| 112 | + <div :foo="1 + 2" /> |
| 113 | + <div :foo="1 + 2" /> |
| 114 | + </template> |
| 115 | + `, |
| 116 | + options: ['none'], |
| 117 | + errors: [ |
| 118 | + { |
| 119 | + message: "There should be no line break before or after '+'.", |
| 120 | + line: 3 |
| 121 | + }, |
| 122 | + { |
| 123 | + message: "There should be no line break before or after '+'.", |
| 124 | + line: 6 |
| 125 | + } |
| 126 | + ] |
| 127 | + } |
| 128 | + ] |
| 129 | +}) |
0 commit comments