|
| 1 | +import tsx from "dedent"; |
| 2 | + |
| 3 | +import { allValid, ruleTester } from "../../../../../test"; |
| 4 | +import rule, { RULE_NAME } from "./jsx-dollar"; |
| 5 | + |
| 6 | +ruleTester.run(RULE_NAME, rule, { |
| 7 | + invalid: [ |
| 8 | + { |
| 9 | + code: tsx` |
| 10 | + const MyComponent = () => <>Hello \${user.name}</> |
| 11 | + `, |
| 12 | + errors: [ |
| 13 | + { |
| 14 | + messageId: "jsxDollar", |
| 15 | + suggestions: [ |
| 16 | + { |
| 17 | + messageId: "removeDollarSign", |
| 18 | + output: tsx` |
| 19 | + const MyComponent = () => <>Hello {user.name}</> |
| 20 | + `, |
| 21 | + }, |
| 22 | + ], |
| 23 | + }, |
| 24 | + ], |
| 25 | + }, |
| 26 | + { |
| 27 | + code: tsx` |
| 28 | + const App = (props) => { |
| 29 | + return <div>Hello \${props.name}</div>; |
| 30 | + }; |
| 31 | + `, |
| 32 | + errors: [ |
| 33 | + { |
| 34 | + messageId: "jsxDollar", |
| 35 | + suggestions: [ |
| 36 | + { |
| 37 | + messageId: "removeDollarSign", |
| 38 | + output: tsx` |
| 39 | + const App = (props) => { |
| 40 | + return <div>Hello {props.name}</div>; |
| 41 | + }; |
| 42 | + `, |
| 43 | + }, |
| 44 | + ], |
| 45 | + }, |
| 46 | + ], |
| 47 | + }, |
| 48 | + { |
| 49 | + code: tsx` |
| 50 | + const App = (props) => { |
| 51 | + return <div>\${props.name} is your name</div>; |
| 52 | + }; |
| 53 | + `, |
| 54 | + errors: [ |
| 55 | + { |
| 56 | + messageId: "jsxDollar", |
| 57 | + suggestions: [ |
| 58 | + { |
| 59 | + messageId: "removeDollarSign", |
| 60 | + output: tsx` |
| 61 | + const App = (props) => { |
| 62 | + return <div>{props.name} is your name</div>; |
| 63 | + }; |
| 64 | + `, |
| 65 | + }, |
| 66 | + ], |
| 67 | + }, |
| 68 | + ], |
| 69 | + }, |
| 70 | + { |
| 71 | + code: tsx` |
| 72 | + const App = (props) => { |
| 73 | + return <div>Hello \${props.name} is your name</div>; |
| 74 | + }; |
| 75 | + `, |
| 76 | + errors: [ |
| 77 | + { |
| 78 | + messageId: "jsxDollar", |
| 79 | + suggestions: [ |
| 80 | + { |
| 81 | + messageId: "removeDollarSign", |
| 82 | + output: tsx` |
| 83 | + const App = (props) => { |
| 84 | + return <div>Hello {props.name} is your name</div>; |
| 85 | + }; |
| 86 | + `, |
| 87 | + }, |
| 88 | + ], |
| 89 | + }, |
| 90 | + ], |
| 91 | + }, |
| 92 | + ], |
| 93 | + valid: [ |
| 94 | + ...allValid, |
| 95 | + tsx` |
| 96 | + const MyComponent = () => \`Hello \${user.name}\` |
| 97 | + `, |
| 98 | + tsx` |
| 99 | + const App = (props) => { |
| 100 | + return [<div key="1">1</div>] |
| 101 | + }; |
| 102 | + `, |
| 103 | + tsx` |
| 104 | + const App = (props) => { |
| 105 | + return <div>Hello $</div>; |
| 106 | + }; |
| 107 | + `, |
| 108 | + tsx` |
| 109 | + const App = (props) => { |
| 110 | + return <div>Hello {props.name}</div>; |
| 111 | + }; |
| 112 | + `, |
| 113 | + tsx` |
| 114 | + import React from "react"; |
| 115 | +
|
| 116 | + function MyComponent({ price }) { |
| 117 | + // 🟢 Good: This is a legitimate use of the '$' character. |
| 118 | + return <div>{\`$\${price}\`}</div>; |
| 119 | + } |
| 120 | + `, |
| 121 | + tsx` |
| 122 | + import React from "react"; |
| 123 | + function AnotherComponent({ price }) { |
| 124 | + // 🟢 Good: Another legitimate way to display a price. |
| 125 | + return <div>\${price}</div>; |
| 126 | + } |
| 127 | + `, |
| 128 | + ], |
| 129 | +}); |
0 commit comments