|
| 1 | +import { RuleTester } from 'eslint' |
| 2 | +import rule = require('../../../lib/rules/prefer-sfc-lang-attr') |
| 3 | + |
| 4 | +new RuleTester({ |
| 5 | + parser: require.resolve('vue-eslint-parser'), |
| 6 | + parserOptions: { ecmaVersion: 2020, sourceType: 'module' } |
| 7 | +}).run('prefer-sfc-lang-attr', rule as never, { |
| 8 | + valid: [ |
| 9 | + { |
| 10 | + filename: 'test.vue', |
| 11 | + code: ` |
| 12 | + <i18n lang="json">{}</i18n> |
| 13 | + <template></template> |
| 14 | + <script></script>` |
| 15 | + }, |
| 16 | + { |
| 17 | + filename: 'test.vue', |
| 18 | + code: ` |
| 19 | + <i18n lang="json5">{}</i18n> |
| 20 | + <template></template> |
| 21 | + <script></script>` |
| 22 | + }, |
| 23 | + { |
| 24 | + filename: 'test.vue', |
| 25 | + code: ` |
| 26 | + <i18n lang="yaml">{}</i18n> |
| 27 | + <template></template> |
| 28 | + <script></script>` |
| 29 | + } |
| 30 | + ], |
| 31 | + invalid: [ |
| 32 | + { |
| 33 | + filename: 'test.vue', |
| 34 | + code: ` |
| 35 | + <i18n>{}</i18n> |
| 36 | + <template></template> |
| 37 | + <script></script>`, |
| 38 | + output: ` |
| 39 | + <i18n lang="json" >{}</i18n> |
| 40 | + <template></template> |
| 41 | + <script></script>`, |
| 42 | + errors: [ |
| 43 | + { |
| 44 | + message: '`lang` attribute is required.', |
| 45 | + line: 2, |
| 46 | + column: 7, |
| 47 | + endLine: 2, |
| 48 | + endColumn: 13 |
| 49 | + } |
| 50 | + ] |
| 51 | + }, |
| 52 | + { |
| 53 | + filename: 'test.vue', |
| 54 | + code: ` |
| 55 | + <i18n>{}</i18n> |
| 56 | + <template></template>`, |
| 57 | + output: ` |
| 58 | + <i18n lang="json" >{}</i18n> |
| 59 | + <template></template>`, |
| 60 | + errors: [ |
| 61 | + { |
| 62 | + message: '`lang` attribute is required.', |
| 63 | + line: 2, |
| 64 | + column: 7, |
| 65 | + endLine: 2, |
| 66 | + endColumn: 13 |
| 67 | + } |
| 68 | + ] |
| 69 | + }, |
| 70 | + { |
| 71 | + filename: 'test.vue', |
| 72 | + code: ` |
| 73 | + <i18n locale="en" >{}</i18n> |
| 74 | + <template></template> |
| 75 | + <script></script>`, |
| 76 | + output: ` |
| 77 | + <i18n locale="en" lang="json" >{}</i18n> |
| 78 | + <template></template> |
| 79 | + <script></script>`, |
| 80 | + errors: [ |
| 81 | + { |
| 82 | + message: '`lang` attribute is required.', |
| 83 | + line: 2, |
| 84 | + column: 7, |
| 85 | + endLine: 2, |
| 86 | + endColumn: 26 |
| 87 | + } |
| 88 | + ] |
| 89 | + }, |
| 90 | + { |
| 91 | + filename: 'test.vue', |
| 92 | + code: ` |
| 93 | + <i18n lang>{}</i18n> |
| 94 | + <template></template>`, |
| 95 | + output: ` |
| 96 | + <i18n lang="json">{}</i18n> |
| 97 | + <template></template>`, |
| 98 | + errors: [ |
| 99 | + { |
| 100 | + message: '`lang` attribute is required.', |
| 101 | + line: 2, |
| 102 | + column: 13, |
| 103 | + endLine: 2, |
| 104 | + endColumn: 17 |
| 105 | + } |
| 106 | + ] |
| 107 | + }, |
| 108 | + { |
| 109 | + filename: 'test.vue', |
| 110 | + code: ` |
| 111 | + <i18n lang="">{}</i18n> |
| 112 | + <template></template>`, |
| 113 | + output: ` |
| 114 | + <i18n lang="json">{}</i18n> |
| 115 | + <template></template>`, |
| 116 | + errors: [ |
| 117 | + { |
| 118 | + message: '`lang` attribute is required.', |
| 119 | + line: 2, |
| 120 | + column: 18, |
| 121 | + endLine: 2, |
| 122 | + endColumn: 20 |
| 123 | + } |
| 124 | + ] |
| 125 | + } |
| 126 | + ] |
| 127 | +}) |
0 commit comments