From 2faffc90e410456f4487eafa92d2192c8785bc99 Mon Sep 17 00:00:00 2001 From: YuanboXue-Amber Date: Thu, 11 Jan 2024 17:27:20 +0100 Subject: [PATCH 01/31] wip lint rule --- packages/eslint-plugin/src/configs/react.js | 6 +++ packages/eslint-plugin/src/index.js | 1 + .../rules/consistent-callback-type/index.js | 52 +++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 packages/eslint-plugin/src/rules/consistent-callback-type/index.js diff --git a/packages/eslint-plugin/src/configs/react.js b/packages/eslint-plugin/src/configs/react.js index 6f6f305ebfe43..72dd35fd7d019 100644 --- a/packages/eslint-plugin/src/configs/react.js +++ b/packages/eslint-plugin/src/configs/react.js @@ -58,5 +58,11 @@ module.exports = { 'react/jsx-no-bind': 'off', }, }, + { + files: ['**/components/**/*.types.ts'], + rules: { + '@fluentui/consistent-callback-type': 'error', + }, + }, ], }; diff --git a/packages/eslint-plugin/src/index.js b/packages/eslint-plugin/src/index.js index eae81f75a8452..ceccdd4dde22b 100644 --- a/packages/eslint-plugin/src/index.js +++ b/packages/eslint-plugin/src/index.js @@ -19,6 +19,7 @@ module.exports = { 'no-visibility-modifiers': require('./rules/no-visibility-modifiers'), 'no-restricted-imports': require('./rules/no-restricted-imports'), 'no-context-default-value': require('./rules/no-context-default-value'), + 'consistent-callback-type': require('./rules/consistent-callback-type'), }, // Not a standard eslint thing, just exported for convenience diff --git a/packages/eslint-plugin/src/rules/consistent-callback-type/index.js b/packages/eslint-plugin/src/rules/consistent-callback-type/index.js new file mode 100644 index 0000000000000..668bf1d7e72e7 --- /dev/null +++ b/packages/eslint-plugin/src/rules/consistent-callback-type/index.js @@ -0,0 +1,52 @@ +// @ts-check +const { AST_NODE_TYPES } = require('@typescript-eslint/experimental-utils'); +const createRule = require('../../utils/createRule'); + +module.exports = createRule({ + name: 'consistent-callback-type', + meta: { + type: 'problem', + docs: { + description: 'Enforce callback props to be typed with `EventHandler`', + category: 'Best Practices', + recommended: 'error', + }, + messages: { + invalidType: 'callback props should be typed with EventHandler', + }, + schema: [], + }, + defaultOptions: [], + create(context) { + return { + // eslint-disable-next-line @typescript-eslint/naming-convention + 'TSTypeAliasDeclaration[id.name=/.*Props$/] TSTypeLiteral': function (node) { + // @ts-ignore + node.members.forEach(member => { + if ( + member.type === 'TSPropertySignature' && + member.key.type === AST_NODE_TYPES.Identifier && + member.key.name.startsWith('on') + ) { + const typeAnnotation = member.typeAnnotation?.typeAnnotation; + // Check if typeAnnotation is of type EventHandler + if ( + !( + typeAnnotation && + typeAnnotation.type === 'TSTypeReference' && + typeAnnotation.typeName.type === AST_NODE_TYPES.Identifier && + typeAnnotation.typeName.name === 'EventHandler' && + typeAnnotation.typeParameters + ) + ) { + context.report({ + node: member, + messageId: 'invalidType', + }); + } + } + }); + }, + }; + }, +}); From 8836d621eec21afef6958240ab60177cab9090e7 Mon Sep 17 00:00:00 2001 From: YuanboXue-Amber Date: Fri, 12 Jan 2024 11:38:58 +0100 Subject: [PATCH 02/31] add eslint disable for existing callbacks --- .../src/components/Accordion/Accordion.types.ts | 1 + .../react-card/src/components/Card/Card.types.ts | 1 + .../src/components/Checkbox/Checkbox.types.ts | 1 + .../src/components/DatePicker/DatePicker.types.ts | 3 +++ .../react-dialog/src/components/Dialog/Dialog.types.ts | 1 + .../react-input/src/components/Input/Input.types.ts | 7 ++++++- .../react-menu/src/components/Menu/Menu.types.ts | 1 + .../react-menu/src/components/MenuList/MenuList.types.ts | 1 + .../src/components/MenuTrigger/MenuTrigger.types.ts | 4 ++++ .../src/components/List/List/List.types.ts | 1 + .../react-popover/src/components/Popover/Popover.types.ts | 1 + .../src/components/PopoverTrigger/PopoverTrigger.types.ts | 3 +++ .../react-radio/src/components/Radio/Radio.types.ts | 1 + .../src/components/RadioGroup/RadioGroup.types.ts | 1 + .../src/components/Rating/Rating.types.ts | 1 + .../react-select/src/components/Select/Select.types.ts | 1 + .../react-slider/src/components/Slider/Slider.types.ts | 1 + .../src/components/SpinButton/SpinButton.types.ts | 1 + .../react-switch/src/components/Switch/Switch.types.ts | 1 + .../react-table/src/components/DataGrid/DataGrid.types.ts | 3 +++ .../react-tabs/src/components/TabList/TabList.types.ts | 1 + .../react-tags/src/components/TagGroup/TagGroup.types.ts | 1 + .../components/TeachingPopover/TeachingPopover.types.ts | 2 ++ .../src/components/Textarea/Textarea.types.ts | 1 + .../src/components/TimePicker/TimePicker.types.ts | 1 + .../react-toolbar/src/components/Toolbar/Toolbar.types.ts | 1 + .../react-tooltip/src/components/Tooltip/Tooltip.types.ts | 1 + .../react-tree/src/components/TreeItem/TreeItem.types.ts | 1 + .../src/components/Virtualizer/Virtualizer.types.ts | 1 + 29 files changed, 44 insertions(+), 1 deletion(-) diff --git a/packages/react-components/react-accordion/src/components/Accordion/Accordion.types.ts b/packages/react-components/react-accordion/src/components/Accordion/Accordion.types.ts index 554016e527ba7..967182a650378 100644 --- a/packages/react-components/react-accordion/src/components/Accordion/Accordion.types.ts +++ b/packages/react-components/react-accordion/src/components/Accordion/Accordion.types.ts @@ -49,6 +49,7 @@ export type AccordionProps = ComponentProps; /** diff --git a/packages/react-components/react-card/src/components/Card/Card.types.ts b/packages/react-components/react-card/src/components/Card/Card.types.ts index 18ee8b4eae446..d9896cd3e8c36 100644 --- a/packages/react-components/react-card/src/components/Card/Card.types.ts +++ b/packages/react-components/react-card/src/components/Card/Card.types.ts @@ -124,6 +124,7 @@ export type CardProps = ComponentProps & { /** * Callback to be called when the selected state value changes. */ + // eslint-disable-next-line @fluentui/consistent-callback-type onSelectionChange?: (event: CardOnSelectionChangeEvent, data: CardOnSelectData) => void; }; diff --git a/packages/react-components/react-checkbox/src/components/Checkbox/Checkbox.types.ts b/packages/react-components/react-checkbox/src/components/Checkbox/Checkbox.types.ts index acb4001a98624..f3a4caf4a3534 100644 --- a/packages/react-components/react-checkbox/src/components/Checkbox/Checkbox.types.ts +++ b/packages/react-components/react-checkbox/src/components/Checkbox/Checkbox.types.ts @@ -64,6 +64,7 @@ export type CheckboxProps = Omit< /** * Callback to be called when the checked state value changes. */ + // eslint-disable-next-line @fluentui/consistent-callback-type onChange?: (ev: React.ChangeEvent, data: CheckboxOnChangeData) => void; /** diff --git a/packages/react-components/react-datepicker-compat/src/components/DatePicker/DatePicker.types.ts b/packages/react-components/react-datepicker-compat/src/components/DatePicker/DatePicker.types.ts index bffab2aa1118c..c12c9ae046954 100644 --- a/packages/react-components/react-datepicker-compat/src/components/DatePicker/DatePicker.types.ts +++ b/packages/react-components/react-datepicker-compat/src/components/DatePicker/DatePicker.types.ts @@ -16,6 +16,7 @@ export type DatePickerProps = Omit>, 'de /** * Callback issued when a date is selected */ + // eslint-disable-next-line @fluentui/consistent-callback-type onSelectDate?: (date: Date | null | undefined) => void; /** @@ -84,11 +85,13 @@ export type DatePickerProps = Omit>, 'de /** * Callback to run when the DatePicker's open state changes */ + // eslint-disable-next-line @fluentui/consistent-callback-type onOpenChange?: (open: boolean) => void; /** * Callback to run after the DatePicker's input has been validated */ + // eslint-disable-next-line @fluentui/consistent-callback-type onValidationResult?: (data: DatePickerValidationResultData) => void; /** diff --git a/packages/react-components/react-dialog/src/components/Dialog/Dialog.types.ts b/packages/react-components/react-dialog/src/components/Dialog/Dialog.types.ts index e91b0e3d1ba22..b0ed1f3dc1e7e 100644 --- a/packages/react-components/react-dialog/src/components/Dialog/Dialog.types.ts +++ b/packages/react-components/react-dialog/src/components/Dialog/Dialog.types.ts @@ -81,6 +81,7 @@ export type DialogProps = ComponentProps> & { * @param data - A data object with relevant information, * such as open value and type of interaction that created the event */ + // eslint-disable-next-line @fluentui/consistent-callback-type onOpenChange?: DialogOpenChangeEventHandler; /** * Can contain two children including {@link DialogTrigger} and {@link DialogSurface}. diff --git a/packages/react-components/react-input/src/components/Input/Input.types.ts b/packages/react-components/react-input/src/components/Input/Input.types.ts index 79a8a8500f4ae..0e58bd1ee3644 100644 --- a/packages/react-components/react-input/src/components/Input/Input.types.ts +++ b/packages/react-components/react-input/src/components/Input/Input.types.ts @@ -1,5 +1,5 @@ import * as React from 'react'; -import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities'; +import type { ComponentProps, ComponentState, EventData, EventHandler, Slot } from '@fluentui/react-utilities'; export type InputSlots = { /** @@ -27,6 +27,8 @@ export type InputSlots = { contentAfter?: Slot<'span'>; }; +type OnOpenChangeData = EventData<'click', React.MouseEvent>; + export type InputProps = Omit< ComponentProps, 'input'>, // `children` is unsupported. The rest of these native props have customized definitions. @@ -77,8 +79,11 @@ export type InputProps = Omit< /** * Called when the user changes the input's value. */ + // eslint-disable-next-line @fluentui/consistent-callback-type onChange?: (ev: React.ChangeEvent, data: InputOnChangeData) => void; + onChange2?: EventHandler; + /** * An input can have different text-based [types](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input#input_types) * based on the type of value the user will enter. diff --git a/packages/react-components/react-menu/src/components/Menu/Menu.types.ts b/packages/react-components/react-menu/src/components/Menu/Menu.types.ts index dcadc40dd74f8..1cf08fa0dc84c 100644 --- a/packages/react-components/react-menu/src/components/Menu/Menu.types.ts +++ b/packages/react-components/react-menu/src/components/Menu/Menu.types.ts @@ -40,6 +40,7 @@ export type MenuProps = ComponentProps & * Call back when the component requests to change value * The `open` value is used as a hint when directly controlling the component */ + // eslint-disable-next-line @fluentui/consistent-callback-type onOpenChange?: (e: MenuOpenEvent, data: MenuOpenChangeData) => void; /** diff --git a/packages/react-components/react-menu/src/components/MenuList/MenuList.types.ts b/packages/react-components/react-menu/src/components/MenuList/MenuList.types.ts index 7e469e730f611..ca4f8d00ce843 100644 --- a/packages/react-components/react-menu/src/components/MenuList/MenuList.types.ts +++ b/packages/react-components/react-menu/src/components/MenuList/MenuList.types.ts @@ -43,6 +43,7 @@ export type MenuListProps = ComponentProps & { * @param event - React's original SyntheticEvent * @param data - A data object with relevant information */ + // eslint-disable-next-line @fluentui/consistent-callback-type onCheckedValueChange?: (e: MenuCheckedValueChangeEvent, data: MenuCheckedValueChangeData) => void; }; diff --git a/packages/react-components/react-menu/src/components/MenuTrigger/MenuTrigger.types.ts b/packages/react-components/react-menu/src/components/MenuTrigger/MenuTrigger.types.ts index c8a78b839648e..db15c3b18cbdb 100644 --- a/packages/react-components/react-menu/src/components/MenuTrigger/MenuTrigger.types.ts +++ b/packages/react-components/react-menu/src/components/MenuTrigger/MenuTrigger.types.ts @@ -20,9 +20,13 @@ export type MenuTriggerChildProps; + // eslint-disable-next-line @fluentui/consistent-callback-type onMouseEnter: React.MouseEventHandler; + // eslint-disable-next-line @fluentui/consistent-callback-type onMouseLeave: React.MouseEventHandler; + // eslint-disable-next-line @fluentui/consistent-callback-type onMouseMove: React.MouseEventHandler; + // eslint-disable-next-line @fluentui/consistent-callback-type onContextMenu: React.MouseEventHandler; } >; diff --git a/packages/react-components/react-migration-v0-v9/src/components/List/List/List.types.ts b/packages/react-components/react-migration-v0-v9/src/components/List/List/List.types.ts index b0fd34fc871e2..5d4ac44962b01 100644 --- a/packages/react-components/react-migration-v0-v9/src/components/List/List/List.types.ts +++ b/packages/react-components/react-migration-v0-v9/src/components/List/List/List.types.ts @@ -53,6 +53,7 @@ export type ListProps = ComponentProps & { /** * Callback for selection change events, used for both controlled and uncontrolled (as notification) */ + // eslint-disable-next-line @fluentui/consistent-callback-type onSelectionChange?: (event: React.SyntheticEvent, data: { selectedItems: SelectionItemId[] }) => void; /** diff --git a/packages/react-components/react-popover/src/components/Popover/Popover.types.ts b/packages/react-components/react-popover/src/components/Popover/Popover.types.ts index 65b08a76a2dfe..7671600f89b97 100644 --- a/packages/react-components/react-popover/src/components/Popover/Popover.types.ts +++ b/packages/react-components/react-popover/src/components/Popover/Popover.types.ts @@ -64,6 +64,7 @@ export type PopoverProps = Pick & { * Call back when the component requests to change value * The `open` value is used as a hint when directly controlling the component */ + // eslint-disable-next-line @fluentui/consistent-callback-type onOpenChange?: (e: OpenPopoverEvents, data: OnOpenChangeData) => void; /** diff --git a/packages/react-components/react-popover/src/components/PopoverTrigger/PopoverTrigger.types.ts b/packages/react-components/react-popover/src/components/PopoverTrigger/PopoverTrigger.types.ts index 918cf0687646c..e8df2197e6c35 100644 --- a/packages/react-components/react-popover/src/components/PopoverTrigger/PopoverTrigger.types.ts +++ b/packages/react-components/react-popover/src/components/PopoverTrigger/PopoverTrigger.types.ts @@ -28,8 +28,11 @@ export type PopoverTriggerChildProps; + // eslint-disable-next-line @fluentui/consistent-callback-type onMouseEnter: React.MouseEventHandler; + // eslint-disable-next-line @fluentui/consistent-callback-type onMouseLeave: React.MouseEventHandler; + // eslint-disable-next-line @fluentui/consistent-callback-type onContextMenu: React.MouseEventHandler; } >; diff --git a/packages/react-components/react-radio/src/components/Radio/Radio.types.ts b/packages/react-components/react-radio/src/components/Radio/Radio.types.ts index 38df20cddb08e..437a8366afef7 100644 --- a/packages/react-components/react-radio/src/components/Radio/Radio.types.ts +++ b/packages/react-components/react-radio/src/components/Radio/Radio.types.ts @@ -60,6 +60,7 @@ export type RadioProps = Omit, 'input'>, 'onC * **Note:** `onChange` is NOT called when this Radio is deselected. * Use RadioGroup's `onChange` event to determine when the selection in the group changes. */ + // eslint-disable-next-line @fluentui/consistent-callback-type onChange?: (ev: React.ChangeEvent, data: RadioOnChangeData) => void; }; diff --git a/packages/react-components/react-radio/src/components/RadioGroup/RadioGroup.types.ts b/packages/react-components/react-radio/src/components/RadioGroup/RadioGroup.types.ts index 02cf82774dde7..b990a815e5e96 100644 --- a/packages/react-components/react-radio/src/components/RadioGroup/RadioGroup.types.ts +++ b/packages/react-components/react-radio/src/components/RadioGroup/RadioGroup.types.ts @@ -33,6 +33,7 @@ export type RadioGroupProps = Omit>, 'on /** * Callback when the selected Radio item changes. */ + // eslint-disable-next-line @fluentui/consistent-callback-type onChange?: (ev: React.FormEvent, data: RadioGroupOnChangeData) => void; /** diff --git a/packages/react-components/react-rating-preview/src/components/Rating/Rating.types.ts b/packages/react-components/react-rating-preview/src/components/Rating/Rating.types.ts index 0bfd260e09eda..dfe5e413342da 100644 --- a/packages/react-components/react-rating-preview/src/components/Rating/Rating.types.ts +++ b/packages/react-components/react-rating-preview/src/components/Rating/Rating.types.ts @@ -46,6 +46,7 @@ export type RatingProps = ComponentProps & { /** * Callback when the rating value is changed by the user. */ + // eslint-disable-next-line @fluentui/consistent-callback-type onChange?: (ev: React.SyntheticEvent | Event, data: RatingOnChangeData) => void; /** * Sets the precision to allow half-filled shapes in Rating diff --git a/packages/react-components/react-select/src/components/Select/Select.types.ts b/packages/react-components/react-select/src/components/Select/Select.types.ts index 56f39e1e50075..49f7d22a1a6fe 100644 --- a/packages/react-components/react-select/src/components/Select/Select.types.ts +++ b/packages/react-components/react-select/src/components/Select/Select.types.ts @@ -27,6 +27,7 @@ export type SelectProps = Omit, 'select'>, ' /** * Called when the user changes the select element's value by selecting an option. */ + // eslint-disable-next-line @fluentui/consistent-callback-type onChange?: (ev: React.ChangeEvent, data: SelectOnChangeData) => void; /** diff --git a/packages/react-components/react-slider/src/components/Slider/Slider.types.ts b/packages/react-components/react-slider/src/components/Slider/Slider.types.ts index 078192342a05a..fd3c63d0c8653 100644 --- a/packages/react-components/react-slider/src/components/Slider/Slider.types.ts +++ b/packages/react-components/react-slider/src/components/Slider/Slider.types.ts @@ -94,6 +94,7 @@ export type SliderProps = Omit< /** * Triggers a callback when the value has been changed. This will be called on every individual step. */ + // eslint-disable-next-line @fluentui/consistent-callback-type onChange?: (ev: React.ChangeEvent, data: SliderOnChangeData) => void; }; diff --git a/packages/react-components/react-spinbutton/src/components/SpinButton/SpinButton.types.ts b/packages/react-components/react-spinbutton/src/components/SpinButton/SpinButton.types.ts index 0f806769f26d3..76e13f3789c01 100644 --- a/packages/react-components/react-spinbutton/src/components/SpinButton/SpinButton.types.ts +++ b/packages/react-components/react-spinbutton/src/components/SpinButton/SpinButton.types.ts @@ -80,6 +80,7 @@ export type SpinButtonProps = Omit< * - User *commits* edits to the input text by focusing away (blurring) or pressing enter. * Note that this is NOT called for every key press while the user is editing. */ + // eslint-disable-next-line @fluentui/consistent-callback-type onChange?: (event: SpinButtonChangeEvent, data: SpinButtonOnChangeData) => void; /** diff --git a/packages/react-components/react-switch/src/components/Switch/Switch.types.ts b/packages/react-components/react-switch/src/components/Switch/Switch.types.ts index 14eaba29dd9b3..7a1cf9a994888 100644 --- a/packages/react-components/react-switch/src/components/Switch/Switch.types.ts +++ b/packages/react-components/react-switch/src/components/Switch/Switch.types.ts @@ -68,6 +68,7 @@ export type SwitchProps = Omit< /** * Callback to be called when the checked state value changes. */ + // eslint-disable-next-line @fluentui/consistent-callback-type onChange?: (ev: React.ChangeEvent, data: SwitchOnChangeData) => void; }; diff --git a/packages/react-components/react-table/src/components/DataGrid/DataGrid.types.ts b/packages/react-components/react-table/src/components/DataGrid/DataGrid.types.ts index d68391be117d3..5b497af44542e 100644 --- a/packages/react-components/react-table/src/components/DataGrid/DataGrid.types.ts +++ b/packages/react-components/react-table/src/components/DataGrid/DataGrid.types.ts @@ -64,7 +64,9 @@ export type DataGridProps = TableProps & Pick, 'focusMode' | 'subtleSelection' | 'selectionAppearance' | 'resizableColumns'> & Pick & Pick & { + // eslint-disable-next-line @fluentui/consistent-callback-type onSortChange?: (e: React.MouseEvent, sortState: SortState) => void; + // eslint-disable-next-line @fluentui/consistent-callback-type onSelectionChange?: (e: React.MouseEvent | React.KeyboardEvent, data: OnSelectionChangeData) => void; /** * Enables row selection and sets the selection mode @@ -78,6 +80,7 @@ export type DataGridProps = TableProps & /** * A callback triggered when a column is resized. */ + // eslint-disable-next-line @fluentui/consistent-callback-type onColumnResize?: ( e: KeyboardEvent | TouchEvent | MouseEvent | undefined, data: { columnId: TableColumnId; width: number }, diff --git a/packages/react-components/react-tabs/src/components/TabList/TabList.types.ts b/packages/react-components/react-tabs/src/components/TabList/TabList.types.ts index a184ef4f67c2b..4b65e4caceaa4 100644 --- a/packages/react-components/react-tabs/src/components/TabList/TabList.types.ts +++ b/packages/react-components/react-tabs/src/components/TabList/TabList.types.ts @@ -71,6 +71,7 @@ export type TabListProps = ComponentProps & { /** * Raised when a tab is selected. */ + // eslint-disable-next-line @fluentui/consistent-callback-type onTabSelect?: SelectTabEventHandler; /** diff --git a/packages/react-components/react-tags/src/components/TagGroup/TagGroup.types.ts b/packages/react-components/react-tags/src/components/TagGroup/TagGroup.types.ts index 35816a321eb50..0f7ed579364f3 100644 --- a/packages/react-components/react-tags/src/components/TagGroup/TagGroup.types.ts +++ b/packages/react-components/react-tags/src/components/TagGroup/TagGroup.types.ts @@ -17,6 +17,7 @@ export type TagGroupProps = ComponentProps & { /** * Callback for when a tag is dismissed */ + // eslint-disable-next-line @fluentui/consistent-callback-type onDismiss?: TagDismissHandler; size?: TagSize; diff --git a/packages/react-components/react-teaching-popover-preview/src/components/TeachingPopover/TeachingPopover.types.ts b/packages/react-components/react-teaching-popover-preview/src/components/TeachingPopover/TeachingPopover.types.ts index 619e3e624a5e6..cfd04de5d11ec 100644 --- a/packages/react-components/react-teaching-popover-preview/src/components/TeachingPopover/TeachingPopover.types.ts +++ b/packages/react-components/react-teaching-popover-preview/src/components/TeachingPopover/TeachingPopover.types.ts @@ -17,6 +17,7 @@ export type TeachingPopoverProps = Omit & { /** * Callback to notify a page change (can be used to update 'currentPage' externally). */ + // eslint-disable-next-line @fluentui/consistent-callback-type onPageChange?: ( event: React.MouseEvent, data: TeachingPopoverPageChangeData, @@ -24,6 +25,7 @@ export type TeachingPopoverProps = Omit & { /** * Callback to notify when the final button step of a carousel has been activated. */ + // eslint-disable-next-line @fluentui/consistent-callback-type onFinish?: (event: React.MouseEvent) => void; /** * The appearance property (extended from popover, but removed 'inverted'). diff --git a/packages/react-components/react-textarea/src/components/Textarea/Textarea.types.ts b/packages/react-components/react-textarea/src/components/Textarea/Textarea.types.ts index c9b28eaab9442..807db1c79bcd2 100644 --- a/packages/react-components/react-textarea/src/components/Textarea/Textarea.types.ts +++ b/packages/react-components/react-textarea/src/components/Textarea/Textarea.types.ts @@ -40,6 +40,7 @@ export type TextareaProps = Omit< /** * Callback for when the user changes the value. */ + // eslint-disable-next-line @fluentui/consistent-callback-type onChange?: (ev: React.ChangeEvent, data: TextareaOnChangeData) => void; /** diff --git a/packages/react-components/react-timepicker-compat/src/components/TimePicker/TimePicker.types.ts b/packages/react-components/react-timepicker-compat/src/components/TimePicker/TimePicker.types.ts index 684feac8813fb..543ba25096e67 100644 --- a/packages/react-components/react-timepicker-compat/src/components/TimePicker/TimePicker.types.ts +++ b/packages/react-components/react-timepicker-compat/src/components/TimePicker/TimePicker.types.ts @@ -145,6 +145,7 @@ export type TimePickerProps = Omit, 'input /** * Callback for when a time selection is made. */ + // eslint-disable-next-line @fluentui/consistent-callback-type onTimeChange?: (event: TimeSelectionEvents, data: TimeSelectionData) => void; /** diff --git a/packages/react-components/react-toolbar/src/components/Toolbar/Toolbar.types.ts b/packages/react-components/react-toolbar/src/components/Toolbar/Toolbar.types.ts index 95a84823d3fb2..2eec29f78f7c9 100644 --- a/packages/react-components/react-toolbar/src/components/Toolbar/Toolbar.types.ts +++ b/packages/react-components/react-toolbar/src/components/Toolbar/Toolbar.types.ts @@ -47,6 +47,7 @@ export type ToolbarProps = ComponentProps & { * @param event - React's original SyntheticEvent * @param data - A data object with relevant information */ + // eslint-disable-next-line @fluentui/consistent-callback-type onCheckedValueChange?: (e: ToolbarCheckedValueChangeEvent, data: ToolbarCheckedValueChangeData) => void; }; diff --git a/packages/react-components/react-tooltip/src/components/Tooltip/Tooltip.types.ts b/packages/react-components/react-tooltip/src/components/Tooltip/Tooltip.types.ts index c09590c3e92b7..6edf9cac03a42 100644 --- a/packages/react-components/react-tooltip/src/components/Tooltip/Tooltip.types.ts +++ b/packages/react-components/react-tooltip/src/components/Tooltip/Tooltip.types.ts @@ -63,6 +63,7 @@ export type TooltipProps = ComponentProps & * **Note**: for backwards compatibility, `event` will be undefined if this was triggered by a keyboard event on * the document element. Use `data.documentKeyboardEvent` if the keyboard event object is needed. */ + // eslint-disable-next-line @fluentui/consistent-callback-type onVisibleChange?: ( event: React.PointerEvent | React.FocusEvent | undefined, data: OnVisibleChangeData, diff --git a/packages/react-components/react-tree/src/components/TreeItem/TreeItem.types.ts b/packages/react-components/react-tree/src/components/TreeItem/TreeItem.types.ts index 38a53044062ec..bdeee481daf7f 100644 --- a/packages/react-components/react-tree/src/components/TreeItem/TreeItem.types.ts +++ b/packages/react-components/react-tree/src/components/TreeItem/TreeItem.types.ts @@ -54,6 +54,7 @@ export type TreeItemProps = ComponentProps> & { * NOTE: controlling the open state of a tree item will not affect the open state of its children */ open?: boolean; + // eslint-disable-next-line @fluentui/consistent-callback-type onOpenChange?: (e: TreeItemOpenChangeEvent, data: TreeItemOpenChangeData) => void; /** * This property is inferred through context on a nested tree, and required for a flat tree. diff --git a/packages/react-components/react-virtualizer/src/components/Virtualizer/Virtualizer.types.ts b/packages/react-components/react-virtualizer/src/components/Virtualizer/Virtualizer.types.ts index ae78857259718..682265f5ffff3 100644 --- a/packages/react-components/react-virtualizer/src/components/Virtualizer/Virtualizer.types.ts +++ b/packages/react-components/react-virtualizer/src/components/Virtualizer/Virtualizer.types.ts @@ -159,6 +159,7 @@ export type VirtualizerConfigProps = { /** * Callback for notifying when a flagged index has been rendered */ + // eslint-disable-next-line @fluentui/consistent-callback-type onRenderedFlaggedIndex?: (index: number) => void; /* From 69dc50399aee7c34b18d732160bd81dd2320167b Mon Sep 17 00:00:00 2001 From: YuanboXue-Amber Date: Fri, 12 Jan 2024 12:08:27 +0100 Subject: [PATCH 03/31] remove testing code in input.type.ts --- .../react-input/src/components/Input/Input.types.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/react-components/react-input/src/components/Input/Input.types.ts b/packages/react-components/react-input/src/components/Input/Input.types.ts index 0e58bd1ee3644..1280da89cd44d 100644 --- a/packages/react-components/react-input/src/components/Input/Input.types.ts +++ b/packages/react-components/react-input/src/components/Input/Input.types.ts @@ -1,5 +1,5 @@ import * as React from 'react'; -import type { ComponentProps, ComponentState, EventData, EventHandler, Slot } from '@fluentui/react-utilities'; +import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities'; export type InputSlots = { /** @@ -27,8 +27,6 @@ export type InputSlots = { contentAfter?: Slot<'span'>; }; -type OnOpenChangeData = EventData<'click', React.MouseEvent>; - export type InputProps = Omit< ComponentProps, 'input'>, // `children` is unsupported. The rest of these native props have customized definitions. @@ -82,8 +80,6 @@ export type InputProps = Omit< // eslint-disable-next-line @fluentui/consistent-callback-type onChange?: (ev: React.ChangeEvent, data: InputOnChangeData) => void; - onChange2?: EventHandler; - /** * An input can have different text-based [types](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input#input_types) * based on the type of value the user will enter. From 135cce927b10ae97583d32cd0917632fa1eceb05 Mon Sep 17 00:00:00 2001 From: YuanboXue-Amber Date: Fri, 12 Jan 2024 14:20:15 +0100 Subject: [PATCH 04/31] changelog --- ...eslint-plugin-bc33d2c9-cfd7-44bb-a8de-04bf3fb7b14f.json | 7 +++++++ ...act-accordion-74970004-bc83-461d-a43c-3758c0c429b5.json | 7 +++++++ ...ui-react-card-26618c50-93dc-4116-8d0a-90c4f1566875.json | 7 +++++++ ...eact-checkbox-61435c59-fe06-4b4a-a1b1-f0a318fd8c87.json | 7 +++++++ ...picker-compat-583ce0d7-9840-431b-8056-91f5991ef562.json | 7 +++++++ ...-react-dialog-285527f9-bb4d-41d5-b6f4-1b57ab4f8ced.json | 7 +++++++ ...i-react-input-b337e912-5bde-4162-9a26-201fcc5347ee.json | 7 +++++++ ...ui-react-menu-ba500681-bcdd-4437-aaa3-002bf617b009.json | 7 +++++++ ...gration-v0-v9-2af1c3a5-5f09-4ead-80b6-c7370457d6c9.json | 7 +++++++ ...react-popover-6de680db-0afe-4131-a96c-9ef10d14c997.json | 7 +++++++ ...i-react-radio-6a06b070-1df9-4416-92fd-8f4de71b1759.json | 7 +++++++ ...ating-preview-be1073d4-f244-4c68-8db6-12d4e897bc68.json | 7 +++++++ ...-react-select-6c0bfff0-b7e4-46a6-a4d3-ca79eada2d17.json | 7 +++++++ ...-react-slider-a79b527f-6529-4b9e-92ef-fca325b162db.json | 7 +++++++ ...ct-spinbutton-2becfac8-c8ca-4ecb-b961-dfad3e44f878.json | 7 +++++++ ...-react-switch-a4f6ce47-4fdb-421d-8229-ec4e30dd9d6b.json | 7 +++++++ ...i-react-table-ea92aa04-54e5-4f63-936e-e37fe9a4f2f7.json | 7 +++++++ ...ui-react-tabs-e928b3f8-e533-4e3c-960d-b62cd1b6661b.json | 7 +++++++ ...ui-react-tags-b38fc107-b805-4f7b-bc94-18852cee65c8.json | 7 +++++++ ...pover-preview-d2a6cc93-7e92-4bce-bbf4-44aa4fc67376.json | 7 +++++++ ...eact-textarea-a9dcf4be-9061-4e14-aeac-2299e8f2a02e.json | 7 +++++++ ...picker-compat-459ec9f4-1fb6-43f4-ae67-ab03757ed9c1.json | 7 +++++++ ...react-toolbar-8707f19b-076b-41da-ad95-246744dc3cce.json | 7 +++++++ ...react-tooltip-486e2f8e-d4ef-49e6-865a-128e020396f8.json | 7 +++++++ ...ui-react-tree-6f3593c4-9155-4a86-8cdf-653b8992e6a1.json | 7 +++++++ ...act-utilities-95dc5d45-ef33-47d5-960c-80828bc324bd.json | 7 +++++++ ...t-virtualizer-7344c6de-f2e4-4795-bd41-06f3bba0406c.json | 7 +++++++ 27 files changed, 189 insertions(+) create mode 100644 change/@fluentui-eslint-plugin-bc33d2c9-cfd7-44bb-a8de-04bf3fb7b14f.json create mode 100644 change/@fluentui-react-accordion-74970004-bc83-461d-a43c-3758c0c429b5.json create mode 100644 change/@fluentui-react-card-26618c50-93dc-4116-8d0a-90c4f1566875.json create mode 100644 change/@fluentui-react-checkbox-61435c59-fe06-4b4a-a1b1-f0a318fd8c87.json create mode 100644 change/@fluentui-react-datepicker-compat-583ce0d7-9840-431b-8056-91f5991ef562.json create mode 100644 change/@fluentui-react-dialog-285527f9-bb4d-41d5-b6f4-1b57ab4f8ced.json create mode 100644 change/@fluentui-react-input-b337e912-5bde-4162-9a26-201fcc5347ee.json create mode 100644 change/@fluentui-react-menu-ba500681-bcdd-4437-aaa3-002bf617b009.json create mode 100644 change/@fluentui-react-migration-v0-v9-2af1c3a5-5f09-4ead-80b6-c7370457d6c9.json create mode 100644 change/@fluentui-react-popover-6de680db-0afe-4131-a96c-9ef10d14c997.json create mode 100644 change/@fluentui-react-radio-6a06b070-1df9-4416-92fd-8f4de71b1759.json create mode 100644 change/@fluentui-react-rating-preview-be1073d4-f244-4c68-8db6-12d4e897bc68.json create mode 100644 change/@fluentui-react-select-6c0bfff0-b7e4-46a6-a4d3-ca79eada2d17.json create mode 100644 change/@fluentui-react-slider-a79b527f-6529-4b9e-92ef-fca325b162db.json create mode 100644 change/@fluentui-react-spinbutton-2becfac8-c8ca-4ecb-b961-dfad3e44f878.json create mode 100644 change/@fluentui-react-switch-a4f6ce47-4fdb-421d-8229-ec4e30dd9d6b.json create mode 100644 change/@fluentui-react-table-ea92aa04-54e5-4f63-936e-e37fe9a4f2f7.json create mode 100644 change/@fluentui-react-tabs-e928b3f8-e533-4e3c-960d-b62cd1b6661b.json create mode 100644 change/@fluentui-react-tags-b38fc107-b805-4f7b-bc94-18852cee65c8.json create mode 100644 change/@fluentui-react-teaching-popover-preview-d2a6cc93-7e92-4bce-bbf4-44aa4fc67376.json create mode 100644 change/@fluentui-react-textarea-a9dcf4be-9061-4e14-aeac-2299e8f2a02e.json create mode 100644 change/@fluentui-react-timepicker-compat-459ec9f4-1fb6-43f4-ae67-ab03757ed9c1.json create mode 100644 change/@fluentui-react-toolbar-8707f19b-076b-41da-ad95-246744dc3cce.json create mode 100644 change/@fluentui-react-tooltip-486e2f8e-d4ef-49e6-865a-128e020396f8.json create mode 100644 change/@fluentui-react-tree-6f3593c4-9155-4a86-8cdf-653b8992e6a1.json create mode 100644 change/@fluentui-react-utilities-95dc5d45-ef33-47d5-960c-80828bc324bd.json create mode 100644 change/@fluentui-react-virtualizer-7344c6de-f2e4-4795-bd41-06f3bba0406c.json diff --git a/change/@fluentui-eslint-plugin-bc33d2c9-cfd7-44bb-a8de-04bf3fb7b14f.json b/change/@fluentui-eslint-plugin-bc33d2c9-cfd7-44bb-a8de-04bf3fb7b14f.json new file mode 100644 index 0000000000000..55df1450cdca4 --- /dev/null +++ b/change/@fluentui-eslint-plugin-bc33d2c9-cfd7-44bb-a8de-04bf3fb7b14f.json @@ -0,0 +1,7 @@ +{ + "type": "minor", + "comment": "feat: add new rule consistent-callback-type", + "packageName": "@fluentui/eslint-plugin", + "email": "yuanboxue@microsoft.com", + "dependentChangeType": "patch" +} diff --git a/change/@fluentui-react-accordion-74970004-bc83-461d-a43c-3758c0c429b5.json b/change/@fluentui-react-accordion-74970004-bc83-461d-a43c-3758c0c429b5.json new file mode 100644 index 0000000000000..79a53aeabc11d --- /dev/null +++ b/change/@fluentui-react-accordion-74970004-bc83-461d-a43c-3758c0c429b5.json @@ -0,0 +1,7 @@ +{ + "type": "none", + "comment": "chore: disable consistent-callback-type lint rule for existing callbacks", + "packageName": "@fluentui/react-accordion", + "email": "yuanboxue@microsoft.com", + "dependentChangeType": "none" +} diff --git a/change/@fluentui-react-card-26618c50-93dc-4116-8d0a-90c4f1566875.json b/change/@fluentui-react-card-26618c50-93dc-4116-8d0a-90c4f1566875.json new file mode 100644 index 0000000000000..ee120f34268fa --- /dev/null +++ b/change/@fluentui-react-card-26618c50-93dc-4116-8d0a-90c4f1566875.json @@ -0,0 +1,7 @@ +{ + "type": "none", + "comment": "chore: disable consistent-callback-type lint rule for existing callbacks", + "packageName": "@fluentui/react-card", + "email": "yuanboxue@microsoft.com", + "dependentChangeType": "none" +} diff --git a/change/@fluentui-react-checkbox-61435c59-fe06-4b4a-a1b1-f0a318fd8c87.json b/change/@fluentui-react-checkbox-61435c59-fe06-4b4a-a1b1-f0a318fd8c87.json new file mode 100644 index 0000000000000..23ea3d6cd4d2a --- /dev/null +++ b/change/@fluentui-react-checkbox-61435c59-fe06-4b4a-a1b1-f0a318fd8c87.json @@ -0,0 +1,7 @@ +{ + "type": "none", + "comment": "chore: disable consistent-callback-type lint rule for existing callbacks", + "packageName": "@fluentui/react-checkbox", + "email": "yuanboxue@microsoft.com", + "dependentChangeType": "none" +} diff --git a/change/@fluentui-react-datepicker-compat-583ce0d7-9840-431b-8056-91f5991ef562.json b/change/@fluentui-react-datepicker-compat-583ce0d7-9840-431b-8056-91f5991ef562.json new file mode 100644 index 0000000000000..f2fd314ee15bf --- /dev/null +++ b/change/@fluentui-react-datepicker-compat-583ce0d7-9840-431b-8056-91f5991ef562.json @@ -0,0 +1,7 @@ +{ + "type": "none", + "comment": "chore: disable consistent-callback-type lint rule for existing callbacks", + "packageName": "@fluentui/react-datepicker-compat", + "email": "yuanboxue@microsoft.com", + "dependentChangeType": "none" +} diff --git a/change/@fluentui-react-dialog-285527f9-bb4d-41d5-b6f4-1b57ab4f8ced.json b/change/@fluentui-react-dialog-285527f9-bb4d-41d5-b6f4-1b57ab4f8ced.json new file mode 100644 index 0000000000000..f0e539703c2cd --- /dev/null +++ b/change/@fluentui-react-dialog-285527f9-bb4d-41d5-b6f4-1b57ab4f8ced.json @@ -0,0 +1,7 @@ +{ + "type": "none", + "comment": "chore: disable consistent-callback-type lint rule for existing callbacks", + "packageName": "@fluentui/react-dialog", + "email": "yuanboxue@microsoft.com", + "dependentChangeType": "none" +} diff --git a/change/@fluentui-react-input-b337e912-5bde-4162-9a26-201fcc5347ee.json b/change/@fluentui-react-input-b337e912-5bde-4162-9a26-201fcc5347ee.json new file mode 100644 index 0000000000000..a8c02a501adc8 --- /dev/null +++ b/change/@fluentui-react-input-b337e912-5bde-4162-9a26-201fcc5347ee.json @@ -0,0 +1,7 @@ +{ + "type": "none", + "comment": "chore: disable consistent-callback-type lint rule for existing callbacks", + "packageName": "@fluentui/react-input", + "email": "yuanboxue@microsoft.com", + "dependentChangeType": "none" +} diff --git a/change/@fluentui-react-menu-ba500681-bcdd-4437-aaa3-002bf617b009.json b/change/@fluentui-react-menu-ba500681-bcdd-4437-aaa3-002bf617b009.json new file mode 100644 index 0000000000000..6ac81d313aaf6 --- /dev/null +++ b/change/@fluentui-react-menu-ba500681-bcdd-4437-aaa3-002bf617b009.json @@ -0,0 +1,7 @@ +{ + "type": "none", + "comment": "chore: disable consistent-callback-type lint rule for existing callbacks", + "packageName": "@fluentui/react-menu", + "email": "yuanboxue@microsoft.com", + "dependentChangeType": "none" +} diff --git a/change/@fluentui-react-migration-v0-v9-2af1c3a5-5f09-4ead-80b6-c7370457d6c9.json b/change/@fluentui-react-migration-v0-v9-2af1c3a5-5f09-4ead-80b6-c7370457d6c9.json new file mode 100644 index 0000000000000..043296131a673 --- /dev/null +++ b/change/@fluentui-react-migration-v0-v9-2af1c3a5-5f09-4ead-80b6-c7370457d6c9.json @@ -0,0 +1,7 @@ +{ + "type": "none", + "comment": "chore: disable consistent-callback-type lint rule for existing callbacks", + "packageName": "@fluentui/react-migration-v0-v9", + "email": "yuanboxue@microsoft.com", + "dependentChangeType": "none" +} diff --git a/change/@fluentui-react-popover-6de680db-0afe-4131-a96c-9ef10d14c997.json b/change/@fluentui-react-popover-6de680db-0afe-4131-a96c-9ef10d14c997.json new file mode 100644 index 0000000000000..7c0a38cda3519 --- /dev/null +++ b/change/@fluentui-react-popover-6de680db-0afe-4131-a96c-9ef10d14c997.json @@ -0,0 +1,7 @@ +{ + "type": "none", + "comment": "chore: disable consistent-callback-type lint rule for existing callbacks", + "packageName": "@fluentui/react-popover", + "email": "yuanboxue@microsoft.com", + "dependentChangeType": "none" +} diff --git a/change/@fluentui-react-radio-6a06b070-1df9-4416-92fd-8f4de71b1759.json b/change/@fluentui-react-radio-6a06b070-1df9-4416-92fd-8f4de71b1759.json new file mode 100644 index 0000000000000..6f8d256c388fa --- /dev/null +++ b/change/@fluentui-react-radio-6a06b070-1df9-4416-92fd-8f4de71b1759.json @@ -0,0 +1,7 @@ +{ + "type": "none", + "comment": "chore: disable consistent-callback-type lint rule for existing callbacks", + "packageName": "@fluentui/react-radio", + "email": "yuanboxue@microsoft.com", + "dependentChangeType": "none" +} diff --git a/change/@fluentui-react-rating-preview-be1073d4-f244-4c68-8db6-12d4e897bc68.json b/change/@fluentui-react-rating-preview-be1073d4-f244-4c68-8db6-12d4e897bc68.json new file mode 100644 index 0000000000000..2d07cf8c7a709 --- /dev/null +++ b/change/@fluentui-react-rating-preview-be1073d4-f244-4c68-8db6-12d4e897bc68.json @@ -0,0 +1,7 @@ +{ + "type": "none", + "comment": "chore: disable consistent-callback-type lint rule for existing callbacks", + "packageName": "@fluentui/react-rating-preview", + "email": "yuanboxue@microsoft.com", + "dependentChangeType": "none" +} diff --git a/change/@fluentui-react-select-6c0bfff0-b7e4-46a6-a4d3-ca79eada2d17.json b/change/@fluentui-react-select-6c0bfff0-b7e4-46a6-a4d3-ca79eada2d17.json new file mode 100644 index 0000000000000..21501db53b8df --- /dev/null +++ b/change/@fluentui-react-select-6c0bfff0-b7e4-46a6-a4d3-ca79eada2d17.json @@ -0,0 +1,7 @@ +{ + "type": "none", + "comment": "chore: disable consistent-callback-type lint rule for existing callbacks", + "packageName": "@fluentui/react-select", + "email": "yuanboxue@microsoft.com", + "dependentChangeType": "none" +} diff --git a/change/@fluentui-react-slider-a79b527f-6529-4b9e-92ef-fca325b162db.json b/change/@fluentui-react-slider-a79b527f-6529-4b9e-92ef-fca325b162db.json new file mode 100644 index 0000000000000..476c65572b0b4 --- /dev/null +++ b/change/@fluentui-react-slider-a79b527f-6529-4b9e-92ef-fca325b162db.json @@ -0,0 +1,7 @@ +{ + "type": "none", + "comment": "chore: disable consistent-callback-type lint rule for existing callbacks", + "packageName": "@fluentui/react-slider", + "email": "yuanboxue@microsoft.com", + "dependentChangeType": "none" +} diff --git a/change/@fluentui-react-spinbutton-2becfac8-c8ca-4ecb-b961-dfad3e44f878.json b/change/@fluentui-react-spinbutton-2becfac8-c8ca-4ecb-b961-dfad3e44f878.json new file mode 100644 index 0000000000000..951a9ccd8aeb5 --- /dev/null +++ b/change/@fluentui-react-spinbutton-2becfac8-c8ca-4ecb-b961-dfad3e44f878.json @@ -0,0 +1,7 @@ +{ + "type": "none", + "comment": "chore: disable consistent-callback-type lint rule for existing callbacks", + "packageName": "@fluentui/react-spinbutton", + "email": "yuanboxue@microsoft.com", + "dependentChangeType": "none" +} diff --git a/change/@fluentui-react-switch-a4f6ce47-4fdb-421d-8229-ec4e30dd9d6b.json b/change/@fluentui-react-switch-a4f6ce47-4fdb-421d-8229-ec4e30dd9d6b.json new file mode 100644 index 0000000000000..db121065b1b8c --- /dev/null +++ b/change/@fluentui-react-switch-a4f6ce47-4fdb-421d-8229-ec4e30dd9d6b.json @@ -0,0 +1,7 @@ +{ + "type": "none", + "comment": "chore: disable consistent-callback-type lint rule for existing callbacks", + "packageName": "@fluentui/react-switch", + "email": "yuanboxue@microsoft.com", + "dependentChangeType": "none" +} diff --git a/change/@fluentui-react-table-ea92aa04-54e5-4f63-936e-e37fe9a4f2f7.json b/change/@fluentui-react-table-ea92aa04-54e5-4f63-936e-e37fe9a4f2f7.json new file mode 100644 index 0000000000000..57d41a639a2f4 --- /dev/null +++ b/change/@fluentui-react-table-ea92aa04-54e5-4f63-936e-e37fe9a4f2f7.json @@ -0,0 +1,7 @@ +{ + "type": "none", + "comment": "chore: disable consistent-callback-type lint rule for existing callbacks", + "packageName": "@fluentui/react-table", + "email": "yuanboxue@microsoft.com", + "dependentChangeType": "none" +} diff --git a/change/@fluentui-react-tabs-e928b3f8-e533-4e3c-960d-b62cd1b6661b.json b/change/@fluentui-react-tabs-e928b3f8-e533-4e3c-960d-b62cd1b6661b.json new file mode 100644 index 0000000000000..5ca3caf290066 --- /dev/null +++ b/change/@fluentui-react-tabs-e928b3f8-e533-4e3c-960d-b62cd1b6661b.json @@ -0,0 +1,7 @@ +{ + "type": "none", + "comment": "chore: disable consistent-callback-type lint rule for existing callbacks", + "packageName": "@fluentui/react-tabs", + "email": "yuanboxue@microsoft.com", + "dependentChangeType": "none" +} diff --git a/change/@fluentui-react-tags-b38fc107-b805-4f7b-bc94-18852cee65c8.json b/change/@fluentui-react-tags-b38fc107-b805-4f7b-bc94-18852cee65c8.json new file mode 100644 index 0000000000000..f3c5f889551c0 --- /dev/null +++ b/change/@fluentui-react-tags-b38fc107-b805-4f7b-bc94-18852cee65c8.json @@ -0,0 +1,7 @@ +{ + "type": "none", + "comment": "chore: disable consistent-callback-type lint rule for existing callbacks", + "packageName": "@fluentui/react-tags", + "email": "yuanboxue@microsoft.com", + "dependentChangeType": "none" +} diff --git a/change/@fluentui-react-teaching-popover-preview-d2a6cc93-7e92-4bce-bbf4-44aa4fc67376.json b/change/@fluentui-react-teaching-popover-preview-d2a6cc93-7e92-4bce-bbf4-44aa4fc67376.json new file mode 100644 index 0000000000000..288587a1818bd --- /dev/null +++ b/change/@fluentui-react-teaching-popover-preview-d2a6cc93-7e92-4bce-bbf4-44aa4fc67376.json @@ -0,0 +1,7 @@ +{ + "type": "none", + "comment": "chore: disable consistent-callback-type lint rule for existing callbacks", + "packageName": "@fluentui/react-teaching-popover-preview", + "email": "yuanboxue@microsoft.com", + "dependentChangeType": "none" +} diff --git a/change/@fluentui-react-textarea-a9dcf4be-9061-4e14-aeac-2299e8f2a02e.json b/change/@fluentui-react-textarea-a9dcf4be-9061-4e14-aeac-2299e8f2a02e.json new file mode 100644 index 0000000000000..0eb0380f66ed1 --- /dev/null +++ b/change/@fluentui-react-textarea-a9dcf4be-9061-4e14-aeac-2299e8f2a02e.json @@ -0,0 +1,7 @@ +{ + "type": "none", + "comment": "chore: disable consistent-callback-type lint rule for existing callbacks", + "packageName": "@fluentui/react-textarea", + "email": "yuanboxue@microsoft.com", + "dependentChangeType": "none" +} diff --git a/change/@fluentui-react-timepicker-compat-459ec9f4-1fb6-43f4-ae67-ab03757ed9c1.json b/change/@fluentui-react-timepicker-compat-459ec9f4-1fb6-43f4-ae67-ab03757ed9c1.json new file mode 100644 index 0000000000000..f9cad44ad5e90 --- /dev/null +++ b/change/@fluentui-react-timepicker-compat-459ec9f4-1fb6-43f4-ae67-ab03757ed9c1.json @@ -0,0 +1,7 @@ +{ + "type": "none", + "comment": "chore: disable consistent-callback-type lint rule for existing callbacks", + "packageName": "@fluentui/react-timepicker-compat", + "email": "yuanboxue@microsoft.com", + "dependentChangeType": "none" +} diff --git a/change/@fluentui-react-toolbar-8707f19b-076b-41da-ad95-246744dc3cce.json b/change/@fluentui-react-toolbar-8707f19b-076b-41da-ad95-246744dc3cce.json new file mode 100644 index 0000000000000..93db9a91b7f43 --- /dev/null +++ b/change/@fluentui-react-toolbar-8707f19b-076b-41da-ad95-246744dc3cce.json @@ -0,0 +1,7 @@ +{ + "type": "none", + "comment": "chore: disable consistent-callback-type lint rule for existing callbacks", + "packageName": "@fluentui/react-toolbar", + "email": "yuanboxue@microsoft.com", + "dependentChangeType": "none" +} diff --git a/change/@fluentui-react-tooltip-486e2f8e-d4ef-49e6-865a-128e020396f8.json b/change/@fluentui-react-tooltip-486e2f8e-d4ef-49e6-865a-128e020396f8.json new file mode 100644 index 0000000000000..aaa3f8ac03bae --- /dev/null +++ b/change/@fluentui-react-tooltip-486e2f8e-d4ef-49e6-865a-128e020396f8.json @@ -0,0 +1,7 @@ +{ + "type": "none", + "comment": "chore: disable consistent-callback-type lint rule for existing callbacks", + "packageName": "@fluentui/react-tooltip", + "email": "yuanboxue@microsoft.com", + "dependentChangeType": "none" +} diff --git a/change/@fluentui-react-tree-6f3593c4-9155-4a86-8cdf-653b8992e6a1.json b/change/@fluentui-react-tree-6f3593c4-9155-4a86-8cdf-653b8992e6a1.json new file mode 100644 index 0000000000000..c0333263c203d --- /dev/null +++ b/change/@fluentui-react-tree-6f3593c4-9155-4a86-8cdf-653b8992e6a1.json @@ -0,0 +1,7 @@ +{ + "type": "none", + "comment": "chore: disable consistent-callback-type lint rule for existing callbacks", + "packageName": "@fluentui/react-tree", + "email": "yuanboxue@microsoft.com", + "dependentChangeType": "none" +} diff --git a/change/@fluentui-react-utilities-95dc5d45-ef33-47d5-960c-80828bc324bd.json b/change/@fluentui-react-utilities-95dc5d45-ef33-47d5-960c-80828bc324bd.json new file mode 100644 index 0000000000000..2e2755ce62271 --- /dev/null +++ b/change/@fluentui-react-utilities-95dc5d45-ef33-47d5-960c-80828bc324bd.json @@ -0,0 +1,7 @@ +{ + "type": "none", + "comment": "chore: disable consistent-callback-type lint rule for existing callbacks", + "packageName": "@fluentui/react-utilities", + "email": "yuanboxue@microsoft.com", + "dependentChangeType": "none" +} diff --git a/change/@fluentui-react-virtualizer-7344c6de-f2e4-4795-bd41-06f3bba0406c.json b/change/@fluentui-react-virtualizer-7344c6de-f2e4-4795-bd41-06f3bba0406c.json new file mode 100644 index 0000000000000..859f9baa44fcf --- /dev/null +++ b/change/@fluentui-react-virtualizer-7344c6de-f2e4-4795-bd41-06f3bba0406c.json @@ -0,0 +1,7 @@ +{ + "type": "none", + "comment": "chore: disable consistent-callback-type lint rule for existing callbacks", + "packageName": "@fluentui/react-virtualizer", + "email": "yuanboxue@microsoft.com", + "dependentChangeType": "none" +} From 530128552886ae523648b87afb7ff9fa4de5db84 Mon Sep 17 00:00:00 2001 From: YuanboXue-Amber Date: Fri, 12 Jan 2024 14:46:06 +0100 Subject: [PATCH 05/31] add unit test --- .../consistent-callback-type/index.test.js | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 packages/eslint-plugin/src/rules/consistent-callback-type/index.test.js diff --git a/packages/eslint-plugin/src/rules/consistent-callback-type/index.test.js b/packages/eslint-plugin/src/rules/consistent-callback-type/index.test.js new file mode 100644 index 0000000000000..779405a618854 --- /dev/null +++ b/packages/eslint-plugin/src/rules/consistent-callback-type/index.test.js @@ -0,0 +1,67 @@ +// @ts-nocheck +const { ESLintUtils } = require('@typescript-eslint/experimental-utils'); +const rule = require('./index'); + +const ruleTester = new ESLintUtils.RuleTester({ + parser: '@typescript-eslint/parser', +}); + +ruleTester.run('consistent-callback-type', rule, { + valid: [ + // Valid when prop is TSTypeAliasDeclaration and the callback uses EventHandler + { + code: ` + import { EventHandler, EventData } from '@fluentui/react-utilities'; + export type OnSomeEventData = EventData<'focus', React.FocusEvent> & { + open: boolean, + }; + export type SomeProps = { + onSomeEvent?: EventHandler, + }; + `, + filename: 'src/components/SomeComponent/SomeComponent.type.ts', + }, + // Valid when prop is TSIntersectionType and the callback uses EventHandler + { + code: ` + import { EventHandler, EventData } from '@fluentui/react-utilities'; + export type OnSomeEventData = EventData<'focus', React.FocusEvent> & { + open: boolean, + }; + export type SomeProps = SomeType & { + onSomeEvent?: EventHandler, + }; + `, + filename: 'src/components/SomeComponent/SomeComponent.type.ts', + }, + // Valid when prop has a function that is not callback, and not using EventHandler type + { + code: ` + export type SomeProps = { + someFunction?: EventHandler, + }; + `, + filename: 'src/components/SomeComponent/SomeComponent.type.ts', + }, + ], + invalid: [ + // Invalid when callback in props is not using EventHandler + { + code: ` + export type SomeProps = { + onChange?: (ev: React.ChangeEvent, data: {}) => void; + }; + `, + errors: [{ messageId: 'invalidType' }], + }, + // Invalid when callback in props is not using EventHandler, and the props is TSIntersectionType + { + code: ` + export type SomeProps = SomeType & { + onChange?: (ev: React.ChangeEvent, data: {}) => void; + }; + `, + errors: [{ messageId: 'invalidType' }], + }, + ], +}); From 89cb618fddb9ce7a1a56fa5c764d58c3f7b54f35 Mon Sep 17 00:00:00 2001 From: YuanboXue-Amber Date: Tue, 16 Jan 2024 11:49:07 +0100 Subject: [PATCH 06/31] remove react-utilities changelog --- ...act-utilities-95dc5d45-ef33-47d5-960c-80828bc324bd.json | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 change/@fluentui-react-utilities-95dc5d45-ef33-47d5-960c-80828bc324bd.json diff --git a/change/@fluentui-react-utilities-95dc5d45-ef33-47d5-960c-80828bc324bd.json b/change/@fluentui-react-utilities-95dc5d45-ef33-47d5-960c-80828bc324bd.json deleted file mode 100644 index 2e2755ce62271..0000000000000 --- a/change/@fluentui-react-utilities-95dc5d45-ef33-47d5-960c-80828bc324bd.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "none", - "comment": "chore: disable consistent-callback-type lint rule for existing callbacks", - "packageName": "@fluentui/react-utilities", - "email": "yuanboxue@microsoft.com", - "dependentChangeType": "none" -} From c35948a7f3feb01859fb8587d286680fe5fdcafe Mon Sep 17 00:00:00 2001 From: YuanboXue-Amber Date: Tue, 16 Jan 2024 14:01:10 +0100 Subject: [PATCH 07/31] add comments for lint disable and use multi line pragma --- .../src/components/Accordion/Accordion.types.ts | 2 +- .../react-card/src/components/Card/Card.types.ts | 2 +- .../src/components/Checkbox/Checkbox.types.ts | 2 +- .../src/components/DatePicker/DatePicker.types.ts | 6 +++--- .../react-dialog/src/components/Dialog/Dialog.types.ts | 2 +- .../react-input/src/components/Input/Input.types.ts | 2 +- .../react-menu/src/components/Menu/Menu.types.ts | 2 +- .../react-menu/src/components/MenuList/MenuList.types.ts | 2 +- .../src/components/MenuTrigger/MenuTrigger.types.ts | 7 +++---- .../src/components/List/List/List.types.ts | 2 +- .../react-popover/src/components/Popover/Popover.types.ts | 2 +- .../src/components/PopoverTrigger/PopoverTrigger.types.ts | 6 +++--- .../react-radio/src/components/Radio/Radio.types.ts | 2 +- .../src/components/RadioGroup/RadioGroup.types.ts | 2 +- .../src/components/Rating/Rating.types.ts | 2 +- .../react-select/src/components/Select/Select.types.ts | 2 +- .../react-slider/src/components/Slider/Slider.types.ts | 2 +- .../src/components/SpinButton/SpinButton.types.ts | 2 +- .../react-switch/src/components/Switch/Switch.types.ts | 2 +- .../react-table/src/components/DataGrid/DataGrid.types.ts | 8 +++++--- .../react-tabs/src/components/TabList/TabList.types.ts | 2 +- .../react-tags/src/components/TagGroup/TagGroup.types.ts | 2 +- .../components/TeachingPopover/TeachingPopover.types.ts | 7 +++++-- .../src/components/Textarea/Textarea.types.ts | 2 +- .../src/components/TimePicker/TimePicker.types.ts | 2 +- .../react-toolbar/src/components/Toolbar/Toolbar.types.ts | 2 +- .../react-tooltip/src/components/Tooltip/Tooltip.types.ts | 2 +- .../react-tree/src/components/TreeItem/TreeItem.types.ts | 2 +- .../src/components/Virtualizer/Virtualizer.types.ts | 2 +- 29 files changed, 43 insertions(+), 39 deletions(-) diff --git a/packages/react-components/react-accordion/src/components/Accordion/Accordion.types.ts b/packages/react-components/react-accordion/src/components/Accordion/Accordion.types.ts index 967182a650378..8a01710718c21 100644 --- a/packages/react-components/react-accordion/src/components/Accordion/Accordion.types.ts +++ b/packages/react-components/react-accordion/src/components/Accordion/Accordion.types.ts @@ -50,7 +50,7 @@ export type AccordionProps = ComponentProps; + onToggle?: AccordionToggleEventHandler; // callback should be typed with EventHandler, but we can't break existing callbacks /** * Controls the state of the panel. diff --git a/packages/react-components/react-card/src/components/Card/Card.types.ts b/packages/react-components/react-card/src/components/Card/Card.types.ts index d9896cd3e8c36..c983bf209f0d0 100644 --- a/packages/react-components/react-card/src/components/Card/Card.types.ts +++ b/packages/react-components/react-card/src/components/Card/Card.types.ts @@ -125,7 +125,7 @@ export type CardProps = ComponentProps & { * Callback to be called when the selected state value changes. */ // eslint-disable-next-line @fluentui/consistent-callback-type - onSelectionChange?: (event: CardOnSelectionChangeEvent, data: CardOnSelectData) => void; + onSelectionChange?: (event: CardOnSelectionChangeEvent, data: CardOnSelectData) => void; // callback should be typed with EventHandler, but we can't break existing callbacks }; /** diff --git a/packages/react-components/react-checkbox/src/components/Checkbox/Checkbox.types.ts b/packages/react-components/react-checkbox/src/components/Checkbox/Checkbox.types.ts index f3a4caf4a3534..58061399a4e0c 100644 --- a/packages/react-components/react-checkbox/src/components/Checkbox/Checkbox.types.ts +++ b/packages/react-components/react-checkbox/src/components/Checkbox/Checkbox.types.ts @@ -65,7 +65,7 @@ export type CheckboxProps = Omit< * Callback to be called when the checked state value changes. */ // eslint-disable-next-line @fluentui/consistent-callback-type - onChange?: (ev: React.ChangeEvent, data: CheckboxOnChangeData) => void; + onChange?: (ev: React.ChangeEvent, data: CheckboxOnChangeData) => void; // callback should be typed with EventHandler, but we can't break existing callbacks /** * The shape of the checkbox indicator. diff --git a/packages/react-components/react-datepicker-compat/src/components/DatePicker/DatePicker.types.ts b/packages/react-components/react-datepicker-compat/src/components/DatePicker/DatePicker.types.ts index c12c9ae046954..a4f5b33ee0b5f 100644 --- a/packages/react-components/react-datepicker-compat/src/components/DatePicker/DatePicker.types.ts +++ b/packages/react-components/react-datepicker-compat/src/components/DatePicker/DatePicker.types.ts @@ -17,7 +17,7 @@ export type DatePickerProps = Omit>, 'de * Callback issued when a date is selected */ // eslint-disable-next-line @fluentui/consistent-callback-type - onSelectDate?: (date: Date | null | undefined) => void; + onSelectDate?: (date: Date | null | undefined) => void; // callback should be typed with EventHandler, but we can't break existing callbacks /** * Whether the DatePicker is a required field or not. When using ``, this prop is automatically set. @@ -86,13 +86,13 @@ export type DatePickerProps = Omit>, 'de * Callback to run when the DatePicker's open state changes */ // eslint-disable-next-line @fluentui/consistent-callback-type - onOpenChange?: (open: boolean) => void; + onOpenChange?: (open: boolean) => void; // callback should be typed with EventHandler, but we can't break existing callbacks /** * Callback to run after the DatePicker's input has been validated */ // eslint-disable-next-line @fluentui/consistent-callback-type - onValidationResult?: (data: DatePickerValidationResultData) => void; + onValidationResult?: (data: DatePickerValidationResultData) => void; // callback should be typed with EventHandler, but we can't break existing callbacks /** * Whether the DatePicker should render the popup as inline or in a portal diff --git a/packages/react-components/react-dialog/src/components/Dialog/Dialog.types.ts b/packages/react-components/react-dialog/src/components/Dialog/Dialog.types.ts index b0ed1f3dc1e7e..a5ced052550e9 100644 --- a/packages/react-components/react-dialog/src/components/Dialog/Dialog.types.ts +++ b/packages/react-components/react-dialog/src/components/Dialog/Dialog.types.ts @@ -82,7 +82,7 @@ export type DialogProps = ComponentProps> & { * such as open value and type of interaction that created the event */ // eslint-disable-next-line @fluentui/consistent-callback-type - onOpenChange?: DialogOpenChangeEventHandler; + onOpenChange?: DialogOpenChangeEventHandler; // callback should be typed with EventHandler, but we can't break existing callbacks /** * Can contain two children including {@link DialogTrigger} and {@link DialogSurface}. * Alternatively can only contain {@link DialogSurface} if using trigger outside dialog, or controlling state. diff --git a/packages/react-components/react-input/src/components/Input/Input.types.ts b/packages/react-components/react-input/src/components/Input/Input.types.ts index 1280da89cd44d..3ed1dd9f91932 100644 --- a/packages/react-components/react-input/src/components/Input/Input.types.ts +++ b/packages/react-components/react-input/src/components/Input/Input.types.ts @@ -78,7 +78,7 @@ export type InputProps = Omit< * Called when the user changes the input's value. */ // eslint-disable-next-line @fluentui/consistent-callback-type - onChange?: (ev: React.ChangeEvent, data: InputOnChangeData) => void; + onChange?: (ev: React.ChangeEvent, data: InputOnChangeData) => void; // callback should be typed with EventHandler, but we can't break existing callbacks /** * An input can have different text-based [types](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input#input_types) diff --git a/packages/react-components/react-menu/src/components/Menu/Menu.types.ts b/packages/react-components/react-menu/src/components/Menu/Menu.types.ts index 1cf08fa0dc84c..9c62597c55534 100644 --- a/packages/react-components/react-menu/src/components/Menu/Menu.types.ts +++ b/packages/react-components/react-menu/src/components/Menu/Menu.types.ts @@ -41,7 +41,7 @@ export type MenuProps = ComponentProps & * The `open` value is used as a hint when directly controlling the component */ // eslint-disable-next-line @fluentui/consistent-callback-type - onOpenChange?: (e: MenuOpenEvent, data: MenuOpenChangeData) => void; + onOpenChange?: (e: MenuOpenEvent, data: MenuOpenChangeData) => void; // callback should be typed with EventHandler, but we can't break existing callbacks /** * Whether the popup is open diff --git a/packages/react-components/react-menu/src/components/MenuList/MenuList.types.ts b/packages/react-components/react-menu/src/components/MenuList/MenuList.types.ts index ca4f8d00ce843..00b7002cabbb2 100644 --- a/packages/react-components/react-menu/src/components/MenuList/MenuList.types.ts +++ b/packages/react-components/react-menu/src/components/MenuList/MenuList.types.ts @@ -44,7 +44,7 @@ export type MenuListProps = ComponentProps & { * @param data - A data object with relevant information */ // eslint-disable-next-line @fluentui/consistent-callback-type - onCheckedValueChange?: (e: MenuCheckedValueChangeEvent, data: MenuCheckedValueChangeData) => void; + onCheckedValueChange?: (e: MenuCheckedValueChangeEvent, data: MenuCheckedValueChangeData) => void; // callback should be typed with EventHandler, but we can't break existing callbacks }; export type MenuListState = ComponentState & diff --git a/packages/react-components/react-menu/src/components/MenuTrigger/MenuTrigger.types.ts b/packages/react-components/react-menu/src/components/MenuTrigger/MenuTrigger.types.ts index db15c3b18cbdb..81fb829f0b77e 100644 --- a/packages/react-components/react-menu/src/components/MenuTrigger/MenuTrigger.types.ts +++ b/packages/react-components/react-menu/src/components/MenuTrigger/MenuTrigger.types.ts @@ -20,14 +20,13 @@ export type MenuTriggerChildProps; - // eslint-disable-next-line @fluentui/consistent-callback-type + /* eslint-disable @fluentui/consistent-callback-type */ + // callback should be typed with EventHandler, but we can't break existing callbacks onMouseEnter: React.MouseEventHandler; - // eslint-disable-next-line @fluentui/consistent-callback-type onMouseLeave: React.MouseEventHandler; - // eslint-disable-next-line @fluentui/consistent-callback-type onMouseMove: React.MouseEventHandler; - // eslint-disable-next-line @fluentui/consistent-callback-type onContextMenu: React.MouseEventHandler; + /* eslint-enable @fluentui/consistent-callback-type */ } >; diff --git a/packages/react-components/react-migration-v0-v9/src/components/List/List/List.types.ts b/packages/react-components/react-migration-v0-v9/src/components/List/List/List.types.ts index 5d4ac44962b01..70707fa271561 100644 --- a/packages/react-components/react-migration-v0-v9/src/components/List/List/List.types.ts +++ b/packages/react-components/react-migration-v0-v9/src/components/List/List/List.types.ts @@ -54,7 +54,7 @@ export type ListProps = ComponentProps & { * Callback for selection change events, used for both controlled and uncontrolled (as notification) */ // eslint-disable-next-line @fluentui/consistent-callback-type - onSelectionChange?: (event: React.SyntheticEvent, data: { selectedItems: SelectionItemId[] }) => void; + onSelectionChange?: (event: React.SyntheticEvent, data: { selectedItems: SelectionItemId[] }) => void; // callback should be typed with EventHandler, but we can't break existing callbacks /** * Truncates header diff --git a/packages/react-components/react-popover/src/components/Popover/Popover.types.ts b/packages/react-components/react-popover/src/components/Popover/Popover.types.ts index 7671600f89b97..5eb51e42ca02a 100644 --- a/packages/react-components/react-popover/src/components/Popover/Popover.types.ts +++ b/packages/react-components/react-popover/src/components/Popover/Popover.types.ts @@ -65,7 +65,7 @@ export type PopoverProps = Pick & { * The `open` value is used as a hint when directly controlling the component */ // eslint-disable-next-line @fluentui/consistent-callback-type - onOpenChange?: (e: OpenPopoverEvents, data: OnOpenChangeData) => void; + onOpenChange?: (e: OpenPopoverEvents, data: OnOpenChangeData) => void; // callback should be typed with EventHandler, but we can't break existing callbacks /** * Controls the opening of the Popover diff --git a/packages/react-components/react-popover/src/components/PopoverTrigger/PopoverTrigger.types.ts b/packages/react-components/react-popover/src/components/PopoverTrigger/PopoverTrigger.types.ts index e8df2197e6c35..42a20e69c6de1 100644 --- a/packages/react-components/react-popover/src/components/PopoverTrigger/PopoverTrigger.types.ts +++ b/packages/react-components/react-popover/src/components/PopoverTrigger/PopoverTrigger.types.ts @@ -28,11 +28,11 @@ export type PopoverTriggerChildProps; - // eslint-disable-next-line @fluentui/consistent-callback-type + /* eslint-disable @fluentui/consistent-callback-type */ + // callback should be typed with EventHandler, but we can't break existing callbacks onMouseEnter: React.MouseEventHandler; - // eslint-disable-next-line @fluentui/consistent-callback-type onMouseLeave: React.MouseEventHandler; - // eslint-disable-next-line @fluentui/consistent-callback-type onContextMenu: React.MouseEventHandler; + /* eslint-enable @fluentui/consistent-callback-type */ } >; diff --git a/packages/react-components/react-radio/src/components/Radio/Radio.types.ts b/packages/react-components/react-radio/src/components/Radio/Radio.types.ts index 437a8366afef7..b5b9ed9e789d7 100644 --- a/packages/react-components/react-radio/src/components/Radio/Radio.types.ts +++ b/packages/react-components/react-radio/src/components/Radio/Radio.types.ts @@ -61,7 +61,7 @@ export type RadioProps = Omit, 'input'>, 'onC * Use RadioGroup's `onChange` event to determine when the selection in the group changes. */ // eslint-disable-next-line @fluentui/consistent-callback-type - onChange?: (ev: React.ChangeEvent, data: RadioOnChangeData) => void; + onChange?: (ev: React.ChangeEvent, data: RadioOnChangeData) => void; // callback should be typed with EventHandler, but we can't break existing callbacks }; /** diff --git a/packages/react-components/react-radio/src/components/RadioGroup/RadioGroup.types.ts b/packages/react-components/react-radio/src/components/RadioGroup/RadioGroup.types.ts index b990a815e5e96..1b7c1dba8692b 100644 --- a/packages/react-components/react-radio/src/components/RadioGroup/RadioGroup.types.ts +++ b/packages/react-components/react-radio/src/components/RadioGroup/RadioGroup.types.ts @@ -34,7 +34,7 @@ export type RadioGroupProps = Omit>, 'on * Callback when the selected Radio item changes. */ // eslint-disable-next-line @fluentui/consistent-callback-type - onChange?: (ev: React.FormEvent, data: RadioGroupOnChangeData) => void; + onChange?: (ev: React.FormEvent, data: RadioGroupOnChangeData) => void; // callback should be typed with EventHandler, but we can't break existing callbacks /** * How the radio items are laid out in the group. diff --git a/packages/react-components/react-rating-preview/src/components/Rating/Rating.types.ts b/packages/react-components/react-rating-preview/src/components/Rating/Rating.types.ts index dfe5e413342da..c8d53d62a41c1 100644 --- a/packages/react-components/react-rating-preview/src/components/Rating/Rating.types.ts +++ b/packages/react-components/react-rating-preview/src/components/Rating/Rating.types.ts @@ -47,7 +47,7 @@ export type RatingProps = ComponentProps & { * Callback when the rating value is changed by the user. */ // eslint-disable-next-line @fluentui/consistent-callback-type - onChange?: (ev: React.SyntheticEvent | Event, data: RatingOnChangeData) => void; + onChange?: (ev: React.SyntheticEvent | Event, data: RatingOnChangeData) => void; // callback should be typed with EventHandler, but we can't break existing callbacks /** * Sets the precision to allow half-filled shapes in Rating * @default 1 diff --git a/packages/react-components/react-select/src/components/Select/Select.types.ts b/packages/react-components/react-select/src/components/Select/Select.types.ts index 49f7d22a1a6fe..8391b292ff413 100644 --- a/packages/react-components/react-select/src/components/Select/Select.types.ts +++ b/packages/react-components/react-select/src/components/Select/Select.types.ts @@ -28,7 +28,7 @@ export type SelectProps = Omit, 'select'>, ' * Called when the user changes the select element's value by selecting an option. */ // eslint-disable-next-line @fluentui/consistent-callback-type - onChange?: (ev: React.ChangeEvent, data: SelectOnChangeData) => void; + onChange?: (ev: React.ChangeEvent, data: SelectOnChangeData) => void; // callback should be typed with EventHandler, but we can't break existing callbacks /** * Matches the Input sizes diff --git a/packages/react-components/react-slider/src/components/Slider/Slider.types.ts b/packages/react-components/react-slider/src/components/Slider/Slider.types.ts index fd3c63d0c8653..0eeb9a4e1116a 100644 --- a/packages/react-components/react-slider/src/components/Slider/Slider.types.ts +++ b/packages/react-components/react-slider/src/components/Slider/Slider.types.ts @@ -95,7 +95,7 @@ export type SliderProps = Omit< * Triggers a callback when the value has been changed. This will be called on every individual step. */ // eslint-disable-next-line @fluentui/consistent-callback-type - onChange?: (ev: React.ChangeEvent, data: SliderOnChangeData) => void; + onChange?: (ev: React.ChangeEvent, data: SliderOnChangeData) => void; // callback should be typed with EventHandler, but we can't break existing callbacks }; export type SliderOnChangeData = { diff --git a/packages/react-components/react-spinbutton/src/components/SpinButton/SpinButton.types.ts b/packages/react-components/react-spinbutton/src/components/SpinButton/SpinButton.types.ts index 76e13f3789c01..06aa5746c3ed9 100644 --- a/packages/react-components/react-spinbutton/src/components/SpinButton/SpinButton.types.ts +++ b/packages/react-components/react-spinbutton/src/components/SpinButton/SpinButton.types.ts @@ -81,7 +81,7 @@ export type SpinButtonProps = Omit< * Note that this is NOT called for every key press while the user is editing. */ // eslint-disable-next-line @fluentui/consistent-callback-type - onChange?: (event: SpinButtonChangeEvent, data: SpinButtonOnChangeData) => void; + onChange?: (event: SpinButtonChangeEvent, data: SpinButtonOnChangeData) => void; // callback should be typed with EventHandler, but we can't break existing callbacks /** * How many decimal places the value should be rounded to. diff --git a/packages/react-components/react-switch/src/components/Switch/Switch.types.ts b/packages/react-components/react-switch/src/components/Switch/Switch.types.ts index 7a1cf9a994888..ffebec243c372 100644 --- a/packages/react-components/react-switch/src/components/Switch/Switch.types.ts +++ b/packages/react-components/react-switch/src/components/Switch/Switch.types.ts @@ -69,7 +69,7 @@ export type SwitchProps = Omit< * Callback to be called when the checked state value changes. */ // eslint-disable-next-line @fluentui/consistent-callback-type - onChange?: (ev: React.ChangeEvent, data: SwitchOnChangeData) => void; + onChange?: (ev: React.ChangeEvent, data: SwitchOnChangeData) => void; // callback should be typed with EventHandler, but we can't break existing callbacks }; /** diff --git a/packages/react-components/react-table/src/components/DataGrid/DataGrid.types.ts b/packages/react-components/react-table/src/components/DataGrid/DataGrid.types.ts index 5b497af44542e..7097189b653a1 100644 --- a/packages/react-components/react-table/src/components/DataGrid/DataGrid.types.ts +++ b/packages/react-components/react-table/src/components/DataGrid/DataGrid.types.ts @@ -64,10 +64,12 @@ export type DataGridProps = TableProps & Pick, 'focusMode' | 'subtleSelection' | 'selectionAppearance' | 'resizableColumns'> & Pick & Pick & { - // eslint-disable-next-line @fluentui/consistent-callback-type + /* eslint-disable @fluentui/consistent-callback-type */ + // callback should be typed with EventHandler, but we can't break existing callbacks onSortChange?: (e: React.MouseEvent, sortState: SortState) => void; - // eslint-disable-next-line @fluentui/consistent-callback-type onSelectionChange?: (e: React.MouseEvent | React.KeyboardEvent, data: OnSelectionChangeData) => void; + /* eslint-enable @fluentui/consistent-callback-type */ + /** * Enables row selection and sets the selection mode * @default false @@ -84,7 +86,7 @@ export type DataGridProps = TableProps & onColumnResize?: ( e: KeyboardEvent | TouchEvent | MouseEvent | undefined, data: { columnId: TableColumnId; width: number }, - ) => void; + ) => void; // callback should be typed with EventHandler, but we can't break existing callbacks /** * For column resizing. Allows for a container size to be adjusted by a number of pixels, to make * sure the columns don't overflow the table. diff --git a/packages/react-components/react-tabs/src/components/TabList/TabList.types.ts b/packages/react-components/react-tabs/src/components/TabList/TabList.types.ts index 4b65e4caceaa4..446b678922853 100644 --- a/packages/react-components/react-tabs/src/components/TabList/TabList.types.ts +++ b/packages/react-components/react-tabs/src/components/TabList/TabList.types.ts @@ -72,7 +72,7 @@ export type TabListProps = ComponentProps & { * Raised when a tab is selected. */ // eslint-disable-next-line @fluentui/consistent-callback-type - onTabSelect?: SelectTabEventHandler; + onTabSelect?: SelectTabEventHandler; // callback should be typed with EventHandler, but we can't break existing callbacks /** * When true, focusing a tab will select it. diff --git a/packages/react-components/react-tags/src/components/TagGroup/TagGroup.types.ts b/packages/react-components/react-tags/src/components/TagGroup/TagGroup.types.ts index 0f7ed579364f3..5c93fcf8434ac 100644 --- a/packages/react-components/react-tags/src/components/TagGroup/TagGroup.types.ts +++ b/packages/react-components/react-tags/src/components/TagGroup/TagGroup.types.ts @@ -18,7 +18,7 @@ export type TagGroupProps = ComponentProps & { * Callback for when a tag is dismissed */ // eslint-disable-next-line @fluentui/consistent-callback-type - onDismiss?: TagDismissHandler; + onDismiss?: TagDismissHandler; // callback should be typed with EventHandler, but we can't break existing callbacks size?: TagSize; }; diff --git a/packages/react-components/react-teaching-popover-preview/src/components/TeachingPopover/TeachingPopover.types.ts b/packages/react-components/react-teaching-popover-preview/src/components/TeachingPopover/TeachingPopover.types.ts index cfd04de5d11ec..572287a5e857b 100644 --- a/packages/react-components/react-teaching-popover-preview/src/components/TeachingPopover/TeachingPopover.types.ts +++ b/packages/react-components/react-teaching-popover-preview/src/components/TeachingPopover/TeachingPopover.types.ts @@ -14,10 +14,12 @@ export type TeachingPopoverProps = Omit & { * Enables user to dictate current page number via props */ currentPage?: number; + + /* eslint-disable @fluentui/consistent-callback-type */ + // callback should be typed with EventHandler, but we can't break existing callbacks /** * Callback to notify a page change (can be used to update 'currentPage' externally). */ - // eslint-disable-next-line @fluentui/consistent-callback-type onPageChange?: ( event: React.MouseEvent, data: TeachingPopoverPageChangeData, @@ -25,8 +27,9 @@ export type TeachingPopoverProps = Omit & { /** * Callback to notify when the final button step of a carousel has been activated. */ - // eslint-disable-next-line @fluentui/consistent-callback-type onFinish?: (event: React.MouseEvent) => void; + /* eslint-enable @fluentui/consistent-callback-type */ + /** * The appearance property (extended from popover, but removed 'inverted'). */ diff --git a/packages/react-components/react-textarea/src/components/Textarea/Textarea.types.ts b/packages/react-components/react-textarea/src/components/Textarea/Textarea.types.ts index 807db1c79bcd2..d7bcd28f9cde9 100644 --- a/packages/react-components/react-textarea/src/components/Textarea/Textarea.types.ts +++ b/packages/react-components/react-textarea/src/components/Textarea/Textarea.types.ts @@ -41,7 +41,7 @@ export type TextareaProps = Omit< * Callback for when the user changes the value. */ // eslint-disable-next-line @fluentui/consistent-callback-type - onChange?: (ev: React.ChangeEvent, data: TextareaOnChangeData) => void; + onChange?: (ev: React.ChangeEvent, data: TextareaOnChangeData) => void; // callback should be typed with EventHandler, but we can't break existing callbacks /** * Which direction the Textarea is allowed to be resized. diff --git a/packages/react-components/react-timepicker-compat/src/components/TimePicker/TimePicker.types.ts b/packages/react-components/react-timepicker-compat/src/components/TimePicker/TimePicker.types.ts index 543ba25096e67..d5508a0d72625 100644 --- a/packages/react-components/react-timepicker-compat/src/components/TimePicker/TimePicker.types.ts +++ b/packages/react-components/react-timepicker-compat/src/components/TimePicker/TimePicker.types.ts @@ -146,7 +146,7 @@ export type TimePickerProps = Omit, 'input * Callback for when a time selection is made. */ // eslint-disable-next-line @fluentui/consistent-callback-type - onTimeChange?: (event: TimeSelectionEvents, data: TimeSelectionData) => void; + onTimeChange?: (event: TimeSelectionEvents, data: TimeSelectionData) => void; // callback should be typed with EventHandler, but we can't break existing callbacks /** * Customizes the formatting of date strings displayed in dropdown options. diff --git a/packages/react-components/react-toolbar/src/components/Toolbar/Toolbar.types.ts b/packages/react-components/react-toolbar/src/components/Toolbar/Toolbar.types.ts index 2eec29f78f7c9..d3a26644e78c6 100644 --- a/packages/react-components/react-toolbar/src/components/Toolbar/Toolbar.types.ts +++ b/packages/react-components/react-toolbar/src/components/Toolbar/Toolbar.types.ts @@ -48,7 +48,7 @@ export type ToolbarProps = ComponentProps & { * @param data - A data object with relevant information */ // eslint-disable-next-line @fluentui/consistent-callback-type - onCheckedValueChange?: (e: ToolbarCheckedValueChangeEvent, data: ToolbarCheckedValueChangeData) => void; + onCheckedValueChange?: (e: ToolbarCheckedValueChangeEvent, data: ToolbarCheckedValueChangeData) => void; // callback should be typed with EventHandler, but we can't break existing callbacks }; /** diff --git a/packages/react-components/react-tooltip/src/components/Tooltip/Tooltip.types.ts b/packages/react-components/react-tooltip/src/components/Tooltip/Tooltip.types.ts index 6edf9cac03a42..5ed584deec9f7 100644 --- a/packages/react-components/react-tooltip/src/components/Tooltip/Tooltip.types.ts +++ b/packages/react-components/react-tooltip/src/components/Tooltip/Tooltip.types.ts @@ -67,7 +67,7 @@ export type TooltipProps = ComponentProps & onVisibleChange?: ( event: React.PointerEvent | React.FocusEvent | undefined, data: OnVisibleChangeData, - ) => void; + ) => void; // callback should be typed with EventHandler, but we can't break existing callbacks /** * Configure the positioning of the tooltip diff --git a/packages/react-components/react-tree/src/components/TreeItem/TreeItem.types.ts b/packages/react-components/react-tree/src/components/TreeItem/TreeItem.types.ts index bdeee481daf7f..426826d6f4906 100644 --- a/packages/react-components/react-tree/src/components/TreeItem/TreeItem.types.ts +++ b/packages/react-components/react-tree/src/components/TreeItem/TreeItem.types.ts @@ -55,7 +55,7 @@ export type TreeItemProps = ComponentProps> & { */ open?: boolean; // eslint-disable-next-line @fluentui/consistent-callback-type - onOpenChange?: (e: TreeItemOpenChangeEvent, data: TreeItemOpenChangeData) => void; + onOpenChange?: (e: TreeItemOpenChangeEvent, data: TreeItemOpenChangeData) => void; // callback should be typed with EventHandler, but we can't break existing callbacks /** * This property is inferred through context on a nested tree, and required for a flat tree. */ diff --git a/packages/react-components/react-virtualizer/src/components/Virtualizer/Virtualizer.types.ts b/packages/react-components/react-virtualizer/src/components/Virtualizer/Virtualizer.types.ts index 682265f5ffff3..934c460865661 100644 --- a/packages/react-components/react-virtualizer/src/components/Virtualizer/Virtualizer.types.ts +++ b/packages/react-components/react-virtualizer/src/components/Virtualizer/Virtualizer.types.ts @@ -160,7 +160,7 @@ export type VirtualizerConfigProps = { * Callback for notifying when a flagged index has been rendered */ // eslint-disable-next-line @fluentui/consistent-callback-type - onRenderedFlaggedIndex?: (index: number) => void; + onRenderedFlaggedIndex?: (index: number) => void; // callback should be typed with EventHandler, but we can't break existing callbacks /* * Callback for notifying when a flagged index has been rendered From 78c479f37b7a3d5a784e5e9f9c97933c46350b49 Mon Sep 17 00:00:00 2001 From: Amber Date: Tue, 16 Jan 2024 16:01:37 +0100 Subject: [PATCH 08/31] Update packages/eslint-plugin/src/rules/consistent-callback-type/index.js Co-authored-by: Martin Hochel --- .../eslint-plugin/src/rules/consistent-callback-type/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-plugin/src/rules/consistent-callback-type/index.js b/packages/eslint-plugin/src/rules/consistent-callback-type/index.js index 668bf1d7e72e7..d201dabe0199f 100644 --- a/packages/eslint-plugin/src/rules/consistent-callback-type/index.js +++ b/packages/eslint-plugin/src/rules/consistent-callback-type/index.js @@ -12,7 +12,7 @@ module.exports = createRule({ recommended: 'error', }, messages: { - invalidType: 'callback props should be typed with EventHandler', + invalidType: 'callback props should be typed with @fluentui/react-utilities#EventHandler', }, schema: [], }, From fcce254da8cd7cc227ad0b5f790b8ae3aeec2af8 Mon Sep 17 00:00:00 2001 From: Amber Date: Tue, 16 Jan 2024 16:02:08 +0100 Subject: [PATCH 09/31] Update packages/eslint-plugin/src/rules/consistent-callback-type/index.js Co-authored-by: Martin Hochel --- .../eslint-plugin/src/rules/consistent-callback-type/index.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/eslint-plugin/src/rules/consistent-callback-type/index.js b/packages/eslint-plugin/src/rules/consistent-callback-type/index.js index d201dabe0199f..4234001bb025a 100644 --- a/packages/eslint-plugin/src/rules/consistent-callback-type/index.js +++ b/packages/eslint-plugin/src/rules/consistent-callback-type/index.js @@ -20,8 +20,7 @@ module.exports = createRule({ create(context) { return { // eslint-disable-next-line @typescript-eslint/naming-convention - 'TSTypeAliasDeclaration[id.name=/.*Props$/] TSTypeLiteral': function (node) { - // @ts-ignore + 'TSTypeAliasDeclaration[id.name=/.*Props$/] TSTypeLiteral': function ( /** @type {import('@typescript-eslint/experimental-utils').TSESTree.TSTypeLiteral}*/ node) { node.members.forEach(member => { if ( member.type === 'TSPropertySignature' && From 2fe4251ae151962bf394eb1f1ece94d8cbbf68e4 Mon Sep 17 00:00:00 2001 From: Amber Date: Tue, 16 Jan 2024 16:03:28 +0100 Subject: [PATCH 10/31] Update packages/eslint-plugin/src/rules/consistent-callback-type/index.js Co-authored-by: Martin Hochel --- .../eslint-plugin/src/rules/consistent-callback-type/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-plugin/src/rules/consistent-callback-type/index.js b/packages/eslint-plugin/src/rules/consistent-callback-type/index.js index 4234001bb025a..80f1df87d4f48 100644 --- a/packages/eslint-plugin/src/rules/consistent-callback-type/index.js +++ b/packages/eslint-plugin/src/rules/consistent-callback-type/index.js @@ -23,7 +23,7 @@ module.exports = createRule({ 'TSTypeAliasDeclaration[id.name=/.*Props$/] TSTypeLiteral': function ( /** @type {import('@typescript-eslint/experimental-utils').TSESTree.TSTypeLiteral}*/ node) { node.members.forEach(member => { if ( - member.type === 'TSPropertySignature' && + member.type === AST_NODE_TYPES.TSPropertySignature && member.key.type === AST_NODE_TYPES.Identifier && member.key.name.startsWith('on') ) { From 29b34cc0d46eddf8a7a92c992c9edd3f07183157 Mon Sep 17 00:00:00 2001 From: Amber Date: Tue, 16 Jan 2024 16:03:37 +0100 Subject: [PATCH 11/31] Update packages/eslint-plugin/src/rules/consistent-callback-type/index.js Co-authored-by: Martin Hochel --- .../eslint-plugin/src/rules/consistent-callback-type/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-plugin/src/rules/consistent-callback-type/index.js b/packages/eslint-plugin/src/rules/consistent-callback-type/index.js index 80f1df87d4f48..81faa6244e4df 100644 --- a/packages/eslint-plugin/src/rules/consistent-callback-type/index.js +++ b/packages/eslint-plugin/src/rules/consistent-callback-type/index.js @@ -32,7 +32,7 @@ module.exports = createRule({ if ( !( typeAnnotation && - typeAnnotation.type === 'TSTypeReference' && + typeAnnotation.type === AST_NODE_TYPES.TSTypeReference && typeAnnotation.typeName.type === AST_NODE_TYPES.Identifier && typeAnnotation.typeName.name === 'EventHandler' && typeAnnotation.typeParameters From 5bf912123be99b7db1cf53e72acac9224b875c90 Mon Sep 17 00:00:00 2001 From: YuanboXue-Amber Date: Tue, 16 Jan 2024 16:08:06 +0100 Subject: [PATCH 12/31] prettier after apply suggestion --- .../eslint-plugin/src/rules/consistent-callback-type/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/eslint-plugin/src/rules/consistent-callback-type/index.js b/packages/eslint-plugin/src/rules/consistent-callback-type/index.js index 81faa6244e4df..62fb54079520f 100644 --- a/packages/eslint-plugin/src/rules/consistent-callback-type/index.js +++ b/packages/eslint-plugin/src/rules/consistent-callback-type/index.js @@ -20,7 +20,9 @@ module.exports = createRule({ create(context) { return { // eslint-disable-next-line @typescript-eslint/naming-convention - 'TSTypeAliasDeclaration[id.name=/.*Props$/] TSTypeLiteral': function ( /** @type {import('@typescript-eslint/experimental-utils').TSESTree.TSTypeLiteral}*/ node) { + 'TSTypeAliasDeclaration[id.name=/.*Props$/] TSTypeLiteral': function ( + /** @type {import('@typescript-eslint/experimental-utils').TSESTree.TSTypeLiteral}*/ node, + ) { node.members.forEach(member => { if ( member.type === AST_NODE_TYPES.TSPropertySignature && From caba8b56ef1a2e7a68e7c98905d1d379a977017d Mon Sep 17 00:00:00 2001 From: YuanboXue-Amber Date: Tue, 16 Jan 2024 19:16:46 +0100 Subject: [PATCH 13/31] update UT according to comments --- .../src/rules/consistent-callback-type/index.test.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/eslint-plugin/src/rules/consistent-callback-type/index.test.js b/packages/eslint-plugin/src/rules/consistent-callback-type/index.test.js index 779405a618854..0bcd236487e35 100644 --- a/packages/eslint-plugin/src/rules/consistent-callback-type/index.test.js +++ b/packages/eslint-plugin/src/rules/consistent-callback-type/index.test.js @@ -37,8 +37,9 @@ ruleTester.run('consistent-callback-type', rule, { // Valid when prop has a function that is not callback, and not using EventHandler type { code: ` + type SomeArgBag = { one: number }; export type SomeProps = { - someFunction?: EventHandler, + someFunction?: (args: SomeArgBag) => void, }; `, filename: 'src/components/SomeComponent/SomeComponent.type.ts', From 10c56326995fd37c52cf6d72c23bba5e6eb36838 Mon Sep 17 00:00:00 2001 From: YuanboXue-Amber Date: Tue, 16 Jan 2024 19:54:14 +0100 Subject: [PATCH 14/31] enhance rule --- .../rules/consistent-callback-type/index.js | 81 +++++++++++++------ .../consistent-callback-type/index.test.js | 3 +- 2 files changed, 57 insertions(+), 27 deletions(-) diff --git a/packages/eslint-plugin/src/rules/consistent-callback-type/index.js b/packages/eslint-plugin/src/rules/consistent-callback-type/index.js index 62fb54079520f..3ed996fd1ea2b 100644 --- a/packages/eslint-plugin/src/rules/consistent-callback-type/index.js +++ b/packages/eslint-plugin/src/rules/consistent-callback-type/index.js @@ -18,35 +18,64 @@ module.exports = createRule({ }, defaultOptions: [], create(context) { + /** + * @type {{ + * node: import('@typescript-eslint/experimental-utils').TSESTree.TSTypeAliasDeclaration, + * hasInnerTypeLiteral: boolean + * }[]} + */ + const typeAliasStack = []; // use a stack to match the first TSTypeLiteral node within TSTypeAliasDeclaration node + return { // eslint-disable-next-line @typescript-eslint/naming-convention - 'TSTypeAliasDeclaration[id.name=/.*Props$/] TSTypeLiteral': function ( - /** @type {import('@typescript-eslint/experimental-utils').TSESTree.TSTypeLiteral}*/ node, - ) { - node.members.forEach(member => { - if ( - member.type === AST_NODE_TYPES.TSPropertySignature && - member.key.type === AST_NODE_TYPES.Identifier && - member.key.name.startsWith('on') - ) { - const typeAnnotation = member.typeAnnotation?.typeAnnotation; - // Check if typeAnnotation is of type EventHandler - if ( - !( - typeAnnotation && - typeAnnotation.type === AST_NODE_TYPES.TSTypeReference && - typeAnnotation.typeName.type === AST_NODE_TYPES.Identifier && - typeAnnotation.typeName.name === 'EventHandler' && - typeAnnotation.typeParameters - ) - ) { - context.report({ - node: member, - messageId: 'invalidType', - }); - } + 'TSTypeAliasDeclaration[id.name=/.*Props$/]': function (node) { + typeAliasStack.push({ node, hasInnerTypeLiteral: false }); + }, + + // eslint-disable-next-line @typescript-eslint/naming-convention + TSTypeLiteral: (/** @type {import('@typescript-eslint/experimental-utils').TSESTree.TSTypeLiteral}*/ node) => { + if (typeAliasStack.length > 0) { + const top = typeAliasStack[typeAliasStack.length - 1]; + if (!top.hasInnerTypeLiteral) { + /** + * This is the first TSTypeLiteral node within the current TSTypeAliasDeclaration + * For this example: + * `type SomeProps3 = SomeArgBag & { someFunction?: (args: SomeArgBag) => void; };` + * it matches `{ someFunction?: (args: SomeArgBag) => void; }` + */ + top.hasInnerTypeLiteral = true; + + node.members.forEach(member => { + if ( + member.type === AST_NODE_TYPES.TSPropertySignature && + member.key.type === AST_NODE_TYPES.Identifier && + member.key.name.startsWith('on') + ) { + const typeAnnotation = member.typeAnnotation?.typeAnnotation; + // Check if typeAnnotation is of type EventHandler + if ( + !( + typeAnnotation && + typeAnnotation.type === AST_NODE_TYPES.TSTypeReference && + typeAnnotation.typeName.type === AST_NODE_TYPES.Identifier && + typeAnnotation.typeName.name === 'EventHandler' && + typeAnnotation.typeParameters + ) + ) { + context.report({ + node: member, + messageId: 'invalidType', + }); + } + } + }); } - }); + } + }, + + // eslint-disable-next-line @typescript-eslint/naming-convention + 'TSTypeAliasDeclaration:exit': function () { + typeAliasStack.pop(); }, }; }, diff --git a/packages/eslint-plugin/src/rules/consistent-callback-type/index.test.js b/packages/eslint-plugin/src/rules/consistent-callback-type/index.test.js index 0bcd236487e35..797574db3997a 100644 --- a/packages/eslint-plugin/src/rules/consistent-callback-type/index.test.js +++ b/packages/eslint-plugin/src/rules/consistent-callback-type/index.test.js @@ -39,7 +39,8 @@ ruleTester.run('consistent-callback-type', rule, { code: ` type SomeArgBag = { one: number }; export type SomeProps = { - someFunction?: (args: SomeArgBag) => void, + someFunction?: (args: SomeArgBag) => void; + someFunction2?: (args: { onSomething: string }) => void; // test nested TSTypeLiteral node that starts with 'on' }; `, filename: 'src/components/SomeComponent/SomeComponent.type.ts', From e94117620d8cb7b7a475938a6e717a6e50a98242 Mon Sep 17 00:00:00 2001 From: YuanboXue-Amber Date: Tue, 16 Jan 2024 20:10:32 +0100 Subject: [PATCH 15/31] update rule --- .../eslint-plugin/src/rules/consistent-callback-type/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-plugin/src/rules/consistent-callback-type/index.js b/packages/eslint-plugin/src/rules/consistent-callback-type/index.js index 3ed996fd1ea2b..27b87c1462120 100644 --- a/packages/eslint-plugin/src/rules/consistent-callback-type/index.js +++ b/packages/eslint-plugin/src/rules/consistent-callback-type/index.js @@ -49,7 +49,7 @@ module.exports = createRule({ if ( member.type === AST_NODE_TYPES.TSPropertySignature && member.key.type === AST_NODE_TYPES.Identifier && - member.key.name.startsWith('on') + /^on[A-Z]/.test(member.key.name) ) { const typeAnnotation = member.typeAnnotation?.typeAnnotation; // Check if typeAnnotation is of type EventHandler From 460b0127551b9ac527aa1d6c5139bb6094c8b01f Mon Sep 17 00:00:00 2001 From: YuanboXue-Amber Date: Tue, 16 Jan 2024 19:10:00 +0100 Subject: [PATCH 16/31] change matching glob to src instead of matching just *.types.ts --- packages/eslint-plugin/src/configs/react.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-plugin/src/configs/react.js b/packages/eslint-plugin/src/configs/react.js index 72dd35fd7d019..ce82b240f39c7 100644 --- a/packages/eslint-plugin/src/configs/react.js +++ b/packages/eslint-plugin/src/configs/react.js @@ -59,7 +59,7 @@ module.exports = { }, }, { - files: ['**/components/**/*.types.ts'], + files: ['**/src/**/*.{ts,tsx}'], rules: { '@fluentui/consistent-callback-type': 'error', }, From 2e5d96d86ee23c50f8b159566e2ab9c1195f54e9 Mon Sep 17 00:00:00 2001 From: YuanboXue-Amber Date: Wed, 17 Jan 2024 16:03:03 +0100 Subject: [PATCH 17/31] add lint disable after changing scope --- .../react-components/react-toast/src/components/Timer/Timer.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/react-components/react-toast/src/components/Timer/Timer.tsx b/packages/react-components/react-toast/src/components/Timer/Timer.tsx index ed29a8e4df5c5..597f70d32490c 100644 --- a/packages/react-components/react-toast/src/components/Timer/Timer.tsx +++ b/packages/react-components/react-toast/src/components/Timer/Timer.tsx @@ -4,6 +4,7 @@ import { useBaseAnimationStyles } from './useTimerStyles.styles'; export type TimerProps = { running: boolean; timeout: number; + // eslint-disable-next-line @fluentui/consistent-callback-type onTimeout: () => void; as?: 'span'; }; From ad5dbe230b81f58ec0c1dac2bfdfa7cfd09ac4ee Mon Sep 17 00:00:00 2001 From: YuanboXue-Amber Date: Wed, 17 Jan 2024 16:12:19 +0100 Subject: [PATCH 18/31] changelog --- ...i-react-toast-32f33ebb-12ce-4009-9088-06208e6bc563.json | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 change/@fluentui-react-toast-32f33ebb-12ce-4009-9088-06208e6bc563.json diff --git a/change/@fluentui-react-toast-32f33ebb-12ce-4009-9088-06208e6bc563.json b/change/@fluentui-react-toast-32f33ebb-12ce-4009-9088-06208e6bc563.json new file mode 100644 index 0000000000000..c0313f7526f0f --- /dev/null +++ b/change/@fluentui-react-toast-32f33ebb-12ce-4009-9088-06208e6bc563.json @@ -0,0 +1,7 @@ +{ + "type": "patch", + "comment": "chore: disable consistent-callback-type lint rule for existing callbacks", + "packageName": "@fluentui/react-toast", + "email": "yuanboxue@microsoft.com", + "dependentChangeType": "patch" +} From 91f6a2096516e8ea5bfc04ec71889441cad00647 Mon Sep 17 00:00:00 2001 From: YuanboXue-Amber Date: Wed, 17 Jan 2024 16:53:14 +0100 Subject: [PATCH 19/31] add lint disable --- .../react-combobox/src/utils/ComboboxBase.types.ts | 3 ++- .../react-combobox/src/utils/Selection.types.ts | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/react-components/react-combobox/src/utils/ComboboxBase.types.ts b/packages/react-components/react-combobox/src/utils/ComboboxBase.types.ts index f5ba8d3863910..aac44513da2a1 100644 --- a/packages/react-components/react-combobox/src/utils/ComboboxBase.types.ts +++ b/packages/react-components/react-combobox/src/utils/ComboboxBase.types.ts @@ -41,7 +41,8 @@ export type ComboboxBaseProps = SelectionProps & /** * Callback when the open/closed state of the dropdown changes */ - onOpenChange?: (e: ComboboxBaseOpenEvents, data: ComboboxBaseOpenChangeData) => void; + // eslint-disable-next-line @fluentui/consistent-callback-type + onOpenChange?: (e: ComboboxBaseOpenEvents, data: ComboboxBaseOpenChangeData) => void; // callback should be typed with EventHandler, but we can't break existing callbacks /** * Sets the open/closed state of the dropdown. diff --git a/packages/react-components/react-combobox/src/utils/Selection.types.ts b/packages/react-components/react-combobox/src/utils/Selection.types.ts index 6e8c6150c0094..6f97cee6e5491 100644 --- a/packages/react-components/react-combobox/src/utils/Selection.types.ts +++ b/packages/react-components/react-combobox/src/utils/Selection.types.ts @@ -17,7 +17,8 @@ export type SelectionProps = { multiselect?: boolean; /* Callback when an option is selected */ - onOptionSelect?: (event: SelectionEvents, data: OptionOnSelectData) => void; + // eslint-disable-next-line @fluentui/consistent-callback-type + onOptionSelect?: (event: SelectionEvents, data: OptionOnSelectData) => void; // callback should be typed with EventHandler, but we can't break existing callbacks /** * An array of selected option keys. From c66507f0f7961c533a74bf6abeb3320e89a8f3ab Mon Sep 17 00:00:00 2001 From: YuanboXue-Amber Date: Wed, 17 Jan 2024 16:56:38 +0100 Subject: [PATCH 20/31] changelog --- ...eact-combobox-536f8d48-97f5-47a6-8328-e9359bc62c1e.json | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 change/@fluentui-react-combobox-536f8d48-97f5-47a6-8328-e9359bc62c1e.json diff --git a/change/@fluentui-react-combobox-536f8d48-97f5-47a6-8328-e9359bc62c1e.json b/change/@fluentui-react-combobox-536f8d48-97f5-47a6-8328-e9359bc62c1e.json new file mode 100644 index 0000000000000..5b0668181a82c --- /dev/null +++ b/change/@fluentui-react-combobox-536f8d48-97f5-47a6-8328-e9359bc62c1e.json @@ -0,0 +1,7 @@ +{ + "type": "patch", + "comment": "chore: disable consistent-callback-type lint rule for existing callbacks", + "packageName": "@fluentui/react-combobox", + "email": "yuanboxue@microsoft.com", + "dependentChangeType": "patch" +} From 720bd99598d1829ff1b253742d1f67215d443782 Mon Sep 17 00:00:00 2001 From: YuanboXue-Amber Date: Wed, 17 Jan 2024 18:24:43 +0100 Subject: [PATCH 21/31] put comment together with disable --- .../src/components/Accordion/Accordion.types.ts | 4 ++-- .../react-card/src/components/Card/Card.types.ts | 4 ++-- .../src/components/Checkbox/Checkbox.types.ts | 4 ++-- .../react-combobox/src/utils/ComboboxBase.types.ts | 4 ++-- .../react-combobox/src/utils/Selection.types.ts | 4 ++-- .../src/components/DatePicker/DatePicker.types.ts | 12 ++++++------ .../src/components/Dialog/Dialog.types.ts | 4 ++-- .../react-input/src/components/Input/Input.types.ts | 4 ++-- .../react-menu/src/components/Menu/Menu.types.ts | 4 ++-- .../src/components/MenuList/MenuList.types.ts | 4 ++-- .../src/components/MenuTrigger/MenuTrigger.types.ts | 3 +-- .../src/components/List/List/List.types.ts | 4 ++-- .../src/components/Popover/Popover.types.ts | 4 ++-- .../PopoverTrigger/PopoverTrigger.types.ts | 3 +-- .../react-radio/src/components/Radio/Radio.types.ts | 4 ++-- .../src/components/RadioGroup/RadioGroup.types.ts | 4 ++-- .../src/components/Rating/Rating.types.ts | 4 ++-- .../src/components/Select/Select.types.ts | 4 ++-- .../src/components/Slider/Slider.types.ts | 4 ++-- .../src/components/SpinButton/SpinButton.types.ts | 4 ++-- .../src/components/Switch/Switch.types.ts | 4 ++-- .../src/components/DataGrid/DataGrid.types.ts | 7 +++---- .../src/components/TabList/TabList.types.ts | 4 ++-- .../src/components/TagGroup/TagGroup.types.ts | 4 ++-- .../TeachingPopover/TeachingPopover.types.ts | 3 +-- .../src/components/Textarea/Textarea.types.ts | 4 ++-- .../src/components/TimePicker/TimePicker.types.ts | 4 ++-- .../react-toast/src/components/Timer/Timer.tsx | 2 +- .../src/components/Toolbar/Toolbar.types.ts | 4 ++-- .../src/components/Tooltip/Tooltip.types.ts | 4 ++-- .../src/components/TreeItem/TreeItem.types.ts | 4 ++-- .../src/components/Virtualizer/Virtualizer.types.ts | 4 ++-- 32 files changed, 65 insertions(+), 69 deletions(-) diff --git a/packages/react-components/react-accordion/src/components/Accordion/Accordion.types.ts b/packages/react-components/react-accordion/src/components/Accordion/Accordion.types.ts index 8a01710718c21..864cc08539575 100644 --- a/packages/react-components/react-accordion/src/components/Accordion/Accordion.types.ts +++ b/packages/react-components/react-accordion/src/components/Accordion/Accordion.types.ts @@ -49,8 +49,8 @@ export type AccordionProps = ComponentProps; // callback should be typed with EventHandler, but we can't break existing callbacks + // eslint-disable-next-line @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks + onToggle?: AccordionToggleEventHandler; /** * Controls the state of the panel. diff --git a/packages/react-components/react-card/src/components/Card/Card.types.ts b/packages/react-components/react-card/src/components/Card/Card.types.ts index c983bf209f0d0..8a30e0cb8764b 100644 --- a/packages/react-components/react-card/src/components/Card/Card.types.ts +++ b/packages/react-components/react-card/src/components/Card/Card.types.ts @@ -124,8 +124,8 @@ export type CardProps = ComponentProps & { /** * Callback to be called when the selected state value changes. */ - // eslint-disable-next-line @fluentui/consistent-callback-type - onSelectionChange?: (event: CardOnSelectionChangeEvent, data: CardOnSelectData) => void; // callback should be typed with EventHandler, but we can't break existing callbacks + // eslint-disable-next-line @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks + onSelectionChange?: (event: CardOnSelectionChangeEvent, data: CardOnSelectData) => void; }; /** diff --git a/packages/react-components/react-checkbox/src/components/Checkbox/Checkbox.types.ts b/packages/react-components/react-checkbox/src/components/Checkbox/Checkbox.types.ts index 58061399a4e0c..80524e865f3e6 100644 --- a/packages/react-components/react-checkbox/src/components/Checkbox/Checkbox.types.ts +++ b/packages/react-components/react-checkbox/src/components/Checkbox/Checkbox.types.ts @@ -64,8 +64,8 @@ export type CheckboxProps = Omit< /** * Callback to be called when the checked state value changes. */ - // eslint-disable-next-line @fluentui/consistent-callback-type - onChange?: (ev: React.ChangeEvent, data: CheckboxOnChangeData) => void; // callback should be typed with EventHandler, but we can't break existing callbacks + // eslint-disable-next-line @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks + onChange?: (ev: React.ChangeEvent, data: CheckboxOnChangeData) => void; /** * The shape of the checkbox indicator. diff --git a/packages/react-components/react-combobox/src/utils/ComboboxBase.types.ts b/packages/react-components/react-combobox/src/utils/ComboboxBase.types.ts index aac44513da2a1..fd256d6a928e6 100644 --- a/packages/react-components/react-combobox/src/utils/ComboboxBase.types.ts +++ b/packages/react-components/react-combobox/src/utils/ComboboxBase.types.ts @@ -41,8 +41,8 @@ export type ComboboxBaseProps = SelectionProps & /** * Callback when the open/closed state of the dropdown changes */ - // eslint-disable-next-line @fluentui/consistent-callback-type - onOpenChange?: (e: ComboboxBaseOpenEvents, data: ComboboxBaseOpenChangeData) => void; // callback should be typed with EventHandler, but we can't break existing callbacks + // eslint-disable-next-line @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks + onOpenChange?: (e: ComboboxBaseOpenEvents, data: ComboboxBaseOpenChangeData) => void; /** * Sets the open/closed state of the dropdown. diff --git a/packages/react-components/react-combobox/src/utils/Selection.types.ts b/packages/react-components/react-combobox/src/utils/Selection.types.ts index 6f97cee6e5491..f701dee3ef766 100644 --- a/packages/react-components/react-combobox/src/utils/Selection.types.ts +++ b/packages/react-components/react-combobox/src/utils/Selection.types.ts @@ -17,8 +17,8 @@ export type SelectionProps = { multiselect?: boolean; /* Callback when an option is selected */ - // eslint-disable-next-line @fluentui/consistent-callback-type - onOptionSelect?: (event: SelectionEvents, data: OptionOnSelectData) => void; // callback should be typed with EventHandler, but we can't break existing callbacks + // eslint-disable-next-line @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks + onOptionSelect?: (event: SelectionEvents, data: OptionOnSelectData) => void; /** * An array of selected option keys. diff --git a/packages/react-components/react-datepicker-compat/src/components/DatePicker/DatePicker.types.ts b/packages/react-components/react-datepicker-compat/src/components/DatePicker/DatePicker.types.ts index a4f5b33ee0b5f..74794f07f548e 100644 --- a/packages/react-components/react-datepicker-compat/src/components/DatePicker/DatePicker.types.ts +++ b/packages/react-components/react-datepicker-compat/src/components/DatePicker/DatePicker.types.ts @@ -16,8 +16,8 @@ export type DatePickerProps = Omit>, 'de /** * Callback issued when a date is selected */ - // eslint-disable-next-line @fluentui/consistent-callback-type - onSelectDate?: (date: Date | null | undefined) => void; // callback should be typed with EventHandler, but we can't break existing callbacks + // eslint-disable-next-line @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks + onSelectDate?: (date: Date | null | undefined) => void; /** * Whether the DatePicker is a required field or not. When using ``, this prop is automatically set. @@ -85,14 +85,14 @@ export type DatePickerProps = Omit>, 'de /** * Callback to run when the DatePicker's open state changes */ - // eslint-disable-next-line @fluentui/consistent-callback-type - onOpenChange?: (open: boolean) => void; // callback should be typed with EventHandler, but we can't break existing callbacks + // eslint-disable-next-line @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks + onOpenChange?: (open: boolean) => void; /** * Callback to run after the DatePicker's input has been validated */ - // eslint-disable-next-line @fluentui/consistent-callback-type - onValidationResult?: (data: DatePickerValidationResultData) => void; // callback should be typed with EventHandler, but we can't break existing callbacks + // eslint-disable-next-line @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks + onValidationResult?: (data: DatePickerValidationResultData) => void; /** * Whether the DatePicker should render the popup as inline or in a portal diff --git a/packages/react-components/react-dialog/src/components/Dialog/Dialog.types.ts b/packages/react-components/react-dialog/src/components/Dialog/Dialog.types.ts index a5ced052550e9..8534436ebeacc 100644 --- a/packages/react-components/react-dialog/src/components/Dialog/Dialog.types.ts +++ b/packages/react-components/react-dialog/src/components/Dialog/Dialog.types.ts @@ -81,8 +81,8 @@ export type DialogProps = ComponentProps> & { * @param data - A data object with relevant information, * such as open value and type of interaction that created the event */ - // eslint-disable-next-line @fluentui/consistent-callback-type - onOpenChange?: DialogOpenChangeEventHandler; // callback should be typed with EventHandler, but we can't break existing callbacks + // eslint-disable-next-line @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks + onOpenChange?: DialogOpenChangeEventHandler; /** * Can contain two children including {@link DialogTrigger} and {@link DialogSurface}. * Alternatively can only contain {@link DialogSurface} if using trigger outside dialog, or controlling state. diff --git a/packages/react-components/react-input/src/components/Input/Input.types.ts b/packages/react-components/react-input/src/components/Input/Input.types.ts index 3ed1dd9f91932..38f9fe316f721 100644 --- a/packages/react-components/react-input/src/components/Input/Input.types.ts +++ b/packages/react-components/react-input/src/components/Input/Input.types.ts @@ -77,8 +77,8 @@ export type InputProps = Omit< /** * Called when the user changes the input's value. */ - // eslint-disable-next-line @fluentui/consistent-callback-type - onChange?: (ev: React.ChangeEvent, data: InputOnChangeData) => void; // callback should be typed with EventHandler, but we can't break existing callbacks + // eslint-disable-next-line @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks + onChange?: (ev: React.ChangeEvent, data: InputOnChangeData) => void; /** * An input can have different text-based [types](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input#input_types) diff --git a/packages/react-components/react-menu/src/components/Menu/Menu.types.ts b/packages/react-components/react-menu/src/components/Menu/Menu.types.ts index 9c62597c55534..5583dcc935ea9 100644 --- a/packages/react-components/react-menu/src/components/Menu/Menu.types.ts +++ b/packages/react-components/react-menu/src/components/Menu/Menu.types.ts @@ -40,8 +40,8 @@ export type MenuProps = ComponentProps & * Call back when the component requests to change value * The `open` value is used as a hint when directly controlling the component */ - // eslint-disable-next-line @fluentui/consistent-callback-type - onOpenChange?: (e: MenuOpenEvent, data: MenuOpenChangeData) => void; // callback should be typed with EventHandler, but we can't break existing callbacks + // eslint-disable-next-line @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks + onOpenChange?: (e: MenuOpenEvent, data: MenuOpenChangeData) => void; /** * Whether the popup is open diff --git a/packages/react-components/react-menu/src/components/MenuList/MenuList.types.ts b/packages/react-components/react-menu/src/components/MenuList/MenuList.types.ts index 00b7002cabbb2..586cc8a748003 100644 --- a/packages/react-components/react-menu/src/components/MenuList/MenuList.types.ts +++ b/packages/react-components/react-menu/src/components/MenuList/MenuList.types.ts @@ -43,8 +43,8 @@ export type MenuListProps = ComponentProps & { * @param event - React's original SyntheticEvent * @param data - A data object with relevant information */ - // eslint-disable-next-line @fluentui/consistent-callback-type - onCheckedValueChange?: (e: MenuCheckedValueChangeEvent, data: MenuCheckedValueChangeData) => void; // callback should be typed with EventHandler, but we can't break existing callbacks + // eslint-disable-next-line @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks + onCheckedValueChange?: (e: MenuCheckedValueChangeEvent, data: MenuCheckedValueChangeData) => void; }; export type MenuListState = ComponentState & diff --git a/packages/react-components/react-menu/src/components/MenuTrigger/MenuTrigger.types.ts b/packages/react-components/react-menu/src/components/MenuTrigger/MenuTrigger.types.ts index 81fb829f0b77e..17cf501ebc791 100644 --- a/packages/react-components/react-menu/src/components/MenuTrigger/MenuTrigger.types.ts +++ b/packages/react-components/react-menu/src/components/MenuTrigger/MenuTrigger.types.ts @@ -20,8 +20,7 @@ export type MenuTriggerChildProps; - /* eslint-disable @fluentui/consistent-callback-type */ - // callback should be typed with EventHandler, but we can't break existing callbacks + /* eslint-disable @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks */ onMouseEnter: React.MouseEventHandler; onMouseLeave: React.MouseEventHandler; onMouseMove: React.MouseEventHandler; diff --git a/packages/react-components/react-migration-v0-v9/src/components/List/List/List.types.ts b/packages/react-components/react-migration-v0-v9/src/components/List/List/List.types.ts index 70707fa271561..bdb9a8b785697 100644 --- a/packages/react-components/react-migration-v0-v9/src/components/List/List/List.types.ts +++ b/packages/react-components/react-migration-v0-v9/src/components/List/List/List.types.ts @@ -53,8 +53,8 @@ export type ListProps = ComponentProps & { /** * Callback for selection change events, used for both controlled and uncontrolled (as notification) */ - // eslint-disable-next-line @fluentui/consistent-callback-type - onSelectionChange?: (event: React.SyntheticEvent, data: { selectedItems: SelectionItemId[] }) => void; // callback should be typed with EventHandler, but we can't break existing callbacks + // eslint-disable-next-line @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks + onSelectionChange?: (event: React.SyntheticEvent, data: { selectedItems: SelectionItemId[] }) => void; /** * Truncates header diff --git a/packages/react-components/react-popover/src/components/Popover/Popover.types.ts b/packages/react-components/react-popover/src/components/Popover/Popover.types.ts index 5eb51e42ca02a..2b1060670a8ae 100644 --- a/packages/react-components/react-popover/src/components/Popover/Popover.types.ts +++ b/packages/react-components/react-popover/src/components/Popover/Popover.types.ts @@ -64,8 +64,8 @@ export type PopoverProps = Pick & { * Call back when the component requests to change value * The `open` value is used as a hint when directly controlling the component */ - // eslint-disable-next-line @fluentui/consistent-callback-type - onOpenChange?: (e: OpenPopoverEvents, data: OnOpenChangeData) => void; // callback should be typed with EventHandler, but we can't break existing callbacks + // eslint-disable-next-line @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks + onOpenChange?: (e: OpenPopoverEvents, data: OnOpenChangeData) => void; /** * Controls the opening of the Popover diff --git a/packages/react-components/react-popover/src/components/PopoverTrigger/PopoverTrigger.types.ts b/packages/react-components/react-popover/src/components/PopoverTrigger/PopoverTrigger.types.ts index 42a20e69c6de1..3afe02fac745b 100644 --- a/packages/react-components/react-popover/src/components/PopoverTrigger/PopoverTrigger.types.ts +++ b/packages/react-components/react-popover/src/components/PopoverTrigger/PopoverTrigger.types.ts @@ -28,8 +28,7 @@ export type PopoverTriggerChildProps; - /* eslint-disable @fluentui/consistent-callback-type */ - // callback should be typed with EventHandler, but we can't break existing callbacks + /* eslint-disable @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks */ onMouseEnter: React.MouseEventHandler; onMouseLeave: React.MouseEventHandler; onContextMenu: React.MouseEventHandler; diff --git a/packages/react-components/react-radio/src/components/Radio/Radio.types.ts b/packages/react-components/react-radio/src/components/Radio/Radio.types.ts index b5b9ed9e789d7..41c5c1d795a9e 100644 --- a/packages/react-components/react-radio/src/components/Radio/Radio.types.ts +++ b/packages/react-components/react-radio/src/components/Radio/Radio.types.ts @@ -60,8 +60,8 @@ export type RadioProps = Omit, 'input'>, 'onC * **Note:** `onChange` is NOT called when this Radio is deselected. * Use RadioGroup's `onChange` event to determine when the selection in the group changes. */ - // eslint-disable-next-line @fluentui/consistent-callback-type - onChange?: (ev: React.ChangeEvent, data: RadioOnChangeData) => void; // callback should be typed with EventHandler, but we can't break existing callbacks + // eslint-disable-next-line @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks + onChange?: (ev: React.ChangeEvent, data: RadioOnChangeData) => void; }; /** diff --git a/packages/react-components/react-radio/src/components/RadioGroup/RadioGroup.types.ts b/packages/react-components/react-radio/src/components/RadioGroup/RadioGroup.types.ts index 1b7c1dba8692b..3180da2bd8cb3 100644 --- a/packages/react-components/react-radio/src/components/RadioGroup/RadioGroup.types.ts +++ b/packages/react-components/react-radio/src/components/RadioGroup/RadioGroup.types.ts @@ -33,8 +33,8 @@ export type RadioGroupProps = Omit>, 'on /** * Callback when the selected Radio item changes. */ - // eslint-disable-next-line @fluentui/consistent-callback-type - onChange?: (ev: React.FormEvent, data: RadioGroupOnChangeData) => void; // callback should be typed with EventHandler, but we can't break existing callbacks + // eslint-disable-next-line @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks + onChange?: (ev: React.FormEvent, data: RadioGroupOnChangeData) => void; /** * How the radio items are laid out in the group. diff --git a/packages/react-components/react-rating-preview/src/components/Rating/Rating.types.ts b/packages/react-components/react-rating-preview/src/components/Rating/Rating.types.ts index c8d53d62a41c1..ff60927c43004 100644 --- a/packages/react-components/react-rating-preview/src/components/Rating/Rating.types.ts +++ b/packages/react-components/react-rating-preview/src/components/Rating/Rating.types.ts @@ -46,8 +46,8 @@ export type RatingProps = ComponentProps & { /** * Callback when the rating value is changed by the user. */ - // eslint-disable-next-line @fluentui/consistent-callback-type - onChange?: (ev: React.SyntheticEvent | Event, data: RatingOnChangeData) => void; // callback should be typed with EventHandler, but we can't break existing callbacks + // eslint-disable-next-line @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks + onChange?: (ev: React.SyntheticEvent | Event, data: RatingOnChangeData) => void; /** * Sets the precision to allow half-filled shapes in Rating * @default 1 diff --git a/packages/react-components/react-select/src/components/Select/Select.types.ts b/packages/react-components/react-select/src/components/Select/Select.types.ts index 8391b292ff413..eeacafe79e66d 100644 --- a/packages/react-components/react-select/src/components/Select/Select.types.ts +++ b/packages/react-components/react-select/src/components/Select/Select.types.ts @@ -27,8 +27,8 @@ export type SelectProps = Omit, 'select'>, ' /** * Called when the user changes the select element's value by selecting an option. */ - // eslint-disable-next-line @fluentui/consistent-callback-type - onChange?: (ev: React.ChangeEvent, data: SelectOnChangeData) => void; // callback should be typed with EventHandler, but we can't break existing callbacks + // eslint-disable-next-line @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks + onChange?: (ev: React.ChangeEvent, data: SelectOnChangeData) => void; /** * Matches the Input sizes diff --git a/packages/react-components/react-slider/src/components/Slider/Slider.types.ts b/packages/react-components/react-slider/src/components/Slider/Slider.types.ts index 0eeb9a4e1116a..9f227636efaa5 100644 --- a/packages/react-components/react-slider/src/components/Slider/Slider.types.ts +++ b/packages/react-components/react-slider/src/components/Slider/Slider.types.ts @@ -94,8 +94,8 @@ export type SliderProps = Omit< /** * Triggers a callback when the value has been changed. This will be called on every individual step. */ - // eslint-disable-next-line @fluentui/consistent-callback-type - onChange?: (ev: React.ChangeEvent, data: SliderOnChangeData) => void; // callback should be typed with EventHandler, but we can't break existing callbacks + // eslint-disable-next-line @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks + onChange?: (ev: React.ChangeEvent, data: SliderOnChangeData) => void; }; export type SliderOnChangeData = { diff --git a/packages/react-components/react-spinbutton/src/components/SpinButton/SpinButton.types.ts b/packages/react-components/react-spinbutton/src/components/SpinButton/SpinButton.types.ts index 06aa5746c3ed9..f541ce87f92e6 100644 --- a/packages/react-components/react-spinbutton/src/components/SpinButton/SpinButton.types.ts +++ b/packages/react-components/react-spinbutton/src/components/SpinButton/SpinButton.types.ts @@ -80,8 +80,8 @@ export type SpinButtonProps = Omit< * - User *commits* edits to the input text by focusing away (blurring) or pressing enter. * Note that this is NOT called for every key press while the user is editing. */ - // eslint-disable-next-line @fluentui/consistent-callback-type - onChange?: (event: SpinButtonChangeEvent, data: SpinButtonOnChangeData) => void; // callback should be typed with EventHandler, but we can't break existing callbacks + // eslint-disable-next-line @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks + onChange?: (event: SpinButtonChangeEvent, data: SpinButtonOnChangeData) => void; /** * How many decimal places the value should be rounded to. diff --git a/packages/react-components/react-switch/src/components/Switch/Switch.types.ts b/packages/react-components/react-switch/src/components/Switch/Switch.types.ts index ffebec243c372..cddd303cb1a19 100644 --- a/packages/react-components/react-switch/src/components/Switch/Switch.types.ts +++ b/packages/react-components/react-switch/src/components/Switch/Switch.types.ts @@ -68,8 +68,8 @@ export type SwitchProps = Omit< /** * Callback to be called when the checked state value changes. */ - // eslint-disable-next-line @fluentui/consistent-callback-type - onChange?: (ev: React.ChangeEvent, data: SwitchOnChangeData) => void; // callback should be typed with EventHandler, but we can't break existing callbacks + // eslint-disable-next-line @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks + onChange?: (ev: React.ChangeEvent, data: SwitchOnChangeData) => void; }; /** diff --git a/packages/react-components/react-table/src/components/DataGrid/DataGrid.types.ts b/packages/react-components/react-table/src/components/DataGrid/DataGrid.types.ts index 7097189b653a1..7a5539755a450 100644 --- a/packages/react-components/react-table/src/components/DataGrid/DataGrid.types.ts +++ b/packages/react-components/react-table/src/components/DataGrid/DataGrid.types.ts @@ -64,8 +64,7 @@ export type DataGridProps = TableProps & Pick, 'focusMode' | 'subtleSelection' | 'selectionAppearance' | 'resizableColumns'> & Pick & Pick & { - /* eslint-disable @fluentui/consistent-callback-type */ - // callback should be typed with EventHandler, but we can't break existing callbacks + /* eslint-disable @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks */ onSortChange?: (e: React.MouseEvent, sortState: SortState) => void; onSelectionChange?: (e: React.MouseEvent | React.KeyboardEvent, data: OnSelectionChangeData) => void; /* eslint-enable @fluentui/consistent-callback-type */ @@ -82,11 +81,11 @@ export type DataGridProps = TableProps & /** * A callback triggered when a column is resized. */ - // eslint-disable-next-line @fluentui/consistent-callback-type + // eslint-disable-next-line @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks onColumnResize?: ( e: KeyboardEvent | TouchEvent | MouseEvent | undefined, data: { columnId: TableColumnId; width: number }, - ) => void; // callback should be typed with EventHandler, but we can't break existing callbacks + ) => void; /** * For column resizing. Allows for a container size to be adjusted by a number of pixels, to make * sure the columns don't overflow the table. diff --git a/packages/react-components/react-tabs/src/components/TabList/TabList.types.ts b/packages/react-components/react-tabs/src/components/TabList/TabList.types.ts index 446b678922853..d22ed48d17dd3 100644 --- a/packages/react-components/react-tabs/src/components/TabList/TabList.types.ts +++ b/packages/react-components/react-tabs/src/components/TabList/TabList.types.ts @@ -71,8 +71,8 @@ export type TabListProps = ComponentProps & { /** * Raised when a tab is selected. */ - // eslint-disable-next-line @fluentui/consistent-callback-type - onTabSelect?: SelectTabEventHandler; // callback should be typed with EventHandler, but we can't break existing callbacks + // eslint-disable-next-line @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks + onTabSelect?: SelectTabEventHandler; /** * When true, focusing a tab will select it. diff --git a/packages/react-components/react-tags/src/components/TagGroup/TagGroup.types.ts b/packages/react-components/react-tags/src/components/TagGroup/TagGroup.types.ts index 5c93fcf8434ac..bd70e6fbbca48 100644 --- a/packages/react-components/react-tags/src/components/TagGroup/TagGroup.types.ts +++ b/packages/react-components/react-tags/src/components/TagGroup/TagGroup.types.ts @@ -17,8 +17,8 @@ export type TagGroupProps = ComponentProps & { /** * Callback for when a tag is dismissed */ - // eslint-disable-next-line @fluentui/consistent-callback-type - onDismiss?: TagDismissHandler; // callback should be typed with EventHandler, but we can't break existing callbacks + // eslint-disable-next-line @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks + onDismiss?: TagDismissHandler; size?: TagSize; }; diff --git a/packages/react-components/react-teaching-popover-preview/src/components/TeachingPopover/TeachingPopover.types.ts b/packages/react-components/react-teaching-popover-preview/src/components/TeachingPopover/TeachingPopover.types.ts index 572287a5e857b..941488314d11d 100644 --- a/packages/react-components/react-teaching-popover-preview/src/components/TeachingPopover/TeachingPopover.types.ts +++ b/packages/react-components/react-teaching-popover-preview/src/components/TeachingPopover/TeachingPopover.types.ts @@ -15,8 +15,7 @@ export type TeachingPopoverProps = Omit & { */ currentPage?: number; - /* eslint-disable @fluentui/consistent-callback-type */ - // callback should be typed with EventHandler, but we can't break existing callbacks + /* eslint-disable @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks */ /** * Callback to notify a page change (can be used to update 'currentPage' externally). */ diff --git a/packages/react-components/react-textarea/src/components/Textarea/Textarea.types.ts b/packages/react-components/react-textarea/src/components/Textarea/Textarea.types.ts index d7bcd28f9cde9..f85a4912a938c 100644 --- a/packages/react-components/react-textarea/src/components/Textarea/Textarea.types.ts +++ b/packages/react-components/react-textarea/src/components/Textarea/Textarea.types.ts @@ -40,8 +40,8 @@ export type TextareaProps = Omit< /** * Callback for when the user changes the value. */ - // eslint-disable-next-line @fluentui/consistent-callback-type - onChange?: (ev: React.ChangeEvent, data: TextareaOnChangeData) => void; // callback should be typed with EventHandler, but we can't break existing callbacks + // eslint-disable-next-line @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks + onChange?: (ev: React.ChangeEvent, data: TextareaOnChangeData) => void; /** * Which direction the Textarea is allowed to be resized. diff --git a/packages/react-components/react-timepicker-compat/src/components/TimePicker/TimePicker.types.ts b/packages/react-components/react-timepicker-compat/src/components/TimePicker/TimePicker.types.ts index d5508a0d72625..226a33ce95c55 100644 --- a/packages/react-components/react-timepicker-compat/src/components/TimePicker/TimePicker.types.ts +++ b/packages/react-components/react-timepicker-compat/src/components/TimePicker/TimePicker.types.ts @@ -145,8 +145,8 @@ export type TimePickerProps = Omit, 'input /** * Callback for when a time selection is made. */ - // eslint-disable-next-line @fluentui/consistent-callback-type - onTimeChange?: (event: TimeSelectionEvents, data: TimeSelectionData) => void; // callback should be typed with EventHandler, but we can't break existing callbacks + // eslint-disable-next-line @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks + onTimeChange?: (event: TimeSelectionEvents, data: TimeSelectionData) => void; /** * Customizes the formatting of date strings displayed in dropdown options. diff --git a/packages/react-components/react-toast/src/components/Timer/Timer.tsx b/packages/react-components/react-toast/src/components/Timer/Timer.tsx index 597f70d32490c..2dc8c68952aed 100644 --- a/packages/react-components/react-toast/src/components/Timer/Timer.tsx +++ b/packages/react-components/react-toast/src/components/Timer/Timer.tsx @@ -4,7 +4,7 @@ import { useBaseAnimationStyles } from './useTimerStyles.styles'; export type TimerProps = { running: boolean; timeout: number; - // eslint-disable-next-line @fluentui/consistent-callback-type + // eslint-disable-next-line @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks onTimeout: () => void; as?: 'span'; }; diff --git a/packages/react-components/react-toolbar/src/components/Toolbar/Toolbar.types.ts b/packages/react-components/react-toolbar/src/components/Toolbar/Toolbar.types.ts index d3a26644e78c6..0fbcff2a19c04 100644 --- a/packages/react-components/react-toolbar/src/components/Toolbar/Toolbar.types.ts +++ b/packages/react-components/react-toolbar/src/components/Toolbar/Toolbar.types.ts @@ -47,8 +47,8 @@ export type ToolbarProps = ComponentProps & { * @param event - React's original SyntheticEvent * @param data - A data object with relevant information */ - // eslint-disable-next-line @fluentui/consistent-callback-type - onCheckedValueChange?: (e: ToolbarCheckedValueChangeEvent, data: ToolbarCheckedValueChangeData) => void; // callback should be typed with EventHandler, but we can't break existing callbacks + // eslint-disable-next-line @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks + onCheckedValueChange?: (e: ToolbarCheckedValueChangeEvent, data: ToolbarCheckedValueChangeData) => void; }; /** diff --git a/packages/react-components/react-tooltip/src/components/Tooltip/Tooltip.types.ts b/packages/react-components/react-tooltip/src/components/Tooltip/Tooltip.types.ts index 5ed584deec9f7..9f36f9a686724 100644 --- a/packages/react-components/react-tooltip/src/components/Tooltip/Tooltip.types.ts +++ b/packages/react-components/react-tooltip/src/components/Tooltip/Tooltip.types.ts @@ -63,11 +63,11 @@ export type TooltipProps = ComponentProps & * **Note**: for backwards compatibility, `event` will be undefined if this was triggered by a keyboard event on * the document element. Use `data.documentKeyboardEvent` if the keyboard event object is needed. */ - // eslint-disable-next-line @fluentui/consistent-callback-type + // eslint-disable-next-line @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks onVisibleChange?: ( event: React.PointerEvent | React.FocusEvent | undefined, data: OnVisibleChangeData, - ) => void; // callback should be typed with EventHandler, but we can't break existing callbacks + ) => void; /** * Configure the positioning of the tooltip diff --git a/packages/react-components/react-tree/src/components/TreeItem/TreeItem.types.ts b/packages/react-components/react-tree/src/components/TreeItem/TreeItem.types.ts index 426826d6f4906..7b4371e88cf8c 100644 --- a/packages/react-components/react-tree/src/components/TreeItem/TreeItem.types.ts +++ b/packages/react-components/react-tree/src/components/TreeItem/TreeItem.types.ts @@ -54,8 +54,8 @@ export type TreeItemProps = ComponentProps> & { * NOTE: controlling the open state of a tree item will not affect the open state of its children */ open?: boolean; - // eslint-disable-next-line @fluentui/consistent-callback-type - onOpenChange?: (e: TreeItemOpenChangeEvent, data: TreeItemOpenChangeData) => void; // callback should be typed with EventHandler, but we can't break existing callbacks + // eslint-disable-next-line @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks + onOpenChange?: (e: TreeItemOpenChangeEvent, data: TreeItemOpenChangeData) => void; /** * This property is inferred through context on a nested tree, and required for a flat tree. */ diff --git a/packages/react-components/react-virtualizer/src/components/Virtualizer/Virtualizer.types.ts b/packages/react-components/react-virtualizer/src/components/Virtualizer/Virtualizer.types.ts index 934c460865661..c1e41bad3fd17 100644 --- a/packages/react-components/react-virtualizer/src/components/Virtualizer/Virtualizer.types.ts +++ b/packages/react-components/react-virtualizer/src/components/Virtualizer/Virtualizer.types.ts @@ -159,8 +159,8 @@ export type VirtualizerConfigProps = { /** * Callback for notifying when a flagged index has been rendered */ - // eslint-disable-next-line @fluentui/consistent-callback-type - onRenderedFlaggedIndex?: (index: number) => void; // callback should be typed with EventHandler, but we can't break existing callbacks + // eslint-disable-next-line @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks + onRenderedFlaggedIndex?: (index: number) => void; /* * Callback for notifying when a flagged index has been rendered From b98d9f8eac02205c6fbf1ca0982001cde2853dec Mon Sep 17 00:00:00 2001 From: YuanboXue-Amber Date: Thu, 18 Jan 2024 11:47:49 +0100 Subject: [PATCH 22/31] update comments --- .../src/components/Accordion/Accordion.types.ts | 2 +- .../react-card/src/components/Card/Card.types.ts | 2 +- .../src/components/Checkbox/Checkbox.types.ts | 2 +- .../react-combobox/src/utils/ComboboxBase.types.ts | 2 +- .../react-combobox/src/utils/Selection.types.ts | 2 +- .../src/components/DatePicker/DatePicker.types.ts | 6 +++--- .../react-dialog/src/components/Dialog/Dialog.types.ts | 2 +- .../react-input/src/components/Input/Input.types.ts | 2 +- .../react-menu/src/components/Menu/Menu.types.ts | 2 +- .../react-menu/src/components/MenuList/MenuList.types.ts | 2 +- .../src/components/MenuTrigger/MenuTrigger.types.ts | 2 +- .../src/components/List/List/List.types.ts | 2 +- .../react-popover/src/components/Popover/Popover.types.ts | 2 +- .../src/components/PopoverTrigger/PopoverTrigger.types.ts | 2 +- .../react-radio/src/components/Radio/Radio.types.ts | 2 +- .../src/components/RadioGroup/RadioGroup.types.ts | 2 +- .../src/components/Rating/Rating.types.ts | 2 +- .../react-select/src/components/Select/Select.types.ts | 2 +- .../react-slider/src/components/Slider/Slider.types.ts | 2 +- .../src/components/SpinButton/SpinButton.types.ts | 2 +- .../react-switch/src/components/Switch/Switch.types.ts | 2 +- .../react-table/src/components/DataGrid/DataGrid.types.ts | 4 ++-- .../react-tabs/src/components/TabList/TabList.types.ts | 2 +- .../react-tags/src/components/TagGroup/TagGroup.types.ts | 2 +- .../src/components/TeachingPopover/TeachingPopover.types.ts | 2 +- .../src/components/Textarea/Textarea.types.ts | 2 +- .../src/components/TimePicker/TimePicker.types.ts | 2 +- .../react-toast/src/components/Timer/Timer.tsx | 2 +- .../react-toolbar/src/components/Toolbar/Toolbar.types.ts | 2 +- .../react-tooltip/src/components/Tooltip/Tooltip.types.ts | 2 +- .../react-tree/src/components/TreeItem/TreeItem.types.ts | 2 +- .../src/components/Virtualizer/Virtualizer.types.ts | 2 +- 32 files changed, 35 insertions(+), 35 deletions(-) diff --git a/packages/react-components/react-accordion/src/components/Accordion/Accordion.types.ts b/packages/react-components/react-accordion/src/components/Accordion/Accordion.types.ts index 864cc08539575..492df43055e16 100644 --- a/packages/react-components/react-accordion/src/components/Accordion/Accordion.types.ts +++ b/packages/react-components/react-accordion/src/components/Accordion/Accordion.types.ts @@ -49,7 +49,7 @@ export type AccordionProps = ComponentProps; /** diff --git a/packages/react-components/react-card/src/components/Card/Card.types.ts b/packages/react-components/react-card/src/components/Card/Card.types.ts index 8a30e0cb8764b..67e7c26c77355 100644 --- a/packages/react-components/react-card/src/components/Card/Card.types.ts +++ b/packages/react-components/react-card/src/components/Card/Card.types.ts @@ -124,7 +124,7 @@ export type CardProps = ComponentProps & { /** * Callback to be called when the selected state value changes. */ - // eslint-disable-next-line @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks + // eslint-disable-next-line @fluentui/consistent-callback-type -- can't change type of existing callback onSelectionChange?: (event: CardOnSelectionChangeEvent, data: CardOnSelectData) => void; }; diff --git a/packages/react-components/react-checkbox/src/components/Checkbox/Checkbox.types.ts b/packages/react-components/react-checkbox/src/components/Checkbox/Checkbox.types.ts index 80524e865f3e6..7735e8c03cbf9 100644 --- a/packages/react-components/react-checkbox/src/components/Checkbox/Checkbox.types.ts +++ b/packages/react-components/react-checkbox/src/components/Checkbox/Checkbox.types.ts @@ -64,7 +64,7 @@ export type CheckboxProps = Omit< /** * Callback to be called when the checked state value changes. */ - // eslint-disable-next-line @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks + // eslint-disable-next-line @fluentui/consistent-callback-type -- can't change type of existing callback onChange?: (ev: React.ChangeEvent, data: CheckboxOnChangeData) => void; /** diff --git a/packages/react-components/react-combobox/src/utils/ComboboxBase.types.ts b/packages/react-components/react-combobox/src/utils/ComboboxBase.types.ts index fd256d6a928e6..bbc5d6b23d983 100644 --- a/packages/react-components/react-combobox/src/utils/ComboboxBase.types.ts +++ b/packages/react-components/react-combobox/src/utils/ComboboxBase.types.ts @@ -41,7 +41,7 @@ export type ComboboxBaseProps = SelectionProps & /** * Callback when the open/closed state of the dropdown changes */ - // eslint-disable-next-line @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks + // eslint-disable-next-line @fluentui/consistent-callback-type -- can't change type of existing callback onOpenChange?: (e: ComboboxBaseOpenEvents, data: ComboboxBaseOpenChangeData) => void; /** diff --git a/packages/react-components/react-combobox/src/utils/Selection.types.ts b/packages/react-components/react-combobox/src/utils/Selection.types.ts index f701dee3ef766..81a5b713d3c3d 100644 --- a/packages/react-components/react-combobox/src/utils/Selection.types.ts +++ b/packages/react-components/react-combobox/src/utils/Selection.types.ts @@ -17,7 +17,7 @@ export type SelectionProps = { multiselect?: boolean; /* Callback when an option is selected */ - // eslint-disable-next-line @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks + // eslint-disable-next-line @fluentui/consistent-callback-type -- can't change type of existing callback onOptionSelect?: (event: SelectionEvents, data: OptionOnSelectData) => void; /** diff --git a/packages/react-components/react-datepicker-compat/src/components/DatePicker/DatePicker.types.ts b/packages/react-components/react-datepicker-compat/src/components/DatePicker/DatePicker.types.ts index 74794f07f548e..cf59053541425 100644 --- a/packages/react-components/react-datepicker-compat/src/components/DatePicker/DatePicker.types.ts +++ b/packages/react-components/react-datepicker-compat/src/components/DatePicker/DatePicker.types.ts @@ -16,7 +16,7 @@ export type DatePickerProps = Omit>, 'de /** * Callback issued when a date is selected */ - // eslint-disable-next-line @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks + // eslint-disable-next-line @fluentui/consistent-callback-type -- can't change type of existing callback onSelectDate?: (date: Date | null | undefined) => void; /** @@ -85,13 +85,13 @@ export type DatePickerProps = Omit>, 'de /** * Callback to run when the DatePicker's open state changes */ - // eslint-disable-next-line @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks + // eslint-disable-next-line @fluentui/consistent-callback-type -- can't change type of existing callback onOpenChange?: (open: boolean) => void; /** * Callback to run after the DatePicker's input has been validated */ - // eslint-disable-next-line @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks + // eslint-disable-next-line @fluentui/consistent-callback-type -- can't change type of existing callback onValidationResult?: (data: DatePickerValidationResultData) => void; /** diff --git a/packages/react-components/react-dialog/src/components/Dialog/Dialog.types.ts b/packages/react-components/react-dialog/src/components/Dialog/Dialog.types.ts index 8534436ebeacc..aeb5b582f5ca3 100644 --- a/packages/react-components/react-dialog/src/components/Dialog/Dialog.types.ts +++ b/packages/react-components/react-dialog/src/components/Dialog/Dialog.types.ts @@ -81,7 +81,7 @@ export type DialogProps = ComponentProps> & { * @param data - A data object with relevant information, * such as open value and type of interaction that created the event */ - // eslint-disable-next-line @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks + // eslint-disable-next-line @fluentui/consistent-callback-type -- can't change type of existing callback onOpenChange?: DialogOpenChangeEventHandler; /** * Can contain two children including {@link DialogTrigger} and {@link DialogSurface}. diff --git a/packages/react-components/react-input/src/components/Input/Input.types.ts b/packages/react-components/react-input/src/components/Input/Input.types.ts index 38f9fe316f721..b085bd555eb7a 100644 --- a/packages/react-components/react-input/src/components/Input/Input.types.ts +++ b/packages/react-components/react-input/src/components/Input/Input.types.ts @@ -77,7 +77,7 @@ export type InputProps = Omit< /** * Called when the user changes the input's value. */ - // eslint-disable-next-line @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks + // eslint-disable-next-line @fluentui/consistent-callback-type -- can't change type of existing callback onChange?: (ev: React.ChangeEvent, data: InputOnChangeData) => void; /** diff --git a/packages/react-components/react-menu/src/components/Menu/Menu.types.ts b/packages/react-components/react-menu/src/components/Menu/Menu.types.ts index 5583dcc935ea9..abdb8e368b5e3 100644 --- a/packages/react-components/react-menu/src/components/Menu/Menu.types.ts +++ b/packages/react-components/react-menu/src/components/Menu/Menu.types.ts @@ -40,7 +40,7 @@ export type MenuProps = ComponentProps & * Call back when the component requests to change value * The `open` value is used as a hint when directly controlling the component */ - // eslint-disable-next-line @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks + // eslint-disable-next-line @fluentui/consistent-callback-type -- can't change type of existing callback onOpenChange?: (e: MenuOpenEvent, data: MenuOpenChangeData) => void; /** diff --git a/packages/react-components/react-menu/src/components/MenuList/MenuList.types.ts b/packages/react-components/react-menu/src/components/MenuList/MenuList.types.ts index 586cc8a748003..0d94ec95d03b9 100644 --- a/packages/react-components/react-menu/src/components/MenuList/MenuList.types.ts +++ b/packages/react-components/react-menu/src/components/MenuList/MenuList.types.ts @@ -43,7 +43,7 @@ export type MenuListProps = ComponentProps & { * @param event - React's original SyntheticEvent * @param data - A data object with relevant information */ - // eslint-disable-next-line @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks + // eslint-disable-next-line @fluentui/consistent-callback-type -- can't change type of existing callback onCheckedValueChange?: (e: MenuCheckedValueChangeEvent, data: MenuCheckedValueChangeData) => void; }; diff --git a/packages/react-components/react-menu/src/components/MenuTrigger/MenuTrigger.types.ts b/packages/react-components/react-menu/src/components/MenuTrigger/MenuTrigger.types.ts index 17cf501ebc791..ab28ff18b0ab5 100644 --- a/packages/react-components/react-menu/src/components/MenuTrigger/MenuTrigger.types.ts +++ b/packages/react-components/react-menu/src/components/MenuTrigger/MenuTrigger.types.ts @@ -20,7 +20,7 @@ export type MenuTriggerChildProps; - /* eslint-disable @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks */ + /* eslint-disable @fluentui/consistent-callback-type -- can't change type of existing callback */ onMouseEnter: React.MouseEventHandler; onMouseLeave: React.MouseEventHandler; onMouseMove: React.MouseEventHandler; diff --git a/packages/react-components/react-migration-v0-v9/src/components/List/List/List.types.ts b/packages/react-components/react-migration-v0-v9/src/components/List/List/List.types.ts index bdb9a8b785697..103ba051d277d 100644 --- a/packages/react-components/react-migration-v0-v9/src/components/List/List/List.types.ts +++ b/packages/react-components/react-migration-v0-v9/src/components/List/List/List.types.ts @@ -53,7 +53,7 @@ export type ListProps = ComponentProps & { /** * Callback for selection change events, used for both controlled and uncontrolled (as notification) */ - // eslint-disable-next-line @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks + // eslint-disable-next-line @fluentui/consistent-callback-type -- can't change type of existing callback onSelectionChange?: (event: React.SyntheticEvent, data: { selectedItems: SelectionItemId[] }) => void; /** diff --git a/packages/react-components/react-popover/src/components/Popover/Popover.types.ts b/packages/react-components/react-popover/src/components/Popover/Popover.types.ts index 2b1060670a8ae..0b1aff451f6f1 100644 --- a/packages/react-components/react-popover/src/components/Popover/Popover.types.ts +++ b/packages/react-components/react-popover/src/components/Popover/Popover.types.ts @@ -64,7 +64,7 @@ export type PopoverProps = Pick & { * Call back when the component requests to change value * The `open` value is used as a hint when directly controlling the component */ - // eslint-disable-next-line @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks + // eslint-disable-next-line @fluentui/consistent-callback-type -- can't change type of existing callback onOpenChange?: (e: OpenPopoverEvents, data: OnOpenChangeData) => void; /** diff --git a/packages/react-components/react-popover/src/components/PopoverTrigger/PopoverTrigger.types.ts b/packages/react-components/react-popover/src/components/PopoverTrigger/PopoverTrigger.types.ts index 3afe02fac745b..ea3563e805e35 100644 --- a/packages/react-components/react-popover/src/components/PopoverTrigger/PopoverTrigger.types.ts +++ b/packages/react-components/react-popover/src/components/PopoverTrigger/PopoverTrigger.types.ts @@ -28,7 +28,7 @@ export type PopoverTriggerChildProps; - /* eslint-disable @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks */ + /* eslint-disable @fluentui/consistent-callback-type -- can't change type of existing callback */ onMouseEnter: React.MouseEventHandler; onMouseLeave: React.MouseEventHandler; onContextMenu: React.MouseEventHandler; diff --git a/packages/react-components/react-radio/src/components/Radio/Radio.types.ts b/packages/react-components/react-radio/src/components/Radio/Radio.types.ts index 41c5c1d795a9e..1696032ba3ce9 100644 --- a/packages/react-components/react-radio/src/components/Radio/Radio.types.ts +++ b/packages/react-components/react-radio/src/components/Radio/Radio.types.ts @@ -60,7 +60,7 @@ export type RadioProps = Omit, 'input'>, 'onC * **Note:** `onChange` is NOT called when this Radio is deselected. * Use RadioGroup's `onChange` event to determine when the selection in the group changes. */ - // eslint-disable-next-line @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks + // eslint-disable-next-line @fluentui/consistent-callback-type -- can't change type of existing callback onChange?: (ev: React.ChangeEvent, data: RadioOnChangeData) => void; }; diff --git a/packages/react-components/react-radio/src/components/RadioGroup/RadioGroup.types.ts b/packages/react-components/react-radio/src/components/RadioGroup/RadioGroup.types.ts index 3180da2bd8cb3..7b81cb4375bf8 100644 --- a/packages/react-components/react-radio/src/components/RadioGroup/RadioGroup.types.ts +++ b/packages/react-components/react-radio/src/components/RadioGroup/RadioGroup.types.ts @@ -33,7 +33,7 @@ export type RadioGroupProps = Omit>, 'on /** * Callback when the selected Radio item changes. */ - // eslint-disable-next-line @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks + // eslint-disable-next-line @fluentui/consistent-callback-type -- can't change type of existing callback onChange?: (ev: React.FormEvent, data: RadioGroupOnChangeData) => void; /** diff --git a/packages/react-components/react-rating-preview/src/components/Rating/Rating.types.ts b/packages/react-components/react-rating-preview/src/components/Rating/Rating.types.ts index ff60927c43004..51d7321fc5a30 100644 --- a/packages/react-components/react-rating-preview/src/components/Rating/Rating.types.ts +++ b/packages/react-components/react-rating-preview/src/components/Rating/Rating.types.ts @@ -46,7 +46,7 @@ export type RatingProps = ComponentProps & { /** * Callback when the rating value is changed by the user. */ - // eslint-disable-next-line @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks + // eslint-disable-next-line @fluentui/consistent-callback-type -- can't change type of existing callback onChange?: (ev: React.SyntheticEvent | Event, data: RatingOnChangeData) => void; /** * Sets the precision to allow half-filled shapes in Rating diff --git a/packages/react-components/react-select/src/components/Select/Select.types.ts b/packages/react-components/react-select/src/components/Select/Select.types.ts index eeacafe79e66d..59217ee4bdb52 100644 --- a/packages/react-components/react-select/src/components/Select/Select.types.ts +++ b/packages/react-components/react-select/src/components/Select/Select.types.ts @@ -27,7 +27,7 @@ export type SelectProps = Omit, 'select'>, ' /** * Called when the user changes the select element's value by selecting an option. */ - // eslint-disable-next-line @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks + // eslint-disable-next-line @fluentui/consistent-callback-type -- can't change type of existing callback onChange?: (ev: React.ChangeEvent, data: SelectOnChangeData) => void; /** diff --git a/packages/react-components/react-slider/src/components/Slider/Slider.types.ts b/packages/react-components/react-slider/src/components/Slider/Slider.types.ts index 9f227636efaa5..3d981874c954a 100644 --- a/packages/react-components/react-slider/src/components/Slider/Slider.types.ts +++ b/packages/react-components/react-slider/src/components/Slider/Slider.types.ts @@ -94,7 +94,7 @@ export type SliderProps = Omit< /** * Triggers a callback when the value has been changed. This will be called on every individual step. */ - // eslint-disable-next-line @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks + // eslint-disable-next-line @fluentui/consistent-callback-type -- can't change type of existing callback onChange?: (ev: React.ChangeEvent, data: SliderOnChangeData) => void; }; diff --git a/packages/react-components/react-spinbutton/src/components/SpinButton/SpinButton.types.ts b/packages/react-components/react-spinbutton/src/components/SpinButton/SpinButton.types.ts index f541ce87f92e6..1264611b1ec97 100644 --- a/packages/react-components/react-spinbutton/src/components/SpinButton/SpinButton.types.ts +++ b/packages/react-components/react-spinbutton/src/components/SpinButton/SpinButton.types.ts @@ -80,7 +80,7 @@ export type SpinButtonProps = Omit< * - User *commits* edits to the input text by focusing away (blurring) or pressing enter. * Note that this is NOT called for every key press while the user is editing. */ - // eslint-disable-next-line @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks + // eslint-disable-next-line @fluentui/consistent-callback-type -- can't change type of existing callback onChange?: (event: SpinButtonChangeEvent, data: SpinButtonOnChangeData) => void; /** diff --git a/packages/react-components/react-switch/src/components/Switch/Switch.types.ts b/packages/react-components/react-switch/src/components/Switch/Switch.types.ts index cddd303cb1a19..93083b2c735e9 100644 --- a/packages/react-components/react-switch/src/components/Switch/Switch.types.ts +++ b/packages/react-components/react-switch/src/components/Switch/Switch.types.ts @@ -68,7 +68,7 @@ export type SwitchProps = Omit< /** * Callback to be called when the checked state value changes. */ - // eslint-disable-next-line @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks + // eslint-disable-next-line @fluentui/consistent-callback-type -- can't change type of existing callback onChange?: (ev: React.ChangeEvent, data: SwitchOnChangeData) => void; }; diff --git a/packages/react-components/react-table/src/components/DataGrid/DataGrid.types.ts b/packages/react-components/react-table/src/components/DataGrid/DataGrid.types.ts index 7a5539755a450..ea7eec2a20b79 100644 --- a/packages/react-components/react-table/src/components/DataGrid/DataGrid.types.ts +++ b/packages/react-components/react-table/src/components/DataGrid/DataGrid.types.ts @@ -64,7 +64,7 @@ export type DataGridProps = TableProps & Pick, 'focusMode' | 'subtleSelection' | 'selectionAppearance' | 'resizableColumns'> & Pick & Pick & { - /* eslint-disable @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks */ + /* eslint-disable @fluentui/consistent-callback-type -- can't change type of existing callback */ onSortChange?: (e: React.MouseEvent, sortState: SortState) => void; onSelectionChange?: (e: React.MouseEvent | React.KeyboardEvent, data: OnSelectionChangeData) => void; /* eslint-enable @fluentui/consistent-callback-type */ @@ -81,7 +81,7 @@ export type DataGridProps = TableProps & /** * A callback triggered when a column is resized. */ - // eslint-disable-next-line @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks + // eslint-disable-next-line @fluentui/consistent-callback-type -- can't change type of existing callback onColumnResize?: ( e: KeyboardEvent | TouchEvent | MouseEvent | undefined, data: { columnId: TableColumnId; width: number }, diff --git a/packages/react-components/react-tabs/src/components/TabList/TabList.types.ts b/packages/react-components/react-tabs/src/components/TabList/TabList.types.ts index d22ed48d17dd3..d4acb21e08563 100644 --- a/packages/react-components/react-tabs/src/components/TabList/TabList.types.ts +++ b/packages/react-components/react-tabs/src/components/TabList/TabList.types.ts @@ -71,7 +71,7 @@ export type TabListProps = ComponentProps & { /** * Raised when a tab is selected. */ - // eslint-disable-next-line @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks + // eslint-disable-next-line @fluentui/consistent-callback-type -- can't change type of existing callback onTabSelect?: SelectTabEventHandler; /** diff --git a/packages/react-components/react-tags/src/components/TagGroup/TagGroup.types.ts b/packages/react-components/react-tags/src/components/TagGroup/TagGroup.types.ts index bd70e6fbbca48..f56e70cab3970 100644 --- a/packages/react-components/react-tags/src/components/TagGroup/TagGroup.types.ts +++ b/packages/react-components/react-tags/src/components/TagGroup/TagGroup.types.ts @@ -17,7 +17,7 @@ export type TagGroupProps = ComponentProps & { /** * Callback for when a tag is dismissed */ - // eslint-disable-next-line @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks + // eslint-disable-next-line @fluentui/consistent-callback-type -- can't change type of existing callback onDismiss?: TagDismissHandler; size?: TagSize; diff --git a/packages/react-components/react-teaching-popover-preview/src/components/TeachingPopover/TeachingPopover.types.ts b/packages/react-components/react-teaching-popover-preview/src/components/TeachingPopover/TeachingPopover.types.ts index 941488314d11d..0df6600f3389e 100644 --- a/packages/react-components/react-teaching-popover-preview/src/components/TeachingPopover/TeachingPopover.types.ts +++ b/packages/react-components/react-teaching-popover-preview/src/components/TeachingPopover/TeachingPopover.types.ts @@ -15,7 +15,7 @@ export type TeachingPopoverProps = Omit & { */ currentPage?: number; - /* eslint-disable @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks */ + /* eslint-disable @fluentui/consistent-callback-type -- can't change type of existing callback */ /** * Callback to notify a page change (can be used to update 'currentPage' externally). */ diff --git a/packages/react-components/react-textarea/src/components/Textarea/Textarea.types.ts b/packages/react-components/react-textarea/src/components/Textarea/Textarea.types.ts index f85a4912a938c..21c0587fdbb75 100644 --- a/packages/react-components/react-textarea/src/components/Textarea/Textarea.types.ts +++ b/packages/react-components/react-textarea/src/components/Textarea/Textarea.types.ts @@ -40,7 +40,7 @@ export type TextareaProps = Omit< /** * Callback for when the user changes the value. */ - // eslint-disable-next-line @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks + // eslint-disable-next-line @fluentui/consistent-callback-type -- can't change type of existing callback onChange?: (ev: React.ChangeEvent, data: TextareaOnChangeData) => void; /** diff --git a/packages/react-components/react-timepicker-compat/src/components/TimePicker/TimePicker.types.ts b/packages/react-components/react-timepicker-compat/src/components/TimePicker/TimePicker.types.ts index 226a33ce95c55..cea5795f37ed7 100644 --- a/packages/react-components/react-timepicker-compat/src/components/TimePicker/TimePicker.types.ts +++ b/packages/react-components/react-timepicker-compat/src/components/TimePicker/TimePicker.types.ts @@ -145,7 +145,7 @@ export type TimePickerProps = Omit, 'input /** * Callback for when a time selection is made. */ - // eslint-disable-next-line @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks + // eslint-disable-next-line @fluentui/consistent-callback-type -- can't change type of existing callback onTimeChange?: (event: TimeSelectionEvents, data: TimeSelectionData) => void; /** diff --git a/packages/react-components/react-toast/src/components/Timer/Timer.tsx b/packages/react-components/react-toast/src/components/Timer/Timer.tsx index 2dc8c68952aed..42ae68521709c 100644 --- a/packages/react-components/react-toast/src/components/Timer/Timer.tsx +++ b/packages/react-components/react-toast/src/components/Timer/Timer.tsx @@ -4,7 +4,7 @@ import { useBaseAnimationStyles } from './useTimerStyles.styles'; export type TimerProps = { running: boolean; timeout: number; - // eslint-disable-next-line @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks + // eslint-disable-next-line @fluentui/consistent-callback-type -- can't change type of existing callback onTimeout: () => void; as?: 'span'; }; diff --git a/packages/react-components/react-toolbar/src/components/Toolbar/Toolbar.types.ts b/packages/react-components/react-toolbar/src/components/Toolbar/Toolbar.types.ts index 0fbcff2a19c04..c6d3717b0b9a9 100644 --- a/packages/react-components/react-toolbar/src/components/Toolbar/Toolbar.types.ts +++ b/packages/react-components/react-toolbar/src/components/Toolbar/Toolbar.types.ts @@ -47,7 +47,7 @@ export type ToolbarProps = ComponentProps & { * @param event - React's original SyntheticEvent * @param data - A data object with relevant information */ - // eslint-disable-next-line @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks + // eslint-disable-next-line @fluentui/consistent-callback-type -- can't change type of existing callback onCheckedValueChange?: (e: ToolbarCheckedValueChangeEvent, data: ToolbarCheckedValueChangeData) => void; }; diff --git a/packages/react-components/react-tooltip/src/components/Tooltip/Tooltip.types.ts b/packages/react-components/react-tooltip/src/components/Tooltip/Tooltip.types.ts index 9f36f9a686724..619532fbc1351 100644 --- a/packages/react-components/react-tooltip/src/components/Tooltip/Tooltip.types.ts +++ b/packages/react-components/react-tooltip/src/components/Tooltip/Tooltip.types.ts @@ -63,7 +63,7 @@ export type TooltipProps = ComponentProps & * **Note**: for backwards compatibility, `event` will be undefined if this was triggered by a keyboard event on * the document element. Use `data.documentKeyboardEvent` if the keyboard event object is needed. */ - // eslint-disable-next-line @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks + // eslint-disable-next-line @fluentui/consistent-callback-type -- can't change type of existing callback onVisibleChange?: ( event: React.PointerEvent | React.FocusEvent | undefined, data: OnVisibleChangeData, diff --git a/packages/react-components/react-tree/src/components/TreeItem/TreeItem.types.ts b/packages/react-components/react-tree/src/components/TreeItem/TreeItem.types.ts index 7b4371e88cf8c..abbb54d41e4fe 100644 --- a/packages/react-components/react-tree/src/components/TreeItem/TreeItem.types.ts +++ b/packages/react-components/react-tree/src/components/TreeItem/TreeItem.types.ts @@ -54,7 +54,7 @@ export type TreeItemProps = ComponentProps> & { * NOTE: controlling the open state of a tree item will not affect the open state of its children */ open?: boolean; - // eslint-disable-next-line @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks + // eslint-disable-next-line @fluentui/consistent-callback-type -- can't change type of existing callback onOpenChange?: (e: TreeItemOpenChangeEvent, data: TreeItemOpenChangeData) => void; /** * This property is inferred through context on a nested tree, and required for a flat tree. diff --git a/packages/react-components/react-virtualizer/src/components/Virtualizer/Virtualizer.types.ts b/packages/react-components/react-virtualizer/src/components/Virtualizer/Virtualizer.types.ts index c1e41bad3fd17..db90677a46f62 100644 --- a/packages/react-components/react-virtualizer/src/components/Virtualizer/Virtualizer.types.ts +++ b/packages/react-components/react-virtualizer/src/components/Virtualizer/Virtualizer.types.ts @@ -159,7 +159,7 @@ export type VirtualizerConfigProps = { /** * Callback for notifying when a flagged index has been rendered */ - // eslint-disable-next-line @fluentui/consistent-callback-type -- callback should be typed with EventHandler, but we can't break existing callbacks + // eslint-disable-next-line @fluentui/consistent-callback-type -- can't change type of existing callback onRenderedFlaggedIndex?: (index: number) => void; /* From 9b8fbc0046c84331b2a1276c1e50b791ef511233 Mon Sep 17 00:00:00 2001 From: YuanboXue-Amber Date: Tue, 23 Jan 2024 11:58:45 +0100 Subject: [PATCH 23/31] update lint rule --- .../rules/consistent-callback-type/index.js | 80 ++++++++----------- .../consistent-callback-type/index.test.js | 9 +++ 2 files changed, 44 insertions(+), 45 deletions(-) diff --git a/packages/eslint-plugin/src/rules/consistent-callback-type/index.js b/packages/eslint-plugin/src/rules/consistent-callback-type/index.js index 27b87c1462120..32dd2d728cc8c 100644 --- a/packages/eslint-plugin/src/rules/consistent-callback-type/index.js +++ b/packages/eslint-plugin/src/rules/consistent-callback-type/index.js @@ -18,64 +18,54 @@ module.exports = createRule({ }, defaultOptions: [], create(context) { - /** - * @type {{ - * node: import('@typescript-eslint/experimental-utils').TSESTree.TSTypeAliasDeclaration, - * hasInnerTypeLiteral: boolean - * }[]} - */ - const typeAliasStack = []; // use a stack to match the first TSTypeLiteral node within TSTypeAliasDeclaration node + let isTypeLiteralDirectChild = false; // captures `*.Props` TSTypeAliasDeclaration node and tracks direct child TSTypeLiteral node within return { // eslint-disable-next-line @typescript-eslint/naming-convention - 'TSTypeAliasDeclaration[id.name=/.*Props$/]': function (node) { - typeAliasStack.push({ node, hasInnerTypeLiteral: false }); + 'TSTypeAliasDeclaration[id.name=/.*Props$/] TSTypeLiteral': () => { + isTypeLiteralDirectChild = true; }, // eslint-disable-next-line @typescript-eslint/naming-convention - TSTypeLiteral: (/** @type {import('@typescript-eslint/experimental-utils').TSESTree.TSTypeLiteral}*/ node) => { - if (typeAliasStack.length > 0) { - const top = typeAliasStack[typeAliasStack.length - 1]; - if (!top.hasInnerTypeLiteral) { - /** - * This is the first TSTypeLiteral node within the current TSTypeAliasDeclaration - * For this example: - * `type SomeProps3 = SomeArgBag & { someFunction?: (args: SomeArgBag) => void; };` - * it matches `{ someFunction?: (args: SomeArgBag) => void; }` - */ - top.hasInnerTypeLiteral = true; - - node.members.forEach(member => { + 'TSTypeAliasDeclaration[id.name=/.*Props$/] TSTypeLiteral:exit': ( + /** @type {import('@typescript-eslint/experimental-utils').TSESTree.TSTypeLiteral}*/ node, + ) => { + if (isTypeLiteralDirectChild) { + node.members.forEach(member => { + if ( + member.type === AST_NODE_TYPES.TSPropertySignature && + member.key.type === AST_NODE_TYPES.Identifier && + /^on[A-Z]/.test(member.key.name) + ) { + const typeAnnotation = member.typeAnnotation?.typeAnnotation; + // Check if typeAnnotation is of type EventHandler if ( - member.type === AST_NODE_TYPES.TSPropertySignature && - member.key.type === AST_NODE_TYPES.Identifier && - /^on[A-Z]/.test(member.key.name) + !( + typeAnnotation && + typeAnnotation.type === AST_NODE_TYPES.TSTypeReference && + typeAnnotation.typeName.type === AST_NODE_TYPES.Identifier && + typeAnnotation.typeName.name === 'EventHandler' && + typeAnnotation.typeParameters + ) ) { - const typeAnnotation = member.typeAnnotation?.typeAnnotation; - // Check if typeAnnotation is of type EventHandler - if ( - !( - typeAnnotation && - typeAnnotation.type === AST_NODE_TYPES.TSTypeReference && - typeAnnotation.typeName.type === AST_NODE_TYPES.Identifier && - typeAnnotation.typeName.name === 'EventHandler' && - typeAnnotation.typeParameters - ) - ) { - context.report({ - node: member, - messageId: 'invalidType', - }); - } + context.report({ + node: member, + messageId: 'invalidType', + }); } - }); - } + } + }); } }, // eslint-disable-next-line @typescript-eslint/naming-convention - 'TSTypeAliasDeclaration:exit': function () { - typeAliasStack.pop(); + 'TSTypeAliasDeclaration[id.name=/.*Props$/] TSTypeLiteral TSTypeLiteral': () => { + isTypeLiteralDirectChild = false; + }, + + // eslint-disable-next-line @typescript-eslint/naming-convention + 'TSTypeAliasDeclaration[id.name=/.*Props$/] TSTypeLiteral TSTypeLiteral:exit': () => { + isTypeLiteralDirectChild = true; }, }; }, diff --git a/packages/eslint-plugin/src/rules/consistent-callback-type/index.test.js b/packages/eslint-plugin/src/rules/consistent-callback-type/index.test.js index 797574db3997a..3689fdefabf3c 100644 --- a/packages/eslint-plugin/src/rules/consistent-callback-type/index.test.js +++ b/packages/eslint-plugin/src/rules/consistent-callback-type/index.test.js @@ -65,5 +65,14 @@ ruleTester.run('consistent-callback-type', rule, { `, errors: [{ messageId: 'invalidType' }], }, + // Invalid when callback in props is not using EventHandler, and the prop is two intersected TypeLiteral + { + code: ` + export type SomeProps = SomeType & { onClick?: (ev: React.ClickEvent) => void } & { + onChange?: (ev: React.ChangeEvent, data: {}) => void, + }; + `, + errors: [{ messageId: 'invalidType' }, { messageId: 'invalidType' }], + }, ], }); From 04a9131e646e75d48d76a752ee0e02f12f03354f Mon Sep 17 00:00:00 2001 From: YuanboXue-Amber Date: Tue, 23 Jan 2024 12:31:08 +0100 Subject: [PATCH 24/31] move rule to internal --- packages/eslint-plugin/src/configs/react.js | 2 +- packages/eslint-plugin/src/index.js | 1 - tools/eslint-rules/index.ts | 6 +++++- .../rules/consistent-callback-type.spec.ts | 13 +++++-------- .../rules/consistent-callback-type.ts | 19 +++++++------------ 5 files changed, 18 insertions(+), 23 deletions(-) rename packages/eslint-plugin/src/rules/consistent-callback-type/index.test.js => tools/eslint-rules/rules/consistent-callback-type.spec.ts (90%) rename packages/eslint-plugin/src/rules/consistent-callback-type/index.js => tools/eslint-rules/rules/consistent-callback-type.ts (76%) diff --git a/packages/eslint-plugin/src/configs/react.js b/packages/eslint-plugin/src/configs/react.js index ce82b240f39c7..c6d34d833920e 100644 --- a/packages/eslint-plugin/src/configs/react.js +++ b/packages/eslint-plugin/src/configs/react.js @@ -61,7 +61,7 @@ module.exports = { { files: ['**/src/**/*.{ts,tsx}'], rules: { - '@fluentui/consistent-callback-type': 'error', + '@nx/workspace-consistent-callback-type': 'error', }, }, ], diff --git a/packages/eslint-plugin/src/index.js b/packages/eslint-plugin/src/index.js index ceccdd4dde22b..eae81f75a8452 100644 --- a/packages/eslint-plugin/src/index.js +++ b/packages/eslint-plugin/src/index.js @@ -19,7 +19,6 @@ module.exports = { 'no-visibility-modifiers': require('./rules/no-visibility-modifiers'), 'no-restricted-imports': require('./rules/no-restricted-imports'), 'no-context-default-value': require('./rules/no-context-default-value'), - 'consistent-callback-type': require('./rules/consistent-callback-type'), }, // Not a standard eslint thing, just exported for convenience diff --git a/tools/eslint-rules/index.ts b/tools/eslint-rules/index.ts index c5d9c0f7e0ad7..e3e602fdf24ca 100644 --- a/tools/eslint-rules/index.ts +++ b/tools/eslint-rules/index.ts @@ -1,3 +1,7 @@ +import { + RULE_NAME as consistentCallbackTypeName, + rule as consistentCallbackType, +} from './rules/consistent-callback-type'; /** * Import your custom workspace rules at the top of this file. * @@ -23,5 +27,5 @@ module.exports = { * [myCustomRuleName]: myCustomRule * } */ - rules: {}, + rules: { [consistentCallbackTypeName]: consistentCallbackType }, }; diff --git a/packages/eslint-plugin/src/rules/consistent-callback-type/index.test.js b/tools/eslint-rules/rules/consistent-callback-type.spec.ts similarity index 90% rename from packages/eslint-plugin/src/rules/consistent-callback-type/index.test.js rename to tools/eslint-rules/rules/consistent-callback-type.spec.ts index 3689fdefabf3c..28e5930dafb78 100644 --- a/packages/eslint-plugin/src/rules/consistent-callback-type/index.test.js +++ b/tools/eslint-rules/rules/consistent-callback-type.spec.ts @@ -1,12 +1,9 @@ -// @ts-nocheck -const { ESLintUtils } = require('@typescript-eslint/experimental-utils'); -const rule = require('./index'); - -const ruleTester = new ESLintUtils.RuleTester({ - parser: '@typescript-eslint/parser', +import { TSESLint } from '@typescript-eslint/experimental-utils'; +import { rule, RULE_NAME } from './consistent-callback-type'; +const ruleTester = new TSESLint.RuleTester({ + parser: require.resolve('@typescript-eslint/parser'), }); - -ruleTester.run('consistent-callback-type', rule, { +ruleTester.run(RULE_NAME, rule, { valid: [ // Valid when prop is TSTypeAliasDeclaration and the callback uses EventHandler { diff --git a/packages/eslint-plugin/src/rules/consistent-callback-type/index.js b/tools/eslint-rules/rules/consistent-callback-type.ts similarity index 76% rename from packages/eslint-plugin/src/rules/consistent-callback-type/index.js rename to tools/eslint-rules/rules/consistent-callback-type.ts index 32dd2d728cc8c..a2dcaba073a4a 100644 --- a/packages/eslint-plugin/src/rules/consistent-callback-type/index.js +++ b/tools/eslint-rules/rules/consistent-callback-type.ts @@ -1,9 +1,10 @@ -// @ts-check -const { AST_NODE_TYPES } = require('@typescript-eslint/experimental-utils'); -const createRule = require('../../utils/createRule'); +import { ESLintUtils, AST_NODE_TYPES, TSESTree } from '@typescript-eslint/experimental-utils'; -module.exports = createRule({ - name: 'consistent-callback-type', +// NOTE: The rule will be available in ESLint configs as "@nx/workspace-consistent-callback-type" +export const RULE_NAME = 'consistent-callback-type'; + +export const rule = ESLintUtils.RuleCreator(() => __filename)({ + name: RULE_NAME, meta: { type: 'problem', docs: { @@ -21,15 +22,11 @@ module.exports = createRule({ let isTypeLiteralDirectChild = false; // captures `*.Props` TSTypeAliasDeclaration node and tracks direct child TSTypeLiteral node within return { - // eslint-disable-next-line @typescript-eslint/naming-convention 'TSTypeAliasDeclaration[id.name=/.*Props$/] TSTypeLiteral': () => { isTypeLiteralDirectChild = true; }, - // eslint-disable-next-line @typescript-eslint/naming-convention - 'TSTypeAliasDeclaration[id.name=/.*Props$/] TSTypeLiteral:exit': ( - /** @type {import('@typescript-eslint/experimental-utils').TSESTree.TSTypeLiteral}*/ node, - ) => { + 'TSTypeAliasDeclaration[id.name=/.*Props$/] TSTypeLiteral:exit': (node: TSESTree.TSTypeLiteral) => { if (isTypeLiteralDirectChild) { node.members.forEach(member => { if ( @@ -58,12 +55,10 @@ module.exports = createRule({ } }, - // eslint-disable-next-line @typescript-eslint/naming-convention 'TSTypeAliasDeclaration[id.name=/.*Props$/] TSTypeLiteral TSTypeLiteral': () => { isTypeLiteralDirectChild = false; }, - // eslint-disable-next-line @typescript-eslint/naming-convention 'TSTypeAliasDeclaration[id.name=/.*Props$/] TSTypeLiteral TSTypeLiteral:exit': () => { isTypeLiteralDirectChild = true; }, From 02b6d7527da2885feb08782ce26c22b98d7c52e0 Mon Sep 17 00:00:00 2001 From: YuanboXue-Amber Date: Tue, 23 Jan 2024 15:04:47 +0100 Subject: [PATCH 25/31] update lint disable --- .../src/components/Accordion/Accordion.types.ts | 2 +- .../react-card/src/components/Card/Card.types.ts | 2 +- .../src/components/Checkbox/Checkbox.types.ts | 2 +- .../react-combobox/src/utils/ComboboxBase.types.ts | 2 +- .../react-combobox/src/utils/Selection.types.ts | 2 +- .../src/components/DatePicker/DatePicker.types.ts | 6 +++--- .../react-dialog/src/components/Dialog/Dialog.types.ts | 2 +- .../react-input/src/components/Input/Input.types.ts | 2 +- .../react-menu/src/components/Menu/Menu.types.ts | 2 +- .../react-menu/src/components/MenuList/MenuList.types.ts | 2 +- .../src/components/MenuTrigger/MenuTrigger.types.ts | 4 ++-- .../src/components/List/List/List.types.ts | 2 +- .../react-popover/src/components/Popover/Popover.types.ts | 2 +- .../src/components/PopoverTrigger/PopoverTrigger.types.ts | 4 ++-- .../react-radio/src/components/Radio/Radio.types.ts | 2 +- .../src/components/RadioGroup/RadioGroup.types.ts | 2 +- .../src/components/Rating/Rating.types.ts | 2 +- .../react-select/src/components/Select/Select.types.ts | 2 +- .../react-slider/src/components/Slider/Slider.types.ts | 2 +- .../src/components/SpinButton/SpinButton.types.ts | 2 +- .../react-switch/src/components/Switch/Switch.types.ts | 2 +- .../react-table/src/components/DataGrid/DataGrid.types.ts | 6 +++--- .../react-tabs/src/components/TabList/TabList.types.ts | 2 +- .../react-tags/src/components/TagGroup/TagGroup.types.ts | 2 +- .../src/components/TeachingPopover/TeachingPopover.types.ts | 4 ++-- .../src/components/Textarea/Textarea.types.ts | 2 +- .../src/components/TimePicker/TimePicker.types.ts | 2 +- .../react-toast/src/components/Timer/Timer.tsx | 2 +- .../react-toolbar/src/components/Toolbar/Toolbar.types.ts | 2 +- .../react-tooltip/src/components/Tooltip/Tooltip.types.ts | 2 +- .../react-tree/src/components/TreeItem/TreeItem.types.ts | 2 +- .../src/components/Virtualizer/Virtualizer.types.ts | 2 +- 32 files changed, 39 insertions(+), 39 deletions(-) diff --git a/packages/react-components/react-accordion/src/components/Accordion/Accordion.types.ts b/packages/react-components/react-accordion/src/components/Accordion/Accordion.types.ts index 492df43055e16..0cbadd9f6fef4 100644 --- a/packages/react-components/react-accordion/src/components/Accordion/Accordion.types.ts +++ b/packages/react-components/react-accordion/src/components/Accordion/Accordion.types.ts @@ -49,7 +49,7 @@ export type AccordionProps = ComponentProps; /** diff --git a/packages/react-components/react-card/src/components/Card/Card.types.ts b/packages/react-components/react-card/src/components/Card/Card.types.ts index 67e7c26c77355..f2d45c9b82734 100644 --- a/packages/react-components/react-card/src/components/Card/Card.types.ts +++ b/packages/react-components/react-card/src/components/Card/Card.types.ts @@ -124,7 +124,7 @@ export type CardProps = ComponentProps & { /** * Callback to be called when the selected state value changes. */ - // eslint-disable-next-line @fluentui/consistent-callback-type -- can't change type of existing callback + // eslint-disable-next-line @nx/workspace-consistent-callback-type -- can't change type of existing callback onSelectionChange?: (event: CardOnSelectionChangeEvent, data: CardOnSelectData) => void; }; diff --git a/packages/react-components/react-checkbox/src/components/Checkbox/Checkbox.types.ts b/packages/react-components/react-checkbox/src/components/Checkbox/Checkbox.types.ts index 7735e8c03cbf9..963ef95141293 100644 --- a/packages/react-components/react-checkbox/src/components/Checkbox/Checkbox.types.ts +++ b/packages/react-components/react-checkbox/src/components/Checkbox/Checkbox.types.ts @@ -64,7 +64,7 @@ export type CheckboxProps = Omit< /** * Callback to be called when the checked state value changes. */ - // eslint-disable-next-line @fluentui/consistent-callback-type -- can't change type of existing callback + // eslint-disable-next-line @nx/workspace-consistent-callback-type -- can't change type of existing callback onChange?: (ev: React.ChangeEvent, data: CheckboxOnChangeData) => void; /** diff --git a/packages/react-components/react-combobox/src/utils/ComboboxBase.types.ts b/packages/react-components/react-combobox/src/utils/ComboboxBase.types.ts index bbc5d6b23d983..1ea84c8b2218a 100644 --- a/packages/react-components/react-combobox/src/utils/ComboboxBase.types.ts +++ b/packages/react-components/react-combobox/src/utils/ComboboxBase.types.ts @@ -41,7 +41,7 @@ export type ComboboxBaseProps = SelectionProps & /** * Callback when the open/closed state of the dropdown changes */ - // eslint-disable-next-line @fluentui/consistent-callback-type -- can't change type of existing callback + // eslint-disable-next-line @nx/workspace-consistent-callback-type -- can't change type of existing callback onOpenChange?: (e: ComboboxBaseOpenEvents, data: ComboboxBaseOpenChangeData) => void; /** diff --git a/packages/react-components/react-combobox/src/utils/Selection.types.ts b/packages/react-components/react-combobox/src/utils/Selection.types.ts index 81a5b713d3c3d..1cbc8affdcef6 100644 --- a/packages/react-components/react-combobox/src/utils/Selection.types.ts +++ b/packages/react-components/react-combobox/src/utils/Selection.types.ts @@ -17,7 +17,7 @@ export type SelectionProps = { multiselect?: boolean; /* Callback when an option is selected */ - // eslint-disable-next-line @fluentui/consistent-callback-type -- can't change type of existing callback + // eslint-disable-next-line @nx/workspace-consistent-callback-type -- can't change type of existing callback onOptionSelect?: (event: SelectionEvents, data: OptionOnSelectData) => void; /** diff --git a/packages/react-components/react-datepicker-compat/src/components/DatePicker/DatePicker.types.ts b/packages/react-components/react-datepicker-compat/src/components/DatePicker/DatePicker.types.ts index cf59053541425..2b6b11b75ee20 100644 --- a/packages/react-components/react-datepicker-compat/src/components/DatePicker/DatePicker.types.ts +++ b/packages/react-components/react-datepicker-compat/src/components/DatePicker/DatePicker.types.ts @@ -16,7 +16,7 @@ export type DatePickerProps = Omit>, 'de /** * Callback issued when a date is selected */ - // eslint-disable-next-line @fluentui/consistent-callback-type -- can't change type of existing callback + // eslint-disable-next-line @nx/workspace-consistent-callback-type -- can't change type of existing callback onSelectDate?: (date: Date | null | undefined) => void; /** @@ -85,13 +85,13 @@ export type DatePickerProps = Omit>, 'de /** * Callback to run when the DatePicker's open state changes */ - // eslint-disable-next-line @fluentui/consistent-callback-type -- can't change type of existing callback + // eslint-disable-next-line @nx/workspace-consistent-callback-type -- can't change type of existing callback onOpenChange?: (open: boolean) => void; /** * Callback to run after the DatePicker's input has been validated */ - // eslint-disable-next-line @fluentui/consistent-callback-type -- can't change type of existing callback + // eslint-disable-next-line @nx/workspace-consistent-callback-type -- can't change type of existing callback onValidationResult?: (data: DatePickerValidationResultData) => void; /** diff --git a/packages/react-components/react-dialog/src/components/Dialog/Dialog.types.ts b/packages/react-components/react-dialog/src/components/Dialog/Dialog.types.ts index aeb5b582f5ca3..85b44d87616ca 100644 --- a/packages/react-components/react-dialog/src/components/Dialog/Dialog.types.ts +++ b/packages/react-components/react-dialog/src/components/Dialog/Dialog.types.ts @@ -81,7 +81,7 @@ export type DialogProps = ComponentProps> & { * @param data - A data object with relevant information, * such as open value and type of interaction that created the event */ - // eslint-disable-next-line @fluentui/consistent-callback-type -- can't change type of existing callback + // eslint-disable-next-line @nx/workspace-consistent-callback-type -- can't change type of existing callback onOpenChange?: DialogOpenChangeEventHandler; /** * Can contain two children including {@link DialogTrigger} and {@link DialogSurface}. diff --git a/packages/react-components/react-input/src/components/Input/Input.types.ts b/packages/react-components/react-input/src/components/Input/Input.types.ts index b085bd555eb7a..2afe13a355f8c 100644 --- a/packages/react-components/react-input/src/components/Input/Input.types.ts +++ b/packages/react-components/react-input/src/components/Input/Input.types.ts @@ -77,7 +77,7 @@ export type InputProps = Omit< /** * Called when the user changes the input's value. */ - // eslint-disable-next-line @fluentui/consistent-callback-type -- can't change type of existing callback + // eslint-disable-next-line @nx/workspace-consistent-callback-type -- can't change type of existing callback onChange?: (ev: React.ChangeEvent, data: InputOnChangeData) => void; /** diff --git a/packages/react-components/react-menu/src/components/Menu/Menu.types.ts b/packages/react-components/react-menu/src/components/Menu/Menu.types.ts index abdb8e368b5e3..56135c67b5097 100644 --- a/packages/react-components/react-menu/src/components/Menu/Menu.types.ts +++ b/packages/react-components/react-menu/src/components/Menu/Menu.types.ts @@ -40,7 +40,7 @@ export type MenuProps = ComponentProps & * Call back when the component requests to change value * The `open` value is used as a hint when directly controlling the component */ - // eslint-disable-next-line @fluentui/consistent-callback-type -- can't change type of existing callback + // eslint-disable-next-line @nx/workspace-consistent-callback-type -- can't change type of existing callback onOpenChange?: (e: MenuOpenEvent, data: MenuOpenChangeData) => void; /** diff --git a/packages/react-components/react-menu/src/components/MenuList/MenuList.types.ts b/packages/react-components/react-menu/src/components/MenuList/MenuList.types.ts index 0d94ec95d03b9..3aaa37a127550 100644 --- a/packages/react-components/react-menu/src/components/MenuList/MenuList.types.ts +++ b/packages/react-components/react-menu/src/components/MenuList/MenuList.types.ts @@ -43,7 +43,7 @@ export type MenuListProps = ComponentProps & { * @param event - React's original SyntheticEvent * @param data - A data object with relevant information */ - // eslint-disable-next-line @fluentui/consistent-callback-type -- can't change type of existing callback + // eslint-disable-next-line @nx/workspace-consistent-callback-type -- can't change type of existing callback onCheckedValueChange?: (e: MenuCheckedValueChangeEvent, data: MenuCheckedValueChangeData) => void; }; diff --git a/packages/react-components/react-menu/src/components/MenuTrigger/MenuTrigger.types.ts b/packages/react-components/react-menu/src/components/MenuTrigger/MenuTrigger.types.ts index ab28ff18b0ab5..177dfdb985984 100644 --- a/packages/react-components/react-menu/src/components/MenuTrigger/MenuTrigger.types.ts +++ b/packages/react-components/react-menu/src/components/MenuTrigger/MenuTrigger.types.ts @@ -20,12 +20,12 @@ export type MenuTriggerChildProps; - /* eslint-disable @fluentui/consistent-callback-type -- can't change type of existing callback */ + /* eslint-disable @nx/workspace-consistent-callback-type -- can't change type of existing callback */ onMouseEnter: React.MouseEventHandler; onMouseLeave: React.MouseEventHandler; onMouseMove: React.MouseEventHandler; onContextMenu: React.MouseEventHandler; - /* eslint-enable @fluentui/consistent-callback-type */ + /* eslint-enable @nx/workspace-consistent-callback-type */ } >; diff --git a/packages/react-components/react-migration-v0-v9/src/components/List/List/List.types.ts b/packages/react-components/react-migration-v0-v9/src/components/List/List/List.types.ts index 103ba051d277d..dea80cc588af8 100644 --- a/packages/react-components/react-migration-v0-v9/src/components/List/List/List.types.ts +++ b/packages/react-components/react-migration-v0-v9/src/components/List/List/List.types.ts @@ -53,7 +53,7 @@ export type ListProps = ComponentProps & { /** * Callback for selection change events, used for both controlled and uncontrolled (as notification) */ - // eslint-disable-next-line @fluentui/consistent-callback-type -- can't change type of existing callback + // eslint-disable-next-line @nx/workspace-consistent-callback-type -- can't change type of existing callback onSelectionChange?: (event: React.SyntheticEvent, data: { selectedItems: SelectionItemId[] }) => void; /** diff --git a/packages/react-components/react-popover/src/components/Popover/Popover.types.ts b/packages/react-components/react-popover/src/components/Popover/Popover.types.ts index 0b1aff451f6f1..b9001833f8bc2 100644 --- a/packages/react-components/react-popover/src/components/Popover/Popover.types.ts +++ b/packages/react-components/react-popover/src/components/Popover/Popover.types.ts @@ -64,7 +64,7 @@ export type PopoverProps = Pick & { * Call back when the component requests to change value * The `open` value is used as a hint when directly controlling the component */ - // eslint-disable-next-line @fluentui/consistent-callback-type -- can't change type of existing callback + // eslint-disable-next-line @nx/workspace-consistent-callback-type -- can't change type of existing callback onOpenChange?: (e: OpenPopoverEvents, data: OnOpenChangeData) => void; /** diff --git a/packages/react-components/react-popover/src/components/PopoverTrigger/PopoverTrigger.types.ts b/packages/react-components/react-popover/src/components/PopoverTrigger/PopoverTrigger.types.ts index ea3563e805e35..8f41c82e703ff 100644 --- a/packages/react-components/react-popover/src/components/PopoverTrigger/PopoverTrigger.types.ts +++ b/packages/react-components/react-popover/src/components/PopoverTrigger/PopoverTrigger.types.ts @@ -28,10 +28,10 @@ export type PopoverTriggerChildProps; - /* eslint-disable @fluentui/consistent-callback-type -- can't change type of existing callback */ + /* eslint-disable @nx/workspace-consistent-callback-type -- can't change type of existing callback */ onMouseEnter: React.MouseEventHandler; onMouseLeave: React.MouseEventHandler; onContextMenu: React.MouseEventHandler; - /* eslint-enable @fluentui/consistent-callback-type */ + /* eslint-enable @nx/workspace-consistent-callback-type */ } >; diff --git a/packages/react-components/react-radio/src/components/Radio/Radio.types.ts b/packages/react-components/react-radio/src/components/Radio/Radio.types.ts index 1696032ba3ce9..e7d50d0a34f59 100644 --- a/packages/react-components/react-radio/src/components/Radio/Radio.types.ts +++ b/packages/react-components/react-radio/src/components/Radio/Radio.types.ts @@ -60,7 +60,7 @@ export type RadioProps = Omit, 'input'>, 'onC * **Note:** `onChange` is NOT called when this Radio is deselected. * Use RadioGroup's `onChange` event to determine when the selection in the group changes. */ - // eslint-disable-next-line @fluentui/consistent-callback-type -- can't change type of existing callback + // eslint-disable-next-line @nx/workspace-consistent-callback-type -- can't change type of existing callback onChange?: (ev: React.ChangeEvent, data: RadioOnChangeData) => void; }; diff --git a/packages/react-components/react-radio/src/components/RadioGroup/RadioGroup.types.ts b/packages/react-components/react-radio/src/components/RadioGroup/RadioGroup.types.ts index 7b81cb4375bf8..946054e898339 100644 --- a/packages/react-components/react-radio/src/components/RadioGroup/RadioGroup.types.ts +++ b/packages/react-components/react-radio/src/components/RadioGroup/RadioGroup.types.ts @@ -33,7 +33,7 @@ export type RadioGroupProps = Omit>, 'on /** * Callback when the selected Radio item changes. */ - // eslint-disable-next-line @fluentui/consistent-callback-type -- can't change type of existing callback + // eslint-disable-next-line @nx/workspace-consistent-callback-type -- can't change type of existing callback onChange?: (ev: React.FormEvent, data: RadioGroupOnChangeData) => void; /** diff --git a/packages/react-components/react-rating-preview/src/components/Rating/Rating.types.ts b/packages/react-components/react-rating-preview/src/components/Rating/Rating.types.ts index 51d7321fc5a30..42dc6b4ce0376 100644 --- a/packages/react-components/react-rating-preview/src/components/Rating/Rating.types.ts +++ b/packages/react-components/react-rating-preview/src/components/Rating/Rating.types.ts @@ -46,7 +46,7 @@ export type RatingProps = ComponentProps & { /** * Callback when the rating value is changed by the user. */ - // eslint-disable-next-line @fluentui/consistent-callback-type -- can't change type of existing callback + // eslint-disable-next-line @nx/workspace-consistent-callback-type -- can't change type of existing callback onChange?: (ev: React.SyntheticEvent | Event, data: RatingOnChangeData) => void; /** * Sets the precision to allow half-filled shapes in Rating diff --git a/packages/react-components/react-select/src/components/Select/Select.types.ts b/packages/react-components/react-select/src/components/Select/Select.types.ts index 59217ee4bdb52..bab585152aa71 100644 --- a/packages/react-components/react-select/src/components/Select/Select.types.ts +++ b/packages/react-components/react-select/src/components/Select/Select.types.ts @@ -27,7 +27,7 @@ export type SelectProps = Omit, 'select'>, ' /** * Called when the user changes the select element's value by selecting an option. */ - // eslint-disable-next-line @fluentui/consistent-callback-type -- can't change type of existing callback + // eslint-disable-next-line @nx/workspace-consistent-callback-type -- can't change type of existing callback onChange?: (ev: React.ChangeEvent, data: SelectOnChangeData) => void; /** diff --git a/packages/react-components/react-slider/src/components/Slider/Slider.types.ts b/packages/react-components/react-slider/src/components/Slider/Slider.types.ts index 3d981874c954a..e09c915d7d6d9 100644 --- a/packages/react-components/react-slider/src/components/Slider/Slider.types.ts +++ b/packages/react-components/react-slider/src/components/Slider/Slider.types.ts @@ -94,7 +94,7 @@ export type SliderProps = Omit< /** * Triggers a callback when the value has been changed. This will be called on every individual step. */ - // eslint-disable-next-line @fluentui/consistent-callback-type -- can't change type of existing callback + // eslint-disable-next-line @nx/workspace-consistent-callback-type -- can't change type of existing callback onChange?: (ev: React.ChangeEvent, data: SliderOnChangeData) => void; }; diff --git a/packages/react-components/react-spinbutton/src/components/SpinButton/SpinButton.types.ts b/packages/react-components/react-spinbutton/src/components/SpinButton/SpinButton.types.ts index 1264611b1ec97..7f48f7835dba8 100644 --- a/packages/react-components/react-spinbutton/src/components/SpinButton/SpinButton.types.ts +++ b/packages/react-components/react-spinbutton/src/components/SpinButton/SpinButton.types.ts @@ -80,7 +80,7 @@ export type SpinButtonProps = Omit< * - User *commits* edits to the input text by focusing away (blurring) or pressing enter. * Note that this is NOT called for every key press while the user is editing. */ - // eslint-disable-next-line @fluentui/consistent-callback-type -- can't change type of existing callback + // eslint-disable-next-line @nx/workspace-consistent-callback-type -- can't change type of existing callback onChange?: (event: SpinButtonChangeEvent, data: SpinButtonOnChangeData) => void; /** diff --git a/packages/react-components/react-switch/src/components/Switch/Switch.types.ts b/packages/react-components/react-switch/src/components/Switch/Switch.types.ts index 93083b2c735e9..4145db0996aed 100644 --- a/packages/react-components/react-switch/src/components/Switch/Switch.types.ts +++ b/packages/react-components/react-switch/src/components/Switch/Switch.types.ts @@ -68,7 +68,7 @@ export type SwitchProps = Omit< /** * Callback to be called when the checked state value changes. */ - // eslint-disable-next-line @fluentui/consistent-callback-type -- can't change type of existing callback + // eslint-disable-next-line @nx/workspace-consistent-callback-type -- can't change type of existing callback onChange?: (ev: React.ChangeEvent, data: SwitchOnChangeData) => void; }; diff --git a/packages/react-components/react-table/src/components/DataGrid/DataGrid.types.ts b/packages/react-components/react-table/src/components/DataGrid/DataGrid.types.ts index ea7eec2a20b79..99c45c70ee164 100644 --- a/packages/react-components/react-table/src/components/DataGrid/DataGrid.types.ts +++ b/packages/react-components/react-table/src/components/DataGrid/DataGrid.types.ts @@ -64,10 +64,10 @@ export type DataGridProps = TableProps & Pick, 'focusMode' | 'subtleSelection' | 'selectionAppearance' | 'resizableColumns'> & Pick & Pick & { - /* eslint-disable @fluentui/consistent-callback-type -- can't change type of existing callback */ + /* eslint-disable @nx/workspace-consistent-callback-type -- can't change type of existing callback */ onSortChange?: (e: React.MouseEvent, sortState: SortState) => void; onSelectionChange?: (e: React.MouseEvent | React.KeyboardEvent, data: OnSelectionChangeData) => void; - /* eslint-enable @fluentui/consistent-callback-type */ + /* eslint-enable @nx/workspace-consistent-callback-type */ /** * Enables row selection and sets the selection mode @@ -81,7 +81,7 @@ export type DataGridProps = TableProps & /** * A callback triggered when a column is resized. */ - // eslint-disable-next-line @fluentui/consistent-callback-type -- can't change type of existing callback + // eslint-disable-next-line @nx/workspace-consistent-callback-type -- can't change type of existing callback onColumnResize?: ( e: KeyboardEvent | TouchEvent | MouseEvent | undefined, data: { columnId: TableColumnId; width: number }, diff --git a/packages/react-components/react-tabs/src/components/TabList/TabList.types.ts b/packages/react-components/react-tabs/src/components/TabList/TabList.types.ts index d4acb21e08563..16f1feaed473c 100644 --- a/packages/react-components/react-tabs/src/components/TabList/TabList.types.ts +++ b/packages/react-components/react-tabs/src/components/TabList/TabList.types.ts @@ -71,7 +71,7 @@ export type TabListProps = ComponentProps & { /** * Raised when a tab is selected. */ - // eslint-disable-next-line @fluentui/consistent-callback-type -- can't change type of existing callback + // eslint-disable-next-line @nx/workspace-consistent-callback-type -- can't change type of existing callback onTabSelect?: SelectTabEventHandler; /** diff --git a/packages/react-components/react-tags/src/components/TagGroup/TagGroup.types.ts b/packages/react-components/react-tags/src/components/TagGroup/TagGroup.types.ts index f56e70cab3970..de65024c14044 100644 --- a/packages/react-components/react-tags/src/components/TagGroup/TagGroup.types.ts +++ b/packages/react-components/react-tags/src/components/TagGroup/TagGroup.types.ts @@ -17,7 +17,7 @@ export type TagGroupProps = ComponentProps & { /** * Callback for when a tag is dismissed */ - // eslint-disable-next-line @fluentui/consistent-callback-type -- can't change type of existing callback + // eslint-disable-next-line @nx/workspace-consistent-callback-type -- can't change type of existing callback onDismiss?: TagDismissHandler; size?: TagSize; diff --git a/packages/react-components/react-teaching-popover-preview/src/components/TeachingPopover/TeachingPopover.types.ts b/packages/react-components/react-teaching-popover-preview/src/components/TeachingPopover/TeachingPopover.types.ts index 0df6600f3389e..5d9f3bab8f7ee 100644 --- a/packages/react-components/react-teaching-popover-preview/src/components/TeachingPopover/TeachingPopover.types.ts +++ b/packages/react-components/react-teaching-popover-preview/src/components/TeachingPopover/TeachingPopover.types.ts @@ -15,7 +15,7 @@ export type TeachingPopoverProps = Omit & { */ currentPage?: number; - /* eslint-disable @fluentui/consistent-callback-type -- can't change type of existing callback */ + /* eslint-disable @nx/workspace-consistent-callback-type -- can't change type of existing callback */ /** * Callback to notify a page change (can be used to update 'currentPage' externally). */ @@ -27,7 +27,7 @@ export type TeachingPopoverProps = Omit & { * Callback to notify when the final button step of a carousel has been activated. */ onFinish?: (event: React.MouseEvent) => void; - /* eslint-enable @fluentui/consistent-callback-type */ + /* eslint-enable @nx/workspace-consistent-callback-type */ /** * The appearance property (extended from popover, but removed 'inverted'). diff --git a/packages/react-components/react-textarea/src/components/Textarea/Textarea.types.ts b/packages/react-components/react-textarea/src/components/Textarea/Textarea.types.ts index 21c0587fdbb75..47520929a4304 100644 --- a/packages/react-components/react-textarea/src/components/Textarea/Textarea.types.ts +++ b/packages/react-components/react-textarea/src/components/Textarea/Textarea.types.ts @@ -40,7 +40,7 @@ export type TextareaProps = Omit< /** * Callback for when the user changes the value. */ - // eslint-disable-next-line @fluentui/consistent-callback-type -- can't change type of existing callback + // eslint-disable-next-line @nx/workspace-consistent-callback-type -- can't change type of existing callback onChange?: (ev: React.ChangeEvent, data: TextareaOnChangeData) => void; /** diff --git a/packages/react-components/react-timepicker-compat/src/components/TimePicker/TimePicker.types.ts b/packages/react-components/react-timepicker-compat/src/components/TimePicker/TimePicker.types.ts index cea5795f37ed7..86828fdaaf5ab 100644 --- a/packages/react-components/react-timepicker-compat/src/components/TimePicker/TimePicker.types.ts +++ b/packages/react-components/react-timepicker-compat/src/components/TimePicker/TimePicker.types.ts @@ -145,7 +145,7 @@ export type TimePickerProps = Omit, 'input /** * Callback for when a time selection is made. */ - // eslint-disable-next-line @fluentui/consistent-callback-type -- can't change type of existing callback + // eslint-disable-next-line @nx/workspace-consistent-callback-type -- can't change type of existing callback onTimeChange?: (event: TimeSelectionEvents, data: TimeSelectionData) => void; /** diff --git a/packages/react-components/react-toast/src/components/Timer/Timer.tsx b/packages/react-components/react-toast/src/components/Timer/Timer.tsx index 42ae68521709c..4e7583da1f25a 100644 --- a/packages/react-components/react-toast/src/components/Timer/Timer.tsx +++ b/packages/react-components/react-toast/src/components/Timer/Timer.tsx @@ -4,7 +4,7 @@ import { useBaseAnimationStyles } from './useTimerStyles.styles'; export type TimerProps = { running: boolean; timeout: number; - // eslint-disable-next-line @fluentui/consistent-callback-type -- can't change type of existing callback + // eslint-disable-next-line @nx/workspace-consistent-callback-type -- can't change type of existing callback onTimeout: () => void; as?: 'span'; }; diff --git a/packages/react-components/react-toolbar/src/components/Toolbar/Toolbar.types.ts b/packages/react-components/react-toolbar/src/components/Toolbar/Toolbar.types.ts index c6d3717b0b9a9..6fa2b148d294f 100644 --- a/packages/react-components/react-toolbar/src/components/Toolbar/Toolbar.types.ts +++ b/packages/react-components/react-toolbar/src/components/Toolbar/Toolbar.types.ts @@ -47,7 +47,7 @@ export type ToolbarProps = ComponentProps & { * @param event - React's original SyntheticEvent * @param data - A data object with relevant information */ - // eslint-disable-next-line @fluentui/consistent-callback-type -- can't change type of existing callback + // eslint-disable-next-line @nx/workspace-consistent-callback-type -- can't change type of existing callback onCheckedValueChange?: (e: ToolbarCheckedValueChangeEvent, data: ToolbarCheckedValueChangeData) => void; }; diff --git a/packages/react-components/react-tooltip/src/components/Tooltip/Tooltip.types.ts b/packages/react-components/react-tooltip/src/components/Tooltip/Tooltip.types.ts index 619532fbc1351..e4b4e7218f27e 100644 --- a/packages/react-components/react-tooltip/src/components/Tooltip/Tooltip.types.ts +++ b/packages/react-components/react-tooltip/src/components/Tooltip/Tooltip.types.ts @@ -63,7 +63,7 @@ export type TooltipProps = ComponentProps & * **Note**: for backwards compatibility, `event` will be undefined if this was triggered by a keyboard event on * the document element. Use `data.documentKeyboardEvent` if the keyboard event object is needed. */ - // eslint-disable-next-line @fluentui/consistent-callback-type -- can't change type of existing callback + // eslint-disable-next-line @nx/workspace-consistent-callback-type -- can't change type of existing callback onVisibleChange?: ( event: React.PointerEvent | React.FocusEvent | undefined, data: OnVisibleChangeData, diff --git a/packages/react-components/react-tree/src/components/TreeItem/TreeItem.types.ts b/packages/react-components/react-tree/src/components/TreeItem/TreeItem.types.ts index abbb54d41e4fe..35f01743e3ac0 100644 --- a/packages/react-components/react-tree/src/components/TreeItem/TreeItem.types.ts +++ b/packages/react-components/react-tree/src/components/TreeItem/TreeItem.types.ts @@ -54,7 +54,7 @@ export type TreeItemProps = ComponentProps> & { * NOTE: controlling the open state of a tree item will not affect the open state of its children */ open?: boolean; - // eslint-disable-next-line @fluentui/consistent-callback-type -- can't change type of existing callback + // eslint-disable-next-line @nx/workspace-consistent-callback-type -- can't change type of existing callback onOpenChange?: (e: TreeItemOpenChangeEvent, data: TreeItemOpenChangeData) => void; /** * This property is inferred through context on a nested tree, and required for a flat tree. diff --git a/packages/react-components/react-virtualizer/src/components/Virtualizer/Virtualizer.types.ts b/packages/react-components/react-virtualizer/src/components/Virtualizer/Virtualizer.types.ts index db90677a46f62..f2664f6d6d9f6 100644 --- a/packages/react-components/react-virtualizer/src/components/Virtualizer/Virtualizer.types.ts +++ b/packages/react-components/react-virtualizer/src/components/Virtualizer/Virtualizer.types.ts @@ -159,7 +159,7 @@ export type VirtualizerConfigProps = { /** * Callback for notifying when a flagged index has been rendered */ - // eslint-disable-next-line @fluentui/consistent-callback-type -- can't change type of existing callback + // eslint-disable-next-line @nx/workspace-consistent-callback-type -- can't change type of existing callback onRenderedFlaggedIndex?: (index: number) => void; /* From 84209ac496e2eab6eb7bbaf756a1940598e1893d Mon Sep 17 00:00:00 2001 From: YuanboXue-Amber Date: Tue, 23 Jan 2024 15:09:36 +0100 Subject: [PATCH 26/31] update change log for eslint-plugin --- ...eslint-plugin-2d20c89f-0a2b-4e89-a47c-e6314bd42a2e.json | 7 +++++++ ...eslint-plugin-bc33d2c9-cfd7-44bb-a8de-04bf3fb7b14f.json | 7 ------- 2 files changed, 7 insertions(+), 7 deletions(-) create mode 100644 change/@fluentui-eslint-plugin-2d20c89f-0a2b-4e89-a47c-e6314bd42a2e.json delete mode 100644 change/@fluentui-eslint-plugin-bc33d2c9-cfd7-44bb-a8de-04bf3fb7b14f.json diff --git a/change/@fluentui-eslint-plugin-2d20c89f-0a2b-4e89-a47c-e6314bd42a2e.json b/change/@fluentui-eslint-plugin-2d20c89f-0a2b-4e89-a47c-e6314bd42a2e.json new file mode 100644 index 0000000000000..0688fc4a3fbad --- /dev/null +++ b/change/@fluentui-eslint-plugin-2d20c89f-0a2b-4e89-a47c-e6314bd42a2e.json @@ -0,0 +1,7 @@ +{ + "type": "none", + "comment": "chore: add internal consistent-callback-type lint rule to v9 config", + "packageName": "@fluentui/eslint-plugin", + "email": "yuanboxue@microsoft.com", + "dependentChangeType": "none" +} diff --git a/change/@fluentui-eslint-plugin-bc33d2c9-cfd7-44bb-a8de-04bf3fb7b14f.json b/change/@fluentui-eslint-plugin-bc33d2c9-cfd7-44bb-a8de-04bf3fb7b14f.json deleted file mode 100644 index 55df1450cdca4..0000000000000 --- a/change/@fluentui-eslint-plugin-bc33d2c9-cfd7-44bb-a8de-04bf3fb7b14f.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "minor", - "comment": "feat: add new rule consistent-callback-type", - "packageName": "@fluentui/eslint-plugin", - "email": "yuanboxue@microsoft.com", - "dependentChangeType": "patch" -} From 51bc1ba4e63ef22f6648a26d42d0c81bce8203db Mon Sep 17 00:00:00 2001 From: YuanboXue-Amber Date: Tue, 23 Jan 2024 15:17:56 +0100 Subject: [PATCH 27/31] add internal lint rule in the proper way --- ...t-plugin-2d20c89f-0a2b-4e89-a47c-e6314bd42a2e.json | 2 +- packages/eslint-plugin/src/configs/react.js | 4 +++- packages/eslint-plugin/src/internal.js | 11 +++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/change/@fluentui-eslint-plugin-2d20c89f-0a2b-4e89-a47c-e6314bd42a2e.json b/change/@fluentui-eslint-plugin-2d20c89f-0a2b-4e89-a47c-e6314bd42a2e.json index 0688fc4a3fbad..c29cea839fea1 100644 --- a/change/@fluentui-eslint-plugin-2d20c89f-0a2b-4e89-a47c-e6314bd42a2e.json +++ b/change/@fluentui-eslint-plugin-2d20c89f-0a2b-4e89-a47c-e6314bd42a2e.json @@ -1,6 +1,6 @@ { "type": "none", - "comment": "chore: add internal consistent-callback-type lint rule to v9 config", + "comment": "chore: add internal lint rule, no change to public behavior/api.", "packageName": "@fluentui/eslint-plugin", "email": "yuanboxue@microsoft.com", "dependentChangeType": "none" diff --git a/packages/eslint-plugin/src/configs/react.js b/packages/eslint-plugin/src/configs/react.js index c6d34d833920e..17d9711a4c8b7 100644 --- a/packages/eslint-plugin/src/configs/react.js +++ b/packages/eslint-plugin/src/configs/react.js @@ -2,6 +2,7 @@ const path = require('path'); const configHelpers = require('../utils/configHelpers'); +const { __internal } = require('../internal'); /** @type {import("eslint").Linter.RulesRecord} */ const typeAwareRules = { @@ -64,5 +65,6 @@ module.exports = { '@nx/workspace-consistent-callback-type': 'error', }, }, - ], + __internal.overrides.react, + ].filter(Boolean), }; diff --git a/packages/eslint-plugin/src/internal.js b/packages/eslint-plugin/src/internal.js index 7a120416be6c3..08b8f11c27ba7 100644 --- a/packages/eslint-plugin/src/internal.js +++ b/packages/eslint-plugin/src/internal.js @@ -21,6 +21,17 @@ const __internal = { * `@nx/eslint-plugin` is necessary in order to register custom lint rules that live within tools/eslint-rules */ plugins: shouldRegister ? ['@nx'] : [], + // extend this object with your rule overrides + overrides: { + react: shouldRegister + ? { + files: ['**/src/**/*.{ts,tsx}'], + rules: { + '@nx/workspace-consistent-callback-type': 'error', + }, + } + : null, + }, }; exports.__internal = __internal; From e1c4b0a9cada4c84e16eee9a9e39810ee9703138 Mon Sep 17 00:00:00 2001 From: Amber Date: Tue, 23 Jan 2024 15:30:37 +0100 Subject: [PATCH 28/31] Update packages/eslint-plugin/src/configs/react.js Co-authored-by: Martin Hochel --- packages/eslint-plugin/src/configs/react.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/packages/eslint-plugin/src/configs/react.js b/packages/eslint-plugin/src/configs/react.js index 17d9711a4c8b7..f56209c52454d 100644 --- a/packages/eslint-plugin/src/configs/react.js +++ b/packages/eslint-plugin/src/configs/react.js @@ -59,12 +59,6 @@ module.exports = { 'react/jsx-no-bind': 'off', }, }, - { - files: ['**/src/**/*.{ts,tsx}'], - rules: { - '@nx/workspace-consistent-callback-type': 'error', - }, - }, __internal.overrides.react, ].filter(Boolean), }; From 8c7e48425c74f264ce0c75250fbdbf7428eba2b5 Mon Sep 17 00:00:00 2001 From: YuanboXue-Amber Date: Thu, 25 Jan 2024 11:42:44 +0100 Subject: [PATCH 29/31] remove react-rating-preview change log after merge --- ...ating-preview-be1073d4-f244-4c68-8db6-12d4e897bc68.json | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 change/@fluentui-react-rating-preview-be1073d4-f244-4c68-8db6-12d4e897bc68.json diff --git a/change/@fluentui-react-rating-preview-be1073d4-f244-4c68-8db6-12d4e897bc68.json b/change/@fluentui-react-rating-preview-be1073d4-f244-4c68-8db6-12d4e897bc68.json deleted file mode 100644 index 2d07cf8c7a709..0000000000000 --- a/change/@fluentui-react-rating-preview-be1073d4-f244-4c68-8db6-12d4e897bc68.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "none", - "comment": "chore: disable consistent-callback-type lint rule for existing callbacks", - "packageName": "@fluentui/react-rating-preview", - "email": "yuanboxue@microsoft.com", - "dependentChangeType": "none" -} From 99871ce087aac9a23da262b74703ab3fa72ee127 Mon Sep 17 00:00:00 2001 From: YuanboXue-Amber Date: Wed, 7 Feb 2024 17:12:54 +0800 Subject: [PATCH 30/31] add lint disable after merge --- .../src/components/SearchBox/SearchBox.types.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/react-components/react-search-preview/src/components/SearchBox/SearchBox.types.ts b/packages/react-components/react-search-preview/src/components/SearchBox/SearchBox.types.ts index b92ff4959bfce..11aa98d2fdf0a 100644 --- a/packages/react-components/react-search-preview/src/components/SearchBox/SearchBox.types.ts +++ b/packages/react-components/react-search-preview/src/components/SearchBox/SearchBox.types.ts @@ -22,6 +22,7 @@ export type SearchBoxProps = Omit< * When the dismiss button is clicked, this will be called with an event of type React.MouseEvent * and an empty string as the `value` property of the data parameter */ + // eslint-disable-next-line @nx/workspace-consistent-callback-type -- can't change type of existing callback onChange?: (event: SearchBoxChangeEvent, data: InputOnChangeData) => void; }; From 13f7c3e3c0cadeb9f860fb4d856136bb071dce16 Mon Sep 17 00:00:00 2001 From: YuanboXue-Amber Date: Wed, 7 Feb 2024 17:22:45 +0800 Subject: [PATCH 31/31] add changelog --- ...earch-preview-c4304060-394d-4f53-80d2-d34d7f781013.json | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 change/@fluentui-react-search-preview-c4304060-394d-4f53-80d2-d34d7f781013.json diff --git a/change/@fluentui-react-search-preview-c4304060-394d-4f53-80d2-d34d7f781013.json b/change/@fluentui-react-search-preview-c4304060-394d-4f53-80d2-d34d7f781013.json new file mode 100644 index 0000000000000..c199678730daa --- /dev/null +++ b/change/@fluentui-react-search-preview-c4304060-394d-4f53-80d2-d34d7f781013.json @@ -0,0 +1,7 @@ +{ + "type": "patch", + "comment": "chore: disable consistent-callback-type lint rule for existing callbacks", + "packageName": "@fluentui/react-search-preview", + "email": "yuanboxue@microsoft.com", + "dependentChangeType": "patch" +}