|
| 1 | +/** |
| 2 | + * @fileoverview enforce unified spacing in mustache interpolations. |
| 3 | + * @author Armano |
| 4 | + */ |
| 5 | +'use strict' |
| 6 | + |
| 7 | +// ------------------------------------------------------------------------------ |
| 8 | +// Requirements |
| 9 | +// ------------------------------------------------------------------------------ |
| 10 | + |
| 11 | +const rule = require('../../../lib/rules/mustache-interpolation-spacing') |
| 12 | +const RuleTester = require('eslint').RuleTester |
| 13 | + |
| 14 | +// ------------------------------------------------------------------------------ |
| 15 | +// Tests |
| 16 | +// ------------------------------------------------------------------------------ |
| 17 | + |
| 18 | +const ruleTester = new RuleTester({ |
| 19 | + parser: 'vue-eslint-parser', |
| 20 | + parserOptions: { ecmaVersion: 2015 } |
| 21 | +}) |
| 22 | + |
| 23 | +ruleTester.run('mustache-interpolation-spacing', rule, { |
| 24 | + |
| 25 | + valid: [ |
| 26 | + { |
| 27 | + filename: 'test.vue', |
| 28 | + code: '<template></template>' |
| 29 | + }, |
| 30 | + { |
| 31 | + filename: 'test.vue', |
| 32 | + code: '<template><div></div></template>' |
| 33 | + }, |
| 34 | + { |
| 35 | + filename: 'test.vue', |
| 36 | + code: '<template> <div id=" "></div> </template>' |
| 37 | + }, |
| 38 | + { |
| 39 | + filename: 'test.vue', |
| 40 | + code: '<template> <div :style=" " :class=" foo " v-if=foo ></div> </template>' |
| 41 | + }, |
| 42 | + { |
| 43 | + filename: 'test.vue', |
| 44 | + code: '<template><div>{{ text }}</div></template>' |
| 45 | + }, |
| 46 | + { |
| 47 | + filename: 'test.vue', |
| 48 | + code: '<template><div>{{ }}</div></template>' |
| 49 | + }, |
| 50 | + { |
| 51 | + filename: 'test.vue', |
| 52 | + code: '<template><div>{{ }}</div></template>', |
| 53 | + options: ['always'] |
| 54 | + }, |
| 55 | + { |
| 56 | + filename: 'test.vue', |
| 57 | + code: '<template><div>{{}}</div></template>', |
| 58 | + options: ['never'] |
| 59 | + }, |
| 60 | + { |
| 61 | + filename: 'test.vue', |
| 62 | + code: '<template><div>{{text}}</div></template>', |
| 63 | + options: ['never'] |
| 64 | + }, |
| 65 | + { |
| 66 | + filename: 'test.vue', |
| 67 | + code: '<template><div>{{ text }}</div></template>', |
| 68 | + options: ['always'] |
| 69 | + }, |
| 70 | + { |
| 71 | + filename: 'test.vue', |
| 72 | + code: '<template><div>{{ }}</div></template>', |
| 73 | + options: ['always'] |
| 74 | + }, |
| 75 | + { |
| 76 | + filename: 'test.vue', |
| 77 | + code: '<template><div>{{ }}</div></template>', |
| 78 | + options: ['never'] |
| 79 | + }, |
| 80 | + { |
| 81 | + filename: 'test.vue', |
| 82 | + code: '<template><div>{{ text }}</div></template>', |
| 83 | + options: ['always'] |
| 84 | + } |
| 85 | + ], |
| 86 | + |
| 87 | + invalid: [ |
| 88 | + { |
| 89 | + filename: 'test.vue', |
| 90 | + code: '<template><div>{{ text}}</div></template>', |
| 91 | + output: '<template><div>{{ text }}</div></template>', |
| 92 | + options: ['always'], |
| 93 | + errors: [{ |
| 94 | + message: 'Found none whitespaces, 1 expected.', |
| 95 | + type: 'VExpressionEnd' |
| 96 | + }] |
| 97 | + }, |
| 98 | + { |
| 99 | + filename: 'test.vue', |
| 100 | + code: '<template><div>{{text }}</div></template>', |
| 101 | + output: '<template><div>{{ text }}</div></template>', |
| 102 | + options: ['always'], |
| 103 | + errors: [{ |
| 104 | + message: 'Found none whitespaces, 1 expected.', |
| 105 | + type: 'Identifier' |
| 106 | + }] |
| 107 | + }, |
| 108 | + { |
| 109 | + filename: 'test.vue', |
| 110 | + code: '<template><div>{{ text}}</div></template>', |
| 111 | + output: '<template><div>{{text}}</div></template>', |
| 112 | + options: ['never'], |
| 113 | + errors: [{ |
| 114 | + message: 'Found 1 whitespaces, none expected.', |
| 115 | + type: 'Identifier' |
| 116 | + }] |
| 117 | + }, |
| 118 | + { |
| 119 | + filename: 'test.vue', |
| 120 | + code: '<template><div>{{text }}</div></template>', |
| 121 | + output: '<template><div>{{text}}</div></template>', |
| 122 | + options: ['never'], |
| 123 | + errors: [{ |
| 124 | + message: 'Found 1 whitespaces, none expected.', |
| 125 | + type: 'VExpressionEnd' |
| 126 | + }] |
| 127 | + }, |
| 128 | + { |
| 129 | + filename: 'test.vue', |
| 130 | + code: '<template><div>{{text}}</div></template>', |
| 131 | + output: '<template><div>{{ text }}</div></template>', |
| 132 | + options: ['always'], |
| 133 | + errors: [{ |
| 134 | + message: 'Found none whitespaces, 1 expected.', |
| 135 | + type: 'Identifier' |
| 136 | + }, { |
| 137 | + message: 'Found none whitespaces, 1 expected.', |
| 138 | + type: 'VExpressionEnd' |
| 139 | + }] |
| 140 | + }, |
| 141 | + { |
| 142 | + filename: 'test.vue', |
| 143 | + code: '<template><div>{{ text }}</div></template>', |
| 144 | + output: '<template><div>{{text}}</div></template>', |
| 145 | + options: ['never'], |
| 146 | + errors: [{ |
| 147 | + message: 'Found 1 whitespaces, none expected.', |
| 148 | + type: 'Identifier' |
| 149 | + }, { |
| 150 | + message: 'Found 1 whitespaces, none expected.', |
| 151 | + type: 'VExpressionEnd' |
| 152 | + }] |
| 153 | + }, |
| 154 | + { |
| 155 | + filename: 'test.vue', |
| 156 | + code: '<template><div>{{ text }}</div></template>', |
| 157 | + output: '<template><div>{{text}}</div></template>', |
| 158 | + options: ['never'], |
| 159 | + errors: [{ |
| 160 | + message: 'Found 3 whitespaces, none expected.', |
| 161 | + type: 'Identifier' |
| 162 | + }, { |
| 163 | + message: 'Found 3 whitespaces, none expected.', |
| 164 | + type: 'VExpressionEnd' |
| 165 | + }] |
| 166 | + } |
| 167 | + ] |
| 168 | +}) |
0 commit comments