|
| 1 | +import { RuleTester } from '@typescript-eslint/rule-tester'; |
| 2 | + |
| 3 | +import { noEmptyStory } from '../no-empty-story'; |
| 4 | + |
| 5 | +const ruleTester = new RuleTester(); |
| 6 | + |
| 7 | +ruleTester.run('no-empty-story', noEmptyStory, { |
| 8 | + valid: [ |
| 9 | + { |
| 10 | + name: 'non-empty args', |
| 11 | + code: `export const Primary = { args: { label: 'Hello' } };`, |
| 12 | + }, |
| 13 | + |
| 14 | + { |
| 15 | + name: 'has render function', |
| 16 | + code: `export const Primary = { render: () => {} };`, |
| 17 | + }, |
| 18 | + |
| 19 | + { |
| 20 | + name: 'has render and empty args', |
| 21 | + code: `export const Primary = { args: {}, render: () => {} };`, |
| 22 | + }, |
| 23 | + |
| 24 | + { |
| 25 | + name: 'has play function', |
| 26 | + code: `export const Primary = { play: () => {} };`, |
| 27 | + }, |
| 28 | + |
| 29 | + { |
| 30 | + name: 'has play and empty args', |
| 31 | + code: `export const Primary = { args: {}, play: () => {} };`, |
| 32 | + }, |
| 33 | + |
| 34 | + { |
| 35 | + name: 'args referencing a variable', |
| 36 | + code: ` |
| 37 | + const someArgs = { label: 'Hello' }; |
| 38 | + export const Primary = { args: someArgs }; |
| 39 | + `, |
| 40 | + }, |
| 41 | + |
| 42 | + { |
| 43 | + name: 'default export with empty object', |
| 44 | + code: `export default {};`, |
| 45 | + }, |
| 46 | + |
| 47 | + { |
| 48 | + name: 'named export of a non-object value', |
| 49 | + code: `export const name = 'Button';`, |
| 50 | + }, |
| 51 | + ], |
| 52 | + |
| 53 | + invalid: [ |
| 54 | + { |
| 55 | + name: 'empty object', |
| 56 | + code: `export const Primary = {};`, |
| 57 | + errors: [ |
| 58 | + { |
| 59 | + messageId: 'noEmptyStory', |
| 60 | + line: 1, |
| 61 | + endLine: 1, |
| 62 | + column: 24, |
| 63 | + endColumn: 26, |
| 64 | + }, |
| 65 | + ], |
| 66 | + }, |
| 67 | + |
| 68 | + { |
| 69 | + name: 'empty object with type annotation', |
| 70 | + code: `export const Primary: Story = {};`, |
| 71 | + errors: [ |
| 72 | + { |
| 73 | + messageId: 'noEmptyStory', |
| 74 | + line: 1, |
| 75 | + endLine: 1, |
| 76 | + column: 31, |
| 77 | + endColumn: 33, |
| 78 | + }, |
| 79 | + ], |
| 80 | + }, |
| 81 | + |
| 82 | + { |
| 83 | + name: 'empty object with satisfies', |
| 84 | + code: `export const Primary = {} satisfies Story;`, |
| 85 | + errors: [ |
| 86 | + { |
| 87 | + messageId: 'noEmptyStory', |
| 88 | + line: 1, |
| 89 | + endLine: 1, |
| 90 | + column: 24, |
| 91 | + endColumn: 26, |
| 92 | + }, |
| 93 | + ], |
| 94 | + }, |
| 95 | + |
| 96 | + { |
| 97 | + name: 'empty object with as assertion', |
| 98 | + code: `export const Primary = {} as Story;`, |
| 99 | + errors: [ |
| 100 | + { |
| 101 | + messageId: 'noEmptyStory', |
| 102 | + line: 1, |
| 103 | + endLine: 1, |
| 104 | + column: 24, |
| 105 | + endColumn: 26, |
| 106 | + }, |
| 107 | + ], |
| 108 | + }, |
| 109 | + |
| 110 | + { |
| 111 | + name: 'empty args', |
| 112 | + code: `export const Primary = { args: {} };`, |
| 113 | + errors: [ |
| 114 | + { |
| 115 | + messageId: 'noEmptyStory', |
| 116 | + line: 1, |
| 117 | + endLine: 1, |
| 118 | + column: 24, |
| 119 | + endColumn: 36, |
| 120 | + }, |
| 121 | + ], |
| 122 | + }, |
| 123 | + |
| 124 | + { |
| 125 | + name: 'variable reference to empty object', |
| 126 | + code: ` |
| 127 | + const empty = {}; |
| 128 | + export const Primary = empty; |
| 129 | + `, |
| 130 | + errors: [ |
| 131 | + { |
| 132 | + messageId: 'noEmptyStory', |
| 133 | + line: 2, |
| 134 | + endLine: 2, |
| 135 | + column: 19, |
| 136 | + endColumn: 21, |
| 137 | + }, |
| 138 | + ], |
| 139 | + }, |
| 140 | + |
| 141 | + { |
| 142 | + name: 'variable reference chain', |
| 143 | + code: ` |
| 144 | + const a = {}; |
| 145 | + const b = a; |
| 146 | + export const Primary = b; |
| 147 | + `, |
| 148 | + errors: [ |
| 149 | + { |
| 150 | + messageId: 'noEmptyStory', |
| 151 | + line: 2, |
| 152 | + endLine: 2, |
| 153 | + column: 15, |
| 154 | + endColumn: 17, |
| 155 | + }, |
| 156 | + ], |
| 157 | + }, |
| 158 | + |
| 159 | + { |
| 160 | + name: 'multiple empty exports', |
| 161 | + code: ` |
| 162 | + export const Primary = {}; |
| 163 | + export const Secondary = {}; |
| 164 | + `, |
| 165 | + errors: [ |
| 166 | + { |
| 167 | + messageId: 'noEmptyStory', |
| 168 | + line: 2, |
| 169 | + endLine: 2, |
| 170 | + column: 28, |
| 171 | + endColumn: 30, |
| 172 | + }, |
| 173 | + { |
| 174 | + messageId: 'noEmptyStory', |
| 175 | + line: 3, |
| 176 | + endLine: 3, |
| 177 | + column: 30, |
| 178 | + endColumn: 32, |
| 179 | + }, |
| 180 | + ], |
| 181 | + }, |
| 182 | + |
| 183 | + { |
| 184 | + name: 'shared empty variable', |
| 185 | + code: ` |
| 186 | + const empty = {}; |
| 187 | + export const A = empty; |
| 188 | + export const B = empty; |
| 189 | + `, |
| 190 | + errors: [ |
| 191 | + { |
| 192 | + messageId: 'noEmptyStory', |
| 193 | + line: 2, |
| 194 | + endLine: 2, |
| 195 | + column: 19, |
| 196 | + endColumn: 21, |
| 197 | + }, |
| 198 | + ], |
| 199 | + }, |
| 200 | + ], |
| 201 | +}); |
0 commit comments