|
| 1 | +/** |
| 2 | + * @fileoverview This rule warns about the usage of extra whitespaces between attributes |
| 3 | + * @author Armano |
| 4 | + */ |
| 5 | +'use strict' |
| 6 | + |
| 7 | +// ------------------------------------------------------------------------------ |
| 8 | +// Requirements |
| 9 | +// ------------------------------------------------------------------------------ |
| 10 | + |
| 11 | +const rule = require('../../../lib/rules/no-multi-spaces') |
| 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('no-multi-spaces', rule, { |
| 24 | + valid: [ |
| 25 | + '', |
| 26 | + '<template></template>', |
| 27 | + '<template><div /></template>', |
| 28 | + '<template><div class="foo"></div></template>', |
| 29 | + '<template><div class=" foo " style=" foo "></div></template>', |
| 30 | + '<template><div class="foo" @click="bar"></div></template>', |
| 31 | + '<template><div class="foo"\n :style="foo"></div></template>', |
| 32 | + '<template><div class="foo"\n\t\t\t:style="foo"></div></template>', |
| 33 | + '<template><div class="foo"\n :style="foo"\n ></div></template>', |
| 34 | + '<template><div class="foo"\n :style="foo" /></template>', |
| 35 | + '<template><div class="foo"\n :style="foo"\n /></template>', |
| 36 | + '<template><div>{{ test }}</div></template>', |
| 37 | + '<template><div>{{test}}</div></template>', |
| 38 | + '<template><div>{{test}}<!-- fooo --></div></template>', |
| 39 | + '<template><div>{{test}} <!-- fooo --></div></template>', |
| 40 | + '<template><div v-for="i in b">{{ i }}</div></template>', |
| 41 | + '<template><div v-for=" i in b ">{{ i }}</div></template>', |
| 42 | + '<template><div :test="` `"> {{ a }} </div></template>', |
| 43 | + '<template><div :test="` `"> \n {{ a }} </div></template>' |
| 44 | + ], |
| 45 | + invalid: [ |
| 46 | + { |
| 47 | + code: '<template><div /></template>', |
| 48 | + output: '<template><div /></template>', |
| 49 | + errors: [{ |
| 50 | + message: "Multiple spaces found before '/>'.", |
| 51 | + type: 'HTMLSelfClosingTagClose' |
| 52 | + }] |
| 53 | + }, |
| 54 | + { |
| 55 | + code: '<template><div class="foo" /></template>', |
| 56 | + output: '<template><div class="foo" /></template>', |
| 57 | + errors: [ |
| 58 | + { |
| 59 | + message: "Multiple spaces found before 'class'.", |
| 60 | + type: 'HTMLIdentifier' |
| 61 | + }, |
| 62 | + { |
| 63 | + message: "Multiple spaces found before '/>'.", |
| 64 | + type: 'HTMLSelfClosingTagClose' |
| 65 | + } |
| 66 | + ] |
| 67 | + }, |
| 68 | + { |
| 69 | + code: '<template><div\t\tclass="foo"\t\t/></template>', |
| 70 | + output: '<template><div class="foo" /></template>', |
| 71 | + errors: [ |
| 72 | + { |
| 73 | + message: "Multiple spaces found before 'class'.", |
| 74 | + type: 'HTMLIdentifier' |
| 75 | + }, |
| 76 | + { |
| 77 | + message: "Multiple spaces found before '/>'.", |
| 78 | + type: 'HTMLSelfClosingTagClose' |
| 79 | + } |
| 80 | + ] |
| 81 | + }, |
| 82 | + { |
| 83 | + code: '<template><div :class="foo" /></template>', |
| 84 | + output: '<template><div :class="foo" /></template>', |
| 85 | + errors: [ |
| 86 | + { |
| 87 | + message: "Multiple spaces found before ':class'.", |
| 88 | + type: 'HTMLIdentifier' |
| 89 | + }, |
| 90 | + { |
| 91 | + message: "Multiple spaces found before '/>'.", |
| 92 | + type: 'HTMLSelfClosingTagClose' |
| 93 | + } |
| 94 | + ] |
| 95 | + }, |
| 96 | + { |
| 97 | + code: '<template><div :foo="" class="foo" /></template>', |
| 98 | + output: '<template><div :foo="" class="foo" /></template>', |
| 99 | + errors: [{ |
| 100 | + message: "Multiple spaces found before '/>'.", |
| 101 | + type: 'HTMLSelfClosingTagClose' |
| 102 | + }] |
| 103 | + }, |
| 104 | + { |
| 105 | + code: '<template><div foo="" class="foo" /></template>', |
| 106 | + output: '<template><div foo="" class="foo" /></template>', |
| 107 | + errors: [{ |
| 108 | + message: "Multiple spaces found before '/>'.", |
| 109 | + type: 'HTMLSelfClosingTagClose' |
| 110 | + }] |
| 111 | + }, |
| 112 | + { |
| 113 | + code: '<template><foo v-foo="" class="foo" /></template>', |
| 114 | + output: '<template><foo v-foo="" class="foo" /></template>', |
| 115 | + errors: [{ |
| 116 | + message: "Multiple spaces found before '/>'.", |
| 117 | + type: 'HTMLSelfClosingTagClose' |
| 118 | + }] |
| 119 | + }, |
| 120 | + { |
| 121 | + code: '<template><foo v-foo="" \n class="foo" /></template>', |
| 122 | + output: '<template><foo v-foo="" \n class="foo" /></template>', |
| 123 | + errors: [ |
| 124 | + { |
| 125 | + message: "Multiple spaces found before '/>'.", |
| 126 | + type: 'HTMLSelfClosingTagClose' |
| 127 | + } |
| 128 | + ] |
| 129 | + }, |
| 130 | + { |
| 131 | + code: '<template><div>{{ test }}</div></template>', |
| 132 | + output: '<template><div>{{ test }}</div></template>', |
| 133 | + errors: [ |
| 134 | + { |
| 135 | + message: "Multiple spaces found before 'test'.", |
| 136 | + type: 'Identifier' |
| 137 | + }, |
| 138 | + { |
| 139 | + message: "Multiple spaces found before '}}'.", |
| 140 | + type: 'VExpressionEnd' |
| 141 | + } |
| 142 | + ] |
| 143 | + }, |
| 144 | + { |
| 145 | + code: '<template><div ></div></template>', |
| 146 | + output: '<template><div ></div></template>', |
| 147 | + errors: [ |
| 148 | + { |
| 149 | + message: "Multiple spaces found before '>'.", |
| 150 | + type: 'HTMLTagClose' |
| 151 | + } |
| 152 | + ] |
| 153 | + }, |
| 154 | + { |
| 155 | + code: '<template><div v-for=" i in b ">{{ test }}</div></template>', |
| 156 | + output: '<template><div v-for=" i in b ">{{ test }}</div></template>', |
| 157 | + errors: [ |
| 158 | + { |
| 159 | + message: "Multiple spaces found before 'i'.", |
| 160 | + type: 'Identifier' |
| 161 | + }, |
| 162 | + { |
| 163 | + message: "Multiple spaces found before 'in'.", |
| 164 | + type: 'Keyword' |
| 165 | + }, |
| 166 | + { |
| 167 | + message: "Multiple spaces found before 'b'.", |
| 168 | + type: 'Identifier' |
| 169 | + }, |
| 170 | + { |
| 171 | + message: "Multiple spaces found before '\"'.", |
| 172 | + type: 'Punctuator' |
| 173 | + } |
| 174 | + ] |
| 175 | + } |
| 176 | + ] |
| 177 | +}) |
0 commit comments