Navigation Menu

Skip to content

Commit

Permalink
feat: add react/display-name ESLint rule (#1925)
Browse files Browse the repository at this point in the history
  • Loading branch information
shleewhite committed Oct 19, 2021
1 parent 3f80fef commit 01baddc
Show file tree
Hide file tree
Showing 30 changed files with 81 additions and 4 deletions.
21 changes: 21 additions & 0 deletions .changeset/olive-wolves-invite.md
@@ -0,0 +1,21 @@
---
'@twilio-paste/badge': patch
'@twilio-paste/checkbox': patch
'@twilio-paste/combobox': patch
'@twilio-paste/disclosure': patch
'@twilio-paste/display-pill-group': patch
'@twilio-paste/form-pill-group': patch
'@twilio-paste/input': patch
'@twilio-paste/menu': patch
'@twilio-paste/modal': patch
'@twilio-paste/popover': patch
'@twilio-paste/radio-group': patch
'@twilio-paste/select': patch
'@twilio-paste/spinner': patch
'@twilio-paste/tooltip': patch
'@twilio-paste/menu-primitive': patch
'@twilio-paste/theme': patch
'@twilio-paste/core': patch
---

Add displayNames to all components
3 changes: 2 additions & 1 deletion .eslintrc.js
Expand Up @@ -7,7 +7,7 @@ module.exports = {
parserOptions: {
project: './tsconfig.json',
},
plugins: ['@typescript-eslint', 'eslint-comments', 'jest', 'promise', 'unicorn', 'emotion'],
plugins: ['@typescript-eslint', 'eslint-comments', 'jest', 'promise', 'unicorn', 'emotion', 'import'],
extends: [
'airbnb-typescript',
'plugin:@typescript-eslint/recommended',
Expand Down Expand Up @@ -87,6 +87,7 @@ module.exports = {
],
'react/jsx-curly-brace-presence': 0,
'react/jsx-props-no-spreading': 0,
'react/display-name': 2,
'no-useless-constructor': 'off',
eqeqeq: ['error', 'smart'],
'no-plusplus': 'off',
Expand Down
Expand Up @@ -35,6 +35,7 @@ jest.mock('@twilio-paste/modal-dialog-primitive', () => {
describe('Alert Dialog `element` prop', () => {
it('should set the default element prop on Alert Dialog', () => {
const {container} = render(<CustomizedAlertDialog />, {
// eslint-disable-next-line react/display-name
wrapper: ({children}) => <div id="test-container-wrapper">{children}</div>,
});
expect(screen.getByTestId('alert_dialog').getAttribute('data-paste-element')).toEqual('ALERT_DIALOG');
Expand Down
3 changes: 3 additions & 0 deletions packages/paste-core/components/badge/src/hooks.tsx
Expand Up @@ -39,6 +39,7 @@ export const useFocusableVariants = (
const buttonProps = safelySpreadProps(redactedProps, BUTTON_DENY_LIST);
return {
styleProps: {...FOCUSABLE_STYLES} as FocusableStyleProps,
// eslint-disable-next-line react/display-name
wrapper: ({children}) => (
<Button variant="reset" size="reset" type="button" {...buttonProps}>
{children}
Expand All @@ -51,6 +52,7 @@ export const useFocusableVariants = (
const anchorProps = safelySpreadProps(redactedProps, ANCHOR_DENY_LIST);
return {
styleProps: {...FOCUSABLE_STYLES} as FocusableStyleProps,
// eslint-disable-next-line react/display-name
wrapper: ({children}) => (
<Button variant="reset" size="reset" type="button" as="a" {...anchorProps}>
{children}
Expand All @@ -62,6 +64,7 @@ export const useFocusableVariants = (

return {
styleProps: {},
// eslint-disable-next-line react/display-name
wrapper: ({children}) => <>{children}</>,
spanProps: redactedProps,
};
Expand Down
2 changes: 2 additions & 0 deletions packages/paste-core/components/checkbox/src/Checkbox.tsx
Expand Up @@ -51,6 +51,8 @@ const HiddenCheckbox = React.forwardRef<HTMLInputElement, HiddenCheckboxProps>((
/>
));

HiddenCheckbox.displayName = 'HiddenCheckbox';

const CheckboxIcon: React.FC<{
indeterminate: boolean | undefined;
disabled: boolean | undefined;
Expand Down
Expand Up @@ -22,6 +22,7 @@ const getStyles = (element = 'COMBOBOX'): {[key: string]: PasteCustomCSS} => ({
[`${element}_SUFFIX`]: {backgroundColor: 'colorBackgroundSubaccount', borderRadius: 'borderRadiusCircle'},
});

// eslint-disable-next-line react/display-name
const initCustomizationWrapper = (elementName?: string | undefined): RenderOptions['wrapper'] => ({children}) => (
<CustomizationProvider
// @ts-expect-error global test variable
Expand Down
Expand Up @@ -6,4 +6,6 @@ const ComboboxInputSelect = React.forwardRef<HTMLInputElement, ComboboxProps>(({
return <InputElement paddingRight={!props.autocomplete ? 'space100' : null} type="text" ref={ref} {...props} />;
});

ComboboxInputSelect.displayName = 'ComboboxInputSelect';

export {ComboboxInputSelect};
Expand Up @@ -79,6 +79,8 @@ const StyledDisclosureHeading = React.forwardRef<HTMLDivElement, StyledDisclosur
}
);

StyledDisclosureHeading.displayName = 'StyledDisclosureHeading';

const DisclosureHeading: React.FC<DisclosureHeadingProps> = ({
children,
as,
Expand Down
Expand Up @@ -60,3 +60,5 @@ export const DisplayPill = React.forwardRef<HTMLAnchorElement, DisplayPillProps>
);
}
);

DisplayPill.displayName = 'DisplayPill';
Expand Up @@ -34,3 +34,5 @@ export const DisplayPillGroup = React.forwardRef<HTMLUListElement, DisplayPillGr
);
}
);

DisplayPillGroup.displayName = 'DisplayPillGroup';
Expand Up @@ -69,6 +69,8 @@ const FormPillStyles = React.forwardRef<HTMLElement, FormPillStylesProps>(
)
);

FormPillStyles.displayName = 'StyledFormPill';

interface FormPillProps extends CompositeStateReturn, Pick<BoxProps, 'element'> {
selected?: boolean;
children: React.ReactNode;
Expand Down Expand Up @@ -135,3 +137,5 @@ export const FormPill = React.forwardRef<HTMLElement, FormPillProps>(
);
}
);

FormPill.displayName = 'FormPill';
Expand Up @@ -27,6 +27,8 @@ const FormPillGroupStyles = React.forwardRef<HTMLUListElement, FormPillGroupProp
)
);

FormPillGroupStyles.displayName = 'StyledFormPillGroup';

/**
* FormPillGroup should be used to wrap a collection of FormPills. It should be used in conjunction with
* useFormPillGroupState hook
Expand All @@ -44,3 +46,5 @@ export const FormPillGroup = React.forwardRef<HTMLUListElement, FormPillGroupPro
</Composite>
);
});

FormPillGroup.displayName = 'FormPillGroup';
2 changes: 2 additions & 0 deletions packages/paste-core/components/input/src/Input.tsx
Expand Up @@ -88,6 +88,8 @@ export const InputElement = React.forwardRef<HTMLInputElement, InputProps>(({ele
);
});

InputElement.displayName = 'InputElement';

const Input = React.forwardRef<HTMLInputElement, InputProps>(
(
{
Expand Down
Expand Up @@ -8,6 +8,7 @@ import {initStyles, BaseMenu} from '../stories/customization.stories';

const PASTE_ELEMENT = 'data-paste-element';

// eslint-disable-next-line react/display-name
const initWrapper = (element: string): RenderOptions['wrapper'] => ({children}) => (
<CustomizationProvider
// @ts-expect-error global test variable
Expand Down
2 changes: 2 additions & 0 deletions packages/paste-core/components/menu/src/Menu.tsx
Expand Up @@ -25,6 +25,8 @@ const StyledMenu = React.forwardRef<HTMLDivElement, BoxElementProps>(({style, ..
);
});

StyledMenu.displayName = 'StyledMenu';

const Menu = React.forwardRef<HTMLDivElement, MenuProps>(({element = 'MENU', ...props}, ref) => {
return <MenuPrimitive {...props} element={element} as={StyledMenu} ref={ref} />;
});
Expand Down
2 changes: 2 additions & 0 deletions packages/paste-core/components/menu/src/MenuItem.tsx
Expand Up @@ -45,6 +45,8 @@ export const StyledMenuItem = React.forwardRef<HTMLDivElement | HTMLAnchorElemen
}
);

StyledMenuItem.displayName = 'StyledMenuItem';

const MenuItem = React.forwardRef<HTMLDivElement, MenuItemProps>(
({as = StyledMenuItem, variant: _variant, element = 'MENU_ITEM', ...props}, ref) => {
const variant = _variant || React.useContext(MenuGroupContext);
Expand Down
2 changes: 2 additions & 0 deletions packages/paste-core/components/menu/src/MenuSeparator.tsx
Expand Up @@ -8,6 +8,8 @@ const StyledMenuSeparator = React.forwardRef<HTMLHRElement, SeparatorProps>((pro
return <Separator {...props} orientation="horizontal" verticalSpacing="space40" ref={ref} />;
});

StyledMenuSeparator.displayName = 'StyledMenuSeparator';

const MenuSeparator = React.forwardRef<HTMLHRElement, MenuSeparatorProps>(
({element = 'MENU_SEPARATOR', ...props}, ref) => {
// as prop from reakit for some reason only accepts a string of `hr` but accepts components. any prevent type errors
Expand Down
2 changes: 2 additions & 0 deletions packages/paste-core/components/menu/stories/index.stories.tsx
Expand Up @@ -76,6 +76,8 @@ const PreferencesMenu = React.forwardRef<HTMLButtonElement>((props, ref) => {
);
});

PreferencesMenu.displayName = 'PreferencesMenu';

const SubMenu: React.FC = () => {
const menu = useMenuState();
return (
Expand Down
Expand Up @@ -97,6 +97,7 @@ describe('Modal Customization', () => {
describe('Custom styles', () => {
it('Should apply correct style rules to normal size variant', () => {
render(<BaseModal size="default" />, {
// eslint-disable-next-line react/display-name
wrapper: ({children}) => (
<CustomizationProvider
// @ts-expect-error global test variable
Expand Down Expand Up @@ -143,6 +144,7 @@ describe('Modal Customization', () => {

it('Should apply correct style rules to wide size variant', () => {
render(<BaseModal size="wide" />, {
// eslint-disable-next-line react/display-name
wrapper: ({children}) => (
<CustomizationProvider
// @ts-expect-error global test variable
Expand Down
2 changes: 2 additions & 0 deletions packages/paste-core/components/popover/src/Popover.tsx
Expand Up @@ -28,6 +28,8 @@ const StyledPopover = React.forwardRef<HTMLDivElement, BoxProps>(({style, ...pro
);
});

StyledPopover.displayName = 'StyledPopover';

export interface PopoverProps extends Pick<BoxProps, 'element'> {
'aria-label': string;
children: React.ReactNode;
Expand Down
Expand Up @@ -27,6 +27,8 @@ const BasePopoverContainer = React.forwardRef<HTMLDivElement, PopoverContainerPr
}
);

BasePopoverContainer.displayName = 'BasePopoverContainer';

const PopoverContainer = React.memo(BasePopoverContainer);

PopoverContainer.displayName = 'PopoverContainer';
Expand Down
2 changes: 2 additions & 0 deletions packages/paste-core/components/radio-group/src/Radio.tsx
Expand Up @@ -45,6 +45,8 @@ const HiddenRadio = React.forwardRef<HTMLInputElement, HiddenRadioProps>((props,
/>
));

HiddenRadio.displayName = 'HiddenRadio';

const Radio = React.forwardRef<HTMLInputElement, RadioProps>(
({id, name, element = 'RADIO', value, checked, disabled, hasError, onChange, children, helpText, ...props}, ref) => {
const helpTextId = useUID();
Expand Down
2 changes: 2 additions & 0 deletions packages/paste-core/components/select/src/Select.tsx
Expand Up @@ -60,6 +60,8 @@ export const SelectElement = React.forwardRef<HTMLSelectElement, SelectProps>(
}
);

SelectElement.displayName = 'SelectElement';

const Select = React.forwardRef<HTMLSelectElement, SelectProps>(
(
{disabled, element = 'SELECT', hasError, insertBefore, insertAfter, children, size, multiple, variant, ...props},
Expand Down
Expand Up @@ -9,6 +9,7 @@ import {Spinner} from '../src';
// @ts-ignore typescript doesn't like js imports
import axe from '../../../../../.jest/axe-helper';

// eslint-disable-next-line react/display-name
const TestWrapper = (elements?: Record<string, any>): RenderOptions['wrapper'] => ({children}) => (
<CustomizationProvider
// @ts-expect-error global test variable
Expand Down Expand Up @@ -106,6 +107,7 @@ describe('Spinner', () => {
describe('Accessibility', () => {
it('Should have no accessibility violations', async () => {
const {container} = render(<Spinner title="Loading" decorative />, {
// eslint-disable-next-line react/display-name
wrapper: ({children}) => <Theme.Provider theme="default">{children}</Theme.Provider>,
});
const results = await axe(container);
Expand Down
2 changes: 2 additions & 0 deletions packages/paste-core/components/spinner/src/index.tsx
Expand Up @@ -53,6 +53,8 @@ const Spinner = React.forwardRef<HTMLDivElement, SpinnerProps>(
}
);

Spinner.displayName = 'Spinner';

Spinner.propTypes = {
title: PropTypes.string.isRequired,
delay: PropTypes.number,
Expand Down
2 changes: 2 additions & 0 deletions packages/paste-core/components/tooltip/src/index.tsx
Expand Up @@ -32,6 +32,8 @@ const StyledTooltip = React.forwardRef<HTMLDivElement, BoxProps>(({style, elemen
);
});

StyledTooltip.displayName = 'StyledTooltip';

export interface TooltipStateReturn extends TooltipPrimitiveStateReturn {
[key: string]: any;
}
Expand Down
Expand Up @@ -4,9 +4,9 @@ import {
MenuPrimitive,
MenuPrimitiveItem,
MenuPrimitiveButton,
MenuPrimitiveButtonProps,
MenuPrimitiveSeparator,
} from '../src';
import type {MenuPrimitiveButtonProps} from '../src';

const PreferencesMenu = React.forwardRef<HTMLButtonElement, MenuPrimitiveButtonProps>((props, ref) => {
const menu = useMenuPrimitiveState();
Expand All @@ -27,6 +27,8 @@ const PreferencesMenu = React.forwardRef<HTMLButtonElement, MenuPrimitiveButtonP
);
});

PreferencesMenu.displayName = 'PreferencesMenu';

// eslint-disable-next-line import/no-default-export
export default {
title: 'Primitives/Menu',
Expand Down
3 changes: 2 additions & 1 deletion packages/paste-theme-designer/.eslintrc.json
Expand Up @@ -3,6 +3,7 @@
"rules": {
"import/prefer-default-export": "off",
"import/no-default-export": "off",
"react/react-in-jsx-scope": "off"
"react/react-in-jsx-scope": "off",
"react/display-name": 0
}
}
Expand Up @@ -6,6 +6,7 @@ import {useThemeContrastCheck} from '../src/useThemeContrastCheck';
describe('useThemeContrastCheck', () => {
test('should return the results of the contrast check when inside a theme', () => {
const {result} = renderHook(() => useThemeContrastCheck(), {
// eslint-disable-next-line react/display-name
wrapper: (props) => (
<ThemeProvider
theme={{
Expand Down
3 changes: 2 additions & 1 deletion packages/paste-website/.eslintrc
@@ -1,6 +1,7 @@
{
"extends": "../../.eslintrc.js",
"rules": {
"import/no-default-export": "off"
"import/no-default-export": "off",
"react/display-name": 0
}
}

0 comments on commit 01baddc

Please sign in to comment.