|
| 1 | +/** |
| 2 | + * @author WayneZhang |
| 3 | + * See LICENSE file in root directory for full license. |
| 4 | + */ |
| 5 | +'use strict' |
| 6 | + |
| 7 | +const RuleTester = require('../../eslint-compat').RuleTester |
| 8 | +const rule = require('../../../lib/rules/slot-name-casing') |
| 9 | + |
| 10 | +const tester = new RuleTester({ |
| 11 | + languageOptions: { |
| 12 | + parser: require('vue-eslint-parser'), |
| 13 | + ecmaVersion: 2020, |
| 14 | + sourceType: 'module' |
| 15 | + } |
| 16 | +}) |
| 17 | + |
| 18 | +tester.run('slot-name-casing', rule, { |
| 19 | + valid: [ |
| 20 | + `<template><slot key="foo" /></template>`, |
| 21 | + `<template><slot name /></template>`, |
| 22 | + `<template><slot name="foo" /></template>`, |
| 23 | + `<template><slot name="fooBar" /></template>`, |
| 24 | + `<template><slot :name="fooBar" /></template>`, |
| 25 | + { |
| 26 | + filename: 'test.vue', |
| 27 | + code: ` |
| 28 | + <template> |
| 29 | + <slot name="foo" /> |
| 30 | + <slot name="foo-bar" /> |
| 31 | + <slot :name="fooBar" /> |
| 32 | + </template> |
| 33 | + `, |
| 34 | + options: ['kebab-case'] |
| 35 | + }, |
| 36 | + { |
| 37 | + filename: 'test.vue', |
| 38 | + code: ` |
| 39 | + <template> |
| 40 | + <slot name="foo" /> |
| 41 | + <slot :name="fooBar" /> |
| 42 | + </template> |
| 43 | + `, |
| 44 | + options: ['singleword'] |
| 45 | + } |
| 46 | + ], |
| 47 | + invalid: [ |
| 48 | + { |
| 49 | + filename: 'test.vue', |
| 50 | + code: ` |
| 51 | + <template> |
| 52 | + <slot name="foo-bar" /> |
| 53 | + <slot name="foo-Bar_baz" /> |
| 54 | + </template> |
| 55 | + `, |
| 56 | + errors: [ |
| 57 | + { |
| 58 | + messageId: 'invalidCase', |
| 59 | + data: { |
| 60 | + name: 'foo-bar', |
| 61 | + caseType: 'camelCase' |
| 62 | + }, |
| 63 | + line: 3, |
| 64 | + column: 17 |
| 65 | + }, |
| 66 | + { |
| 67 | + messageId: 'invalidCase', |
| 68 | + data: { |
| 69 | + name: 'foo-Bar_baz', |
| 70 | + caseType: 'camelCase' |
| 71 | + }, |
| 72 | + line: 4, |
| 73 | + column: 17 |
| 74 | + } |
| 75 | + ] |
| 76 | + }, |
| 77 | + { |
| 78 | + filename: 'test.vue', |
| 79 | + code: ` |
| 80 | + <template> |
| 81 | + <slot name="fooBar" /> |
| 82 | + <slot name="foo-Bar_baz" /> |
| 83 | + </template> |
| 84 | + `, |
| 85 | + options: ['kebab-case'], |
| 86 | + errors: [ |
| 87 | + { |
| 88 | + messageId: 'invalidCase', |
| 89 | + data: { |
| 90 | + name: 'fooBar', |
| 91 | + caseType: 'kebab-case' |
| 92 | + }, |
| 93 | + line: 3, |
| 94 | + column: 17 |
| 95 | + }, |
| 96 | + { |
| 97 | + messageId: 'invalidCase', |
| 98 | + data: { |
| 99 | + name: 'foo-Bar_baz', |
| 100 | + caseType: 'kebab-case' |
| 101 | + }, |
| 102 | + line: 4, |
| 103 | + column: 17 |
| 104 | + } |
| 105 | + ] |
| 106 | + }, |
| 107 | + { |
| 108 | + filename: 'test.vue', |
| 109 | + code: ` |
| 110 | + <template> |
| 111 | + <slot name="foo-bar" /> |
| 112 | + <slot name="fooBar" /> |
| 113 | + <slot name="foo-Bar_baz" /> |
| 114 | + </template> |
| 115 | + `, |
| 116 | + options: ['singleword'], |
| 117 | + errors: [ |
| 118 | + { |
| 119 | + messageId: 'invalidCase', |
| 120 | + data: { |
| 121 | + name: 'foo-bar', |
| 122 | + caseType: 'singleword' |
| 123 | + }, |
| 124 | + line: 3, |
| 125 | + column: 17 |
| 126 | + }, |
| 127 | + { |
| 128 | + messageId: 'invalidCase', |
| 129 | + data: { |
| 130 | + name: 'fooBar', |
| 131 | + caseType: 'singleword' |
| 132 | + }, |
| 133 | + line: 4, |
| 134 | + column: 17 |
| 135 | + }, |
| 136 | + { |
| 137 | + messageId: 'invalidCase', |
| 138 | + data: { |
| 139 | + name: 'foo-Bar_baz', |
| 140 | + caseType: 'singleword' |
| 141 | + }, |
| 142 | + line: 5, |
| 143 | + column: 17 |
| 144 | + } |
| 145 | + ] |
| 146 | + } |
| 147 | + ] |
| 148 | +}) |
0 commit comments