-
-
Notifications
You must be signed in to change notification settings - Fork 4
fix: dsr avatar linting violations #674
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
'packages/design-system-react/src/components/AvatarFavicon/AvatarFavicon.test.tsx', | ||
'packages/design-system-react/src/components/AvatarGroup/AvatarGroup.stories.tsx', | ||
'packages/design-system-react/src/components/AvatarGroup/AvatarGroup.test.tsx', | ||
'packages/design-system-react/src/components/AvatarGroup/AvatarGroup.tsx', | ||
'packages/design-system-react/src/components/AvatarNetwork/AvatarNetwork.test.tsx', | ||
'packages/design-system-react/src/components/AvatarToken/AvatarToken.test.tsx', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing avatars from file ignores in eslint config, this also enables automatic linting fixes like import order
packages/design-system-react/src/components/AvatarAccount/AvatarAccount.tsx
Outdated
Show resolved
Hide resolved
packages/design-system-react/src/components/AvatarBase/AvatarBase.tsx
Outdated
Show resolved
Hide resolved
@@ -65,7 +66,7 @@ describe('AvatarFavicon', () => { | |||
<AvatarFavicon | |||
name="ACME" | |||
src={src} | |||
imageProps={{ 'data-testid': 'img', id: 'img-id' } as any} | |||
imageProps={{ 'data-testid': 'img', id: 'img-id' }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't be using a type assertion here (as any
) to bypass a TypeScript type error. The reason for this is that ComponentProps<'img'>
(the standard React type for <img>
props) does not accept custom data-*
attributes like data-testid
by default, even though they are valid HTML attributes and commonly used in testing.
This is a valid type violation because the component's imageProps
should allow test IDs and similar data-*
attributes, but the current type definition doesn't support them. To properly fix this, we are explicitly extending the imageProps
type in our avatar types.
imageProps?: ComponentProps<'img'> & { | ||
'data-testid'?: string; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
packages/design-system-react/src/components/AvatarFavicon/AvatarFavicon.tsx
Outdated
Show resolved
Hide resolved
@@ -2,6 +2,7 @@ import type { Meta, StoryObj } from '@storybook/react'; | |||
import React from 'react'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prettier fixes
variant={'Invalid' as any} | ||
avatarPropsArr={[{ foo: 'bar' } as any]} | ||
variant={'Invalid' as unknown as AvatarGroupVariant} | ||
// @ts-expect-error - invalid variant |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we are expecting an error so @ts-expect-error
is valid to ignore the type violation
@@ -1,22 +1,28 @@ | |||
import React, { useCallback } from 'react'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yarn lint:fix
automatic fixes after being removed from ignore list
@@ -65,7 +66,7 @@ describe('AvatarNetwork', () => { | |||
<AvatarNetwork | |||
name="ACME" | |||
src={src} | |||
imageProps={{ 'data-testid': 'img', id: 'img-id' } as any} | |||
imageProps={{ 'data-testid': 'img', id: 'img-id' }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same fixes for all imageProps types see this comment https://github.com/MetaMask/metamask-design-system/pull/674/files#r2094696645
14f319e
to
c6fe9b6
Compare
c6fe9b6
to
4f95d59
Compare
Description
This PR improves the Avatar components in the design-system-react package by removing ESLint ignores and fixing TypeScript type issues.
What is the reason for the change?
as any
) which can hide potential errorsWhat is the improvement/solution?
imageProps
to includedata-testid
propertyReact.forwardRef
to destructured{ forwardRef }
from ReactRelated issues
Part of: #657
Manual testing steps
Pre-merge author checklist
Pre-merge reviewer checklist