|
| 1 | +/** |
| 2 | + * @author Yosuke Ota |
| 3 | + */ |
| 4 | +'use strict' |
| 5 | + |
| 6 | +// ------------------------------------------------------------------------------ |
| 7 | +// Requirements |
| 8 | +// ------------------------------------------------------------------------------ |
| 9 | + |
| 10 | +const rule = require('../../../lib/rules/no-spaces-around-equal-signs-in-attribute') |
| 11 | +const RuleTester = require('eslint').RuleTester |
| 12 | + |
| 13 | +// ------------------------------------------------------------------------------ |
| 14 | +// Tests |
| 15 | +// ------------------------------------------------------------------------------ |
| 16 | + |
| 17 | +const tester = new RuleTester({ |
| 18 | + parser: 'vue-eslint-parser' |
| 19 | +}) |
| 20 | + |
| 21 | +tester.run('no-spaces-around-equal-signs-in-attribute', rule, { |
| 22 | + valid: [ |
| 23 | + '<template><div attr="value" /></template>', |
| 24 | + '<template><div attr="" /></template>', |
| 25 | + '<template><div attr=\'value\' /></template>', |
| 26 | + '<template><div attr=value /></template>', |
| 27 | + '<template><div attr /></template>', |
| 28 | + '<template><div/></template>', |
| 29 | + `<template> |
| 30 | + <div |
| 31 | + is="header" |
| 32 | + v-for="item in items" |
| 33 | + v-if="!visible" |
| 34 | + v-once |
| 35 | + id="uniqueID" |
| 36 | + ref="header" |
| 37 | + v-model="headerData" |
| 38 | + myProp="prop" |
| 39 | + @click="functionCall" |
| 40 | + v-text="textContent"> |
| 41 | + </div> |
| 42 | + </template>` |
| 43 | + ], |
| 44 | + invalid: [ |
| 45 | + { |
| 46 | + code: '<template><div attr = "value" /></template>', |
| 47 | + output: '<template><div attr="value" /></template>', |
| 48 | + errors: [ |
| 49 | + { |
| 50 | + message: 'Unexpected spaces found around equal signs.', |
| 51 | + line: 1, |
| 52 | + column: 20, |
| 53 | + endLine: 1, |
| 54 | + endColumn: 23 |
| 55 | + } |
| 56 | + ] |
| 57 | + }, |
| 58 | + { |
| 59 | + code: '<template><div attr = "" /></template>', |
| 60 | + output: '<template><div attr="" /></template>', |
| 61 | + errors: [ |
| 62 | + { |
| 63 | + message: 'Unexpected spaces found around equal signs.', |
| 64 | + line: 1, |
| 65 | + column: 20, |
| 66 | + endLine: 1, |
| 67 | + endColumn: 23 |
| 68 | + } |
| 69 | + ] |
| 70 | + }, |
| 71 | + { |
| 72 | + code: '<template><div attr = \'value\' /></template>', |
| 73 | + output: '<template><div attr=\'value\' /></template>', |
| 74 | + errors: [ |
| 75 | + { |
| 76 | + message: 'Unexpected spaces found around equal signs.', |
| 77 | + line: 1, |
| 78 | + column: 20, |
| 79 | + endLine: 1, |
| 80 | + endColumn: 23 |
| 81 | + } |
| 82 | + ] |
| 83 | + }, |
| 84 | + { |
| 85 | + code: '<template><div attr = value /></template>', |
| 86 | + output: '<template><div attr=value /></template>', |
| 87 | + errors: [ |
| 88 | + { |
| 89 | + message: 'Unexpected spaces found around equal signs.', |
| 90 | + line: 1, |
| 91 | + column: 20, |
| 92 | + endLine: 1, |
| 93 | + endColumn: 23 |
| 94 | + } |
| 95 | + ] |
| 96 | + }, |
| 97 | + { |
| 98 | + code: '<template><div attr \t\n = \t\n "value" /></template>', |
| 99 | + output: '<template><div attr="value" /></template>', |
| 100 | + errors: [ |
| 101 | + { |
| 102 | + message: 'Unexpected spaces found around equal signs.', |
| 103 | + line: 1, |
| 104 | + column: 20, |
| 105 | + endLine: 3, |
| 106 | + endColumn: 2 |
| 107 | + } |
| 108 | + ] |
| 109 | + }, |
| 110 | + { |
| 111 | + code: '<template><div attr ="value" /></template>', |
| 112 | + output: '<template><div attr="value" /></template>', |
| 113 | + errors: [ |
| 114 | + { |
| 115 | + message: 'Unexpected spaces found around equal signs.', |
| 116 | + line: 1, |
| 117 | + column: 20, |
| 118 | + endLine: 1, |
| 119 | + endColumn: 22 |
| 120 | + } |
| 121 | + ] |
| 122 | + }, |
| 123 | + { |
| 124 | + code: '<template><div attr= "value" /></template>', |
| 125 | + output: '<template><div attr="value" /></template>', |
| 126 | + errors: [ |
| 127 | + { |
| 128 | + message: 'Unexpected spaces found around equal signs.', |
| 129 | + line: 1, |
| 130 | + column: 20, |
| 131 | + endLine: 1, |
| 132 | + endColumn: 22 |
| 133 | + } |
| 134 | + ] |
| 135 | + }, |
| 136 | + { |
| 137 | + code: |
| 138 | + `<template> |
| 139 | + <div |
| 140 | + is = "header" |
| 141 | + v-for = "item in items" |
| 142 | + v-if = "!visible" |
| 143 | + v-once |
| 144 | + id = "uniqueID" |
| 145 | + ref = "header" |
| 146 | + v-model = "headerData" |
| 147 | + myProp = "prop" |
| 148 | + @click = "functionCall" |
| 149 | + v-text = "textContent"> |
| 150 | + </div> |
| 151 | + </template>`, |
| 152 | + output: |
| 153 | + `<template> |
| 154 | + <div |
| 155 | + is="header" |
| 156 | + v-for="item in items" |
| 157 | + v-if="!visible" |
| 158 | + v-once |
| 159 | + id="uniqueID" |
| 160 | + ref="header" |
| 161 | + v-model="headerData" |
| 162 | + myProp="prop" |
| 163 | + @click="functionCall" |
| 164 | + v-text="textContent"> |
| 165 | + </div> |
| 166 | + </template>`, |
| 167 | + errors: [ |
| 168 | + { |
| 169 | + message: 'Unexpected spaces found around equal signs.', |
| 170 | + line: 3, |
| 171 | + column: 15, |
| 172 | + endLine: 3, |
| 173 | + endColumn: 18 |
| 174 | + }, |
| 175 | + { |
| 176 | + message: 'Unexpected spaces found around equal signs.', |
| 177 | + line: 4, |
| 178 | + column: 18, |
| 179 | + endLine: 4, |
| 180 | + endColumn: 21 |
| 181 | + }, |
| 182 | + { |
| 183 | + message: 'Unexpected spaces found around equal signs.', |
| 184 | + line: 5, |
| 185 | + column: 17, |
| 186 | + endLine: 5, |
| 187 | + endColumn: 20 |
| 188 | + }, |
| 189 | + { |
| 190 | + message: 'Unexpected spaces found around equal signs.', |
| 191 | + line: 7, |
| 192 | + column: 15, |
| 193 | + endLine: 7, |
| 194 | + endColumn: 18 |
| 195 | + }, |
| 196 | + { |
| 197 | + message: 'Unexpected spaces found around equal signs.', |
| 198 | + line: 8, |
| 199 | + column: 16, |
| 200 | + endLine: 8, |
| 201 | + endColumn: 19 |
| 202 | + }, |
| 203 | + { |
| 204 | + message: 'Unexpected spaces found around equal signs.', |
| 205 | + line: 9, |
| 206 | + column: 20, |
| 207 | + endLine: 9, |
| 208 | + endColumn: 23 |
| 209 | + }, |
| 210 | + { |
| 211 | + message: 'Unexpected spaces found around equal signs.', |
| 212 | + line: 10, |
| 213 | + column: 19, |
| 214 | + endLine: 10, |
| 215 | + endColumn: 22 |
| 216 | + }, |
| 217 | + { |
| 218 | + message: 'Unexpected spaces found around equal signs.', |
| 219 | + line: 11, |
| 220 | + column: 19, |
| 221 | + endLine: 11, |
| 222 | + endColumn: 22 |
| 223 | + }, |
| 224 | + { |
| 225 | + message: 'Unexpected spaces found around equal signs.', |
| 226 | + line: 12, |
| 227 | + column: 19, |
| 228 | + endLine: 12, |
| 229 | + endColumn: 22 |
| 230 | + } |
| 231 | + ] |
| 232 | + } |
| 233 | + ] |
| 234 | +}) |
0 commit comments