|
| 1 | +# Covered Cases |
| 2 | + |
| 3 | +This plugin is intended to not be too opinionated. In general the approach is to suggest to the developer to add 'data-component' when there is an obvious approach, but in questionable cases, the plugin will them and stay quiet. |
| 4 | + |
| 5 | +### Covered |
| 6 | + |
| 7 | +#### Basic function components |
| 8 | + |
| 9 | +```tsx |
| 10 | +const MyComponent = () => <div />; |
| 11 | +``` |
| 12 | + |
| 13 | +> MyComponent is missing the data-component attribute for the top-level element. |
| 14 | +
|
| 15 | +```tsx |
| 16 | +function MyComponent() { |
| 17 | + return <div />; |
| 18 | +} |
| 19 | +``` |
| 20 | + |
| 21 | +> MyComponent is missing the data-component attribute for the top-level element. |
| 22 | +
|
| 23 | +```tsx |
| 24 | +export default function MyComponent() { |
| 25 | + return <div />; |
| 26 | +} |
| 27 | +``` |
| 28 | + |
| 29 | +> MyComponent is missing the data-component attribute for the top-level element. |
| 30 | +
|
| 31 | +#### Typescript generic components |
| 32 | + |
| 33 | +```tsx |
| 34 | +const yAxis = (xScale, xTicks) => ( |
| 35 | + <BottomAxis<Date> width={1} height={1} xScale={xScale} xTicks={xTicks}> |
| 36 | + 123 |
| 37 | + </BottomAxis> |
| 38 | +); |
| 39 | +``` |
| 40 | + |
| 41 | +> yAxis is missing the data-component attribute for the top-level element. |
| 42 | +
|
| 43 | +#### Multiple components in a file |
| 44 | + |
| 45 | +```tsx |
| 46 | +const Component1 = () => <div />; |
| 47 | +const Component2 = () => <span />; |
| 48 | +``` |
| 49 | + |
| 50 | +> Component1 is missing the data-component attribute for the top-level element. |
| 51 | +> Component2 is missing the data-component attribute for the top-level element. |
| 52 | +
|
| 53 | +#### Class-based components |
| 54 | + |
| 55 | +```tsx |
| 56 | +class Car extends React.Component { |
| 57 | + render() { |
| 58 | + return <h2>Hi, I am a Car!</h2>; |
| 59 | + } |
| 60 | +} |
| 61 | +``` |
| 62 | + |
| 63 | +> Car is missing the data-component attribute for the top-level element. |
| 64 | +
|
| 65 | +#### Components wrapped with forwardRef |
| 66 | + |
| 67 | +```tsx |
| 68 | +export const Navigate = React.forwardRef<HTMLAnchorElement, NavigateProps>( |
| 69 | + (props, ref) => <Link ref={ref} {...props} />, |
| 70 | +); |
| 71 | +``` |
| 72 | + |
| 73 | +> Navigate is missing the data-component attribute for the top-level element. |
| 74 | +
|
| 75 | +### Ignored |
| 76 | + |
| 77 | +#### Components with Provider as the top-level element |
| 78 | + |
| 79 | +```tsx |
| 80 | +export const App = () => <AppContext.Provider value={ctx} />; |
| 81 | +``` |
| 82 | + |
| 83 | +> All good! |
| 84 | +
|
| 85 | +_Note: This just uses a simple `/Provider$/` regex test_ |
| 86 | + |
| 87 | +#### Components with a [React Fragment](https://reactjs.org/docs/fragments.html) as the top-level element |
| 88 | + |
| 89 | +```tsx |
| 90 | +const FragmentComponent = () => ( |
| 91 | + <> |
| 92 | + <span /> |
| 93 | + <div /> |
| 94 | + <a /> |
| 95 | + </> |
| 96 | +); |
| 97 | +``` |
| 98 | + |
| 99 | +> All good! |
| 100 | +
|
| 101 | +#### Components that conditionally return different values |
| 102 | + |
| 103 | +```tsx |
| 104 | +const ConditionalComponent = () => { |
| 105 | + const isActive = useIsActive(); |
| 106 | + return isActive ? <div /> : null; |
| 107 | +}; |
| 108 | +``` |
| 109 | + |
| 110 | +> All good! |
| 111 | +
|
| 112 | +```tsx |
| 113 | +const ConditionalComponent = () => { |
| 114 | + const isActive = useIsActive(); |
| 115 | + if (isActive) { |
| 116 | + return <ActiveComponent />; |
| 117 | + } |
| 118 | + return <div />; |
| 119 | +}; |
| 120 | +``` |
| 121 | + |
| 122 | +> All good! |
0 commit comments