|
| 1 | +import tsx from "dedent"; |
| 2 | + |
| 3 | +import { allValid, ruleTester } from "../../../../../test"; |
| 4 | +import rule, { RULE_NAME } from "./avoid-shorthand-fragment"; |
| 5 | + |
| 6 | +ruleTester.run(RULE_NAME, rule, { |
| 7 | + invalid: [ |
| 8 | + { |
| 9 | + code: tsx`<><div /></>`, |
| 10 | + errors: [ |
| 11 | + { |
| 12 | + messageId: "avoidShorthandFragment", |
| 13 | + }, |
| 14 | + ], |
| 15 | + }, |
| 16 | + { |
| 17 | + code: tsx`<><div /><div /></>`, |
| 18 | + errors: [ |
| 19 | + { |
| 20 | + messageId: "avoidShorthandFragment", |
| 21 | + }, |
| 22 | + ], |
| 23 | + }, |
| 24 | + { |
| 25 | + code: tsx` |
| 26 | + /** @jsx createElement */ |
| 27 | + /** @jsxFrag Fragment */ |
| 28 | +
|
| 29 | + const element = <><div /></>; |
| 30 | + `, |
| 31 | + errors: [ |
| 32 | + { |
| 33 | + messageId: "avoidShorthandFragment", |
| 34 | + data: { |
| 35 | + jsxFragmentFactory: "Fragment", |
| 36 | + }, |
| 37 | + }, |
| 38 | + ], |
| 39 | + }, |
| 40 | + { |
| 41 | + code: tsx` |
| 42 | + /** @jsx React.createElement */ |
| 43 | + /** @jsxFrag React.Fragment */ |
| 44 | +
|
| 45 | + const element = <><div /></>; |
| 46 | + `, |
| 47 | + errors: [ |
| 48 | + { |
| 49 | + messageId: "avoidShorthandFragment", |
| 50 | + data: { |
| 51 | + jsxFragmentFactory: "React.Fragment", |
| 52 | + }, |
| 53 | + }, |
| 54 | + ], |
| 55 | + }, |
| 56 | + { |
| 57 | + code: tsx` |
| 58 | + /** @jsx h */ |
| 59 | + /** @jsxFrag Fragment */ |
| 60 | +
|
| 61 | + const element = <><div /></>; |
| 62 | + `, |
| 63 | + errors: [ |
| 64 | + { |
| 65 | + messageId: "avoidShorthandFragment", |
| 66 | + data: { |
| 67 | + jsxFragmentFactory: "Fragment", |
| 68 | + }, |
| 69 | + }, |
| 70 | + ], |
| 71 | + }, |
| 72 | + { |
| 73 | + code: tsx` |
| 74 | + /** @jsx Preact.h */ |
| 75 | + /** @jsxFrag Preact.Fragment */ |
| 76 | +
|
| 77 | + const element = <><div /></>; |
| 78 | + `, |
| 79 | + errors: [ |
| 80 | + { |
| 81 | + messageId: "avoidShorthandFragment", |
| 82 | + data: { |
| 83 | + jsxFragmentFactory: "Preact.Fragment", |
| 84 | + }, |
| 85 | + }, |
| 86 | + ], |
| 87 | + }, |
| 88 | + ], |
| 89 | + valid: [ |
| 90 | + ...allValid, |
| 91 | + "<React.Fragment><Foo /><Bar /></React.Fragment>", |
| 92 | + "<Fragment>foo<div /></Fragment>", |
| 93 | + ], |
| 94 | +}); |
0 commit comments