|
| 1 | +import tsx from "dedent"; |
| 2 | + |
| 3 | +import { allValid, ruleTester } from "../../../../../test"; |
| 4 | +import rule, { RULE_NAME } from "./jsx-key-before-spread"; |
| 5 | + |
| 6 | +ruleTester.run(RULE_NAME, rule, { |
| 7 | + invalid: [ |
| 8 | + { |
| 9 | + code: tsx` |
| 10 | + const App = (props) => { |
| 11 | + return [ |
| 12 | + <div {...props} key="1">1</div>, |
| 13 | + <div {...props} key="1">2</div>, |
| 14 | + <div {...props} key="1">3</div>, |
| 15 | + ] |
| 16 | + }; |
| 17 | + `, |
| 18 | + errors: [ |
| 19 | + { messageId: "jsxKeyBeforeSpread" }, |
| 20 | + { messageId: "jsxKeyBeforeSpread" }, |
| 21 | + { messageId: "jsxKeyBeforeSpread" }, |
| 22 | + ], |
| 23 | + }, |
| 24 | + { |
| 25 | + code: tsx` |
| 26 | +
|
| 27 | + const App = (props) => { |
| 28 | + return [ |
| 29 | + <div {...props} key="1">1</div>, |
| 30 | + <div {...props} key="1">2</div>, |
| 31 | + <div {...props} key="1">3</div>, |
| 32 | + ] |
| 33 | + }; |
| 34 | + `, |
| 35 | + errors: [ |
| 36 | + { messageId: "jsxKeyBeforeSpread" }, |
| 37 | + { messageId: "jsxKeyBeforeSpread" }, |
| 38 | + { messageId: "jsxKeyBeforeSpread" }, |
| 39 | + ], |
| 40 | + }, |
| 41 | + ], |
| 42 | + valid: [ |
| 43 | + ...allValid, |
| 44 | + tsx` |
| 45 | + const App = (props) => { |
| 46 | + return [<div key="1">1</div>] |
| 47 | + }; |
| 48 | + `, |
| 49 | + tsx` |
| 50 | + const App = (props) => { |
| 51 | + return [ |
| 52 | + <div key="1" {...props}>1</div>, |
| 53 | + <div key="2" {...props}>2</div>, |
| 54 | + <div key="3" {...props}>3</div>, |
| 55 | + ] |
| 56 | + }; |
| 57 | + `, |
| 58 | + tsx` |
| 59 | + const App = (props) => { |
| 60 | + return [1, 2, 3].map((item) => <div key={Math.random()}>{item}</div>) |
| 61 | + }; |
| 62 | + `, |
| 63 | + ], |
| 64 | +}); |
0 commit comments