|
| 1 | +/** |
| 2 | + * @fileoverview enforce `v-for` directive's delimiter style |
| 3 | + * @author Flo Edelmann |
| 4 | + * @copyright 2020 Flo Edelmann. All rights reserved. |
| 5 | + * See LICENSE file in root directory for full license. |
| 6 | + */ |
| 7 | +'use strict' |
| 8 | + |
| 9 | +// ------------------------------------------------------------------------------ |
| 10 | +// Requirements |
| 11 | +// ------------------------------------------------------------------------------ |
| 12 | + |
| 13 | +const RuleTester = require('eslint').RuleTester |
| 14 | +const rule = require('../../../lib/rules/v-for-delimiter-style') |
| 15 | + |
| 16 | +// ------------------------------------------------------------------------------ |
| 17 | +// Tests |
| 18 | +// ------------------------------------------------------------------------------ |
| 19 | + |
| 20 | +const tester = new RuleTester({ |
| 21 | + parser: require.resolve('vue-eslint-parser'), |
| 22 | + parserOptions: { ecmaVersion: 2015 } |
| 23 | +}) |
| 24 | + |
| 25 | +tester.run('v-for-delimiter-style', rule, { |
| 26 | + valid: [ |
| 27 | + { |
| 28 | + filename: 'test.vue', |
| 29 | + code: '' |
| 30 | + }, |
| 31 | + { |
| 32 | + filename: 'test.vue', |
| 33 | + code: '<template><div v-for="x in xs"></div></template>' |
| 34 | + }, |
| 35 | + { |
| 36 | + filename: 'test.vue', |
| 37 | + code: '<template><div v-for="x in xs"></div></template>' |
| 38 | + }, |
| 39 | + { |
| 40 | + filename: 'test.vue', |
| 41 | + code: '<template><div v-for="x in xs"></div></template>' |
| 42 | + }, |
| 43 | + { |
| 44 | + filename: 'test.vue', |
| 45 | + code: '<template><div v-for="x in xs"></div></template>' |
| 46 | + }, |
| 47 | + { |
| 48 | + filename: 'test.vue', |
| 49 | + code: '<template><div v-for="x in xs"></div></template>', |
| 50 | + options: ['in'] |
| 51 | + }, |
| 52 | + { |
| 53 | + filename: 'test.vue', |
| 54 | + code: '<template><div v-for="x of xs"></div></template>', |
| 55 | + options: ['of'] |
| 56 | + } |
| 57 | + ], |
| 58 | + invalid: [ |
| 59 | + { |
| 60 | + filename: 'test.vue', |
| 61 | + code: '<template><div v-for="x of xs"></div></template>', |
| 62 | + output: '<template><div v-for="x in xs"></div></template>', |
| 63 | + errors: [ |
| 64 | + { |
| 65 | + message: "Expected 'in' instead of 'of' in 'v-for'.", |
| 66 | + column: 23 |
| 67 | + } |
| 68 | + ] |
| 69 | + }, |
| 70 | + { |
| 71 | + filename: 'test.vue', |
| 72 | + code: '<template><div v-for="x of xs"></div></template>', |
| 73 | + output: '<template><div v-for="x in xs"></div></template>', |
| 74 | + errors: [ |
| 75 | + { |
| 76 | + message: "Expected 'in' instead of 'of' in 'v-for'.", |
| 77 | + column: 23 |
| 78 | + } |
| 79 | + ] |
| 80 | + }, |
| 81 | + { |
| 82 | + filename: 'test.vue', |
| 83 | + code: '<template><div v-for="x of xs"></div></template>', |
| 84 | + output: '<template><div v-for="x in xs"></div></template>', |
| 85 | + errors: [ |
| 86 | + { |
| 87 | + message: "Expected 'in' instead of 'of' in 'v-for'.", |
| 88 | + column: 23 |
| 89 | + } |
| 90 | + ] |
| 91 | + }, |
| 92 | + { |
| 93 | + filename: 'test.vue', |
| 94 | + code: '<template><div v-for="x of xs"></div></template>', |
| 95 | + output: '<template><div v-for="x in xs"></div></template>', |
| 96 | + errors: [ |
| 97 | + { |
| 98 | + message: "Expected 'in' instead of 'of' in 'v-for'.", |
| 99 | + column: 23 |
| 100 | + } |
| 101 | + ] |
| 102 | + }, |
| 103 | + { |
| 104 | + filename: 'test.vue', |
| 105 | + options: ['in'], |
| 106 | + code: '<template><div v-for="x of xs"></div></template>', |
| 107 | + output: '<template><div v-for="x in xs"></div></template>', |
| 108 | + errors: [ |
| 109 | + { |
| 110 | + message: "Expected 'in' instead of 'of' in 'v-for'.", |
| 111 | + column: 23 |
| 112 | + } |
| 113 | + ] |
| 114 | + }, |
| 115 | + { |
| 116 | + filename: 'test.vue', |
| 117 | + options: ['of'], |
| 118 | + code: '<template><div v-for="x in xs"></div></template>', |
| 119 | + output: '<template><div v-for="x of xs"></div></template>', |
| 120 | + errors: [ |
| 121 | + { |
| 122 | + message: "Expected 'of' instead of 'in' in 'v-for'.", |
| 123 | + column: 23 |
| 124 | + } |
| 125 | + ] |
| 126 | + } |
| 127 | + ] |
| 128 | +}) |
0 commit comments