|
| 1 | +/** |
| 2 | + * @author alshyra |
| 3 | + * See LICENSE file in root directory for full license. |
| 4 | + */ |
| 5 | +'use strict' |
| 6 | + |
| 7 | +const RuleTester = require('eslint').RuleTester |
| 8 | +const rule = require('../../../lib/rules/array-element-newline') |
| 9 | + |
| 10 | +const tester = new RuleTester({ |
| 11 | + parser: require.resolve('vue-eslint-parser'), |
| 12 | + parserOptions: { |
| 13 | + ecmaVersion: 2020, |
| 14 | + sourceType: 'module' |
| 15 | + } |
| 16 | +}) |
| 17 | + |
| 18 | +tester.run('array-element-newline', rule, { |
| 19 | + valid: [ |
| 20 | + '<template><div :attr="[]" /></template>', |
| 21 | + '<template><div :attr="[a]" /></template>', |
| 22 | + ` |
| 23 | + <template> |
| 24 | + <div :attr="[a, |
| 25 | + b, |
| 26 | + c]" /> |
| 27 | + </template>`, |
| 28 | + `<template> |
| 29 | + <div :attr="[a, |
| 30 | + b, |
| 31 | + c |
| 32 | + ]" /> |
| 33 | + </template>`, |
| 34 | + '<template><div :[attr]="a" /></template>', |
| 35 | + '<template><div :[[attr]]="a" /></template>', |
| 36 | + `<template> |
| 37 | + <div :attr="[ |
| 38 | + a, |
| 39 | + b, |
| 40 | + c |
| 41 | + ]" /> |
| 42 | + </template>`, |
| 43 | + ` |
| 44 | + <template> |
| 45 | + <div :attr="[a |
| 46 | + b]" /> |
| 47 | + </template>`, |
| 48 | + { |
| 49 | + code: ` |
| 50 | + <template> |
| 51 | + <div :attr="[a, |
| 52 | + b, |
| 53 | + c]" /> |
| 54 | + </template>`, |
| 55 | + options: ['always'] |
| 56 | + }, |
| 57 | + { |
| 58 | + code: '<template><div :attr="[a]" /></template>', |
| 59 | + options: ['never'] |
| 60 | + }, |
| 61 | + { |
| 62 | + code: '<template><div :attr="[a,b,c]" /></template>', |
| 63 | + options: ['never'] |
| 64 | + }, |
| 65 | + { |
| 66 | + code: '<template><div :attr="[a, b, c]" /></template>', |
| 67 | + options: [{ multiline: true }] |
| 68 | + }, |
| 69 | + { |
| 70 | + code: ` |
| 71 | + <template> |
| 72 | + <div :attr="[a, |
| 73 | + { |
| 74 | + b:c |
| 75 | + }]" /> |
| 76 | + </template>`, |
| 77 | + options: [{ multiline: true }] |
| 78 | + }, |
| 79 | + { |
| 80 | + code: '<template><div :attr="[a, b, c]" /></template>', |
| 81 | + options: ['consistent'] |
| 82 | + }, |
| 83 | + { |
| 84 | + code: ` |
| 85 | + <template> |
| 86 | + <div :attr="[a, |
| 87 | + b, |
| 88 | + c |
| 89 | + ]" /> |
| 90 | + </template>`, |
| 91 | + options: ['consistent'] |
| 92 | + }, |
| 93 | + { |
| 94 | + code: '<template><div :attr="[a,b]" /></template>', |
| 95 | + options: [{ minItems: 3 }] |
| 96 | + } |
| 97 | + ], |
| 98 | + invalid: [ |
| 99 | + { |
| 100 | + code: ` |
| 101 | + <template> |
| 102 | + <div :attr="[a, b]" /> |
| 103 | + </template>`, |
| 104 | + output: ` |
| 105 | + <template> |
| 106 | + <div :attr="[a, |
| 107 | +b]" /> |
| 108 | + </template>`, |
| 109 | + errors: [ |
| 110 | + { |
| 111 | + message: 'There should be a linebreak after this element.', |
| 112 | + line: 3, |
| 113 | + column: 26, |
| 114 | + endLine: 3, |
| 115 | + endColumn: 27 |
| 116 | + } |
| 117 | + ] |
| 118 | + }, |
| 119 | + { |
| 120 | + code: ` |
| 121 | + <template> |
| 122 | + <div :attr="[a,b,c]" /> |
| 123 | + </template>`, |
| 124 | + output: ` |
| 125 | + <template> |
| 126 | + <div :attr="[a, |
| 127 | +b, |
| 128 | +c]" /> |
| 129 | + </template>`, |
| 130 | + options: ['always'], |
| 131 | + errors: [ |
| 132 | + { |
| 133 | + message: 'There should be a linebreak after this element.', |
| 134 | + line: 3, |
| 135 | + column: 26, |
| 136 | + endLine: 3, |
| 137 | + endColumn: 26 |
| 138 | + }, |
| 139 | + { |
| 140 | + message: 'There should be a linebreak after this element.', |
| 141 | + line: 3, |
| 142 | + column: 28, |
| 143 | + endLine: 3, |
| 144 | + endColumn: 28 |
| 145 | + } |
| 146 | + ] |
| 147 | + }, |
| 148 | + { |
| 149 | + code: ` |
| 150 | + <template> |
| 151 | + <div :attr="[a, |
| 152 | + b,c]" /> |
| 153 | + </template>`, |
| 154 | + output: ` |
| 155 | + <template> |
| 156 | + <div :attr="[a, |
| 157 | + b, |
| 158 | +c]" /> |
| 159 | + </template>`, |
| 160 | + options: ['always'], |
| 161 | + errors: [ |
| 162 | + { |
| 163 | + message: 'There should be a linebreak after this element.', |
| 164 | + line: 4, |
| 165 | + column: 25, |
| 166 | + endLine: 4, |
| 167 | + endColumn: 25 |
| 168 | + } |
| 169 | + ] |
| 170 | + }, |
| 171 | + { |
| 172 | + code: ` |
| 173 | + <template> |
| 174 | + <div :attr="[a, |
| 175 | + b,c]" /> |
| 176 | + </template>`, |
| 177 | + output: ` |
| 178 | + <template> |
| 179 | + <div :attr="[a, |
| 180 | + b, |
| 181 | +c]" /> |
| 182 | + </template>`, |
| 183 | + options: ['consistent'], |
| 184 | + errors: [ |
| 185 | + { |
| 186 | + message: 'There should be a linebreak after this element.', |
| 187 | + line: 4, |
| 188 | + column: 26, |
| 189 | + endLine: 4, |
| 190 | + endColumn: 26 |
| 191 | + } |
| 192 | + ] |
| 193 | + }, |
| 194 | + { |
| 195 | + code: ` |
| 196 | + <template> |
| 197 | + <div :attr="[a, |
| 198 | + b, c]" /> |
| 199 | + </template>`, |
| 200 | + output: ` |
| 201 | + <template> |
| 202 | + <div :attr="[a, b, c]" /> |
| 203 | + </template>`, |
| 204 | + options: [{ multiline: true }], |
| 205 | + errors: [ |
| 206 | + { |
| 207 | + message: 'There should be no linebreak here.', |
| 208 | + line: 3, |
| 209 | + column: 26, |
| 210 | + endLine: 4, |
| 211 | + endColumn: 24 |
| 212 | + } |
| 213 | + ] |
| 214 | + }, |
| 215 | + { |
| 216 | + code: ` |
| 217 | + <template> |
| 218 | + <div :attr="[a, { |
| 219 | + b:c |
| 220 | + }]" /> |
| 221 | + </template>`, |
| 222 | + output: ` |
| 223 | + <template> |
| 224 | + <div :attr="[a, |
| 225 | +{ |
| 226 | + b:c |
| 227 | + }]" /> |
| 228 | + </template>`, |
| 229 | + options: [{ multiline: true }], |
| 230 | + errors: [ |
| 231 | + { |
| 232 | + message: 'There should be a linebreak after this element.', |
| 233 | + line: 3, |
| 234 | + column: 26, |
| 235 | + endLine: 3, |
| 236 | + endColumn: 27 |
| 237 | + } |
| 238 | + ] |
| 239 | + }, |
| 240 | + { |
| 241 | + code: ` |
| 242 | + <template> |
| 243 | + <div :attr="[a,b,c]" /> |
| 244 | + </template>`, |
| 245 | + output: ` |
| 246 | + <template> |
| 247 | + <div :attr="[a, |
| 248 | +b, |
| 249 | +c]" /> |
| 250 | + </template>`, |
| 251 | + options: [{ minItems: 2 }], |
| 252 | + errors: [ |
| 253 | + { |
| 254 | + message: 'There should be a linebreak after this element.', |
| 255 | + line: 3, |
| 256 | + column: 26, |
| 257 | + endLine: 3, |
| 258 | + endColumn: 26 |
| 259 | + }, |
| 260 | + { |
| 261 | + message: 'There should be a linebreak after this element.', |
| 262 | + line: 3, |
| 263 | + column: 28, |
| 264 | + endLine: 3, |
| 265 | + endColumn: 28 |
| 266 | + } |
| 267 | + ] |
| 268 | + } |
| 269 | + ] |
| 270 | +}) |
0 commit comments