Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(eslint-rules): add consistent-callback-type rule for event callback typing for react-components and enable it in all v9 packages #30293

Merged
merged 36 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
2faffc9
wip lint rule
YuanboXue-Amber Jan 11, 2024
8836d62
add eslint disable for existing callbacks
YuanboXue-Amber Jan 12, 2024
69dc503
remove testing code in input.type.ts
YuanboXue-Amber Jan 12, 2024
135cce9
changelog
YuanboXue-Amber Jan 12, 2024
5301285
add unit test
YuanboXue-Amber Jan 12, 2024
89cb618
remove react-utilities changelog
YuanboXue-Amber Jan 16, 2024
c35948a
add comments for lint disable and use multi line pragma
YuanboXue-Amber Jan 16, 2024
78c479f
Update packages/eslint-plugin/src/rules/consistent-callback-type/inde…
YuanboXue-Amber Jan 16, 2024
fcce254
Update packages/eslint-plugin/src/rules/consistent-callback-type/inde…
YuanboXue-Amber Jan 16, 2024
2fe4251
Update packages/eslint-plugin/src/rules/consistent-callback-type/inde…
YuanboXue-Amber Jan 16, 2024
29b34cc
Update packages/eslint-plugin/src/rules/consistent-callback-type/inde…
YuanboXue-Amber Jan 16, 2024
5bf9121
prettier after apply suggestion
YuanboXue-Amber Jan 16, 2024
caba8b5
update UT according to comments
YuanboXue-Amber Jan 16, 2024
10c5632
enhance rule
YuanboXue-Amber Jan 16, 2024
e941176
update rule
YuanboXue-Amber Jan 16, 2024
460b012
change matching glob to src instead of matching just *.types.ts
YuanboXue-Amber Jan 16, 2024
2e5d96d
add lint disable after changing scope
YuanboXue-Amber Jan 17, 2024
ad5dbe2
changelog
YuanboXue-Amber Jan 17, 2024
91f6a20
add lint disable
YuanboXue-Amber Jan 17, 2024
c66507f
changelog
YuanboXue-Amber Jan 17, 2024
720bd99
put comment together with disable
YuanboXue-Amber Jan 17, 2024
b98d9f8
update comments
YuanboXue-Amber Jan 18, 2024
9b8fbc0
update lint rule
YuanboXue-Amber Jan 23, 2024
2c1632a
Merge branch 'master' into event-test-lint
YuanboXue-Amber Jan 23, 2024
04a9131
move rule to internal
YuanboXue-Amber Jan 23, 2024
02b6d75
update lint disable
YuanboXue-Amber Jan 23, 2024
84209ac
update change log for eslint-plugin
YuanboXue-Amber Jan 23, 2024
51bc1ba
add internal lint rule in the proper way
YuanboXue-Amber Jan 23, 2024
e1c4b0a
Update packages/eslint-plugin/src/configs/react.js
YuanboXue-Amber Jan 23, 2024
8b671d5
Merge branch 'master' into event-test-lint
YuanboXue-Amber Jan 25, 2024
8c7e484
remove react-rating-preview change log after merge
YuanboXue-Amber Jan 25, 2024
cc028b1
Merge branch 'master' into event-test-lint
YuanboXue-Amber Feb 6, 2024
5d12e30
Merge branch 'master' into event-test-lint
YuanboXue-Amber Feb 7, 2024
99871ce
add lint disable after merge
YuanboXue-Amber Feb 7, 2024
13f7c3e
add changelog
YuanboXue-Amber Feb 7, 2024
a704db8
Merge branch 'master' into event-test-lint
YuanboXue-Amber Feb 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "chore: add internal lint rule, no change to public behavior/api.",
"packageName": "@fluentui/eslint-plugin",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "chore: disable consistent-callback-type lint rule for existing callbacks",
"packageName": "@fluentui/react-accordion",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "chore: disable consistent-callback-type lint rule for existing callbacks",
"packageName": "@fluentui/react-card",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "chore: disable consistent-callback-type lint rule for existing callbacks",
"packageName": "@fluentui/react-checkbox",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "chore: disable consistent-callback-type lint rule for existing callbacks",
"packageName": "@fluentui/react-combobox",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "chore: disable consistent-callback-type lint rule for existing callbacks",
"packageName": "@fluentui/react-datepicker-compat",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "chore: disable consistent-callback-type lint rule for existing callbacks",
"packageName": "@fluentui/react-dialog",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "chore: disable consistent-callback-type lint rule for existing callbacks",
"packageName": "@fluentui/react-input",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "chore: disable consistent-callback-type lint rule for existing callbacks",
"packageName": "@fluentui/react-menu",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "chore: disable consistent-callback-type lint rule for existing callbacks",
"packageName": "@fluentui/react-migration-v0-v9",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "chore: disable consistent-callback-type lint rule for existing callbacks",
"packageName": "@fluentui/react-popover",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "chore: disable consistent-callback-type lint rule for existing callbacks",
"packageName": "@fluentui/react-radio",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "chore: disable consistent-callback-type lint rule for existing callbacks",
"packageName": "@fluentui/react-rating-preview",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "chore: disable consistent-callback-type lint rule for existing callbacks",
"packageName": "@fluentui/react-select",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "chore: disable consistent-callback-type lint rule for existing callbacks",
"packageName": "@fluentui/react-slider",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "chore: disable consistent-callback-type lint rule for existing callbacks",
"packageName": "@fluentui/react-spinbutton",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "chore: disable consistent-callback-type lint rule for existing callbacks",
"packageName": "@fluentui/react-switch",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "chore: disable consistent-callback-type lint rule for existing callbacks",
"packageName": "@fluentui/react-table",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "chore: disable consistent-callback-type lint rule for existing callbacks",
"packageName": "@fluentui/react-tabs",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "chore: disable consistent-callback-type lint rule for existing callbacks",
"packageName": "@fluentui/react-tags",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "chore: disable consistent-callback-type lint rule for existing callbacks",
"packageName": "@fluentui/react-teaching-popover-preview",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "chore: disable consistent-callback-type lint rule for existing callbacks",
"packageName": "@fluentui/react-textarea",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "chore: disable consistent-callback-type lint rule for existing callbacks",
"packageName": "@fluentui/react-timepicker-compat",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "chore: disable consistent-callback-type lint rule for existing callbacks",
"packageName": "@fluentui/react-toast",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "chore: disable consistent-callback-type lint rule for existing callbacks",
"packageName": "@fluentui/react-toolbar",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "chore: disable consistent-callback-type lint rule for existing callbacks",
"packageName": "@fluentui/react-tooltip",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "chore: disable consistent-callback-type lint rule for existing callbacks",
"packageName": "@fluentui/react-tree",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "chore: disable consistent-callback-type lint rule for existing callbacks",
"packageName": "@fluentui/react-virtualizer",
"email": "[email protected]",
"dependentChangeType": "none"
}
10 changes: 9 additions & 1 deletion packages/eslint-plugin/src/configs/react.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const path = require('path');
const configHelpers = require('../utils/configHelpers');
const { __internal } = require('../internal');

/** @type {import("eslint").Linter.RulesRecord} */
const typeAwareRules = {
Expand Down Expand Up @@ -58,5 +59,12 @@ module.exports = {
'react/jsx-no-bind': 'off',
},
},
],
{
files: ['**/src/**/*.{ts,tsx}'],
rules: {
'@nx/workspace-consistent-callback-type': 'error',
},
},
YuanboXue-Amber marked this conversation as resolved.
Show resolved Hide resolved
__internal.overrides.react,
].filter(Boolean),
};
11 changes: 11 additions & 0 deletions packages/eslint-plugin/src/internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export type AccordionProps<Value = AccordionItemValue> = ComponentProps<Accordio
/**
* Callback to be called when the opened items change.
*/
// eslint-disable-next-line @nx/workspace-consistent-callback-type -- can't change type of existing callback
onToggle?: AccordionToggleEventHandler<Value>;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ export type CardProps = ComponentProps<CardSlots> & {
/**
* Callback to be called when the selected state value changes.
*/
// eslint-disable-next-line @nx/workspace-consistent-callback-type -- can't change type of existing callback
onSelectionChange?: (event: CardOnSelectionChangeEvent, data: CardOnSelectData) => void;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export type CheckboxProps = Omit<
/**
* Callback to be called when the checked state value changes.
*/
// eslint-disable-next-line @nx/workspace-consistent-callback-type -- can't change type of existing callback
onChange?: (ev: React.ChangeEvent<HTMLInputElement>, data: CheckboxOnChangeData) => void;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export type ComboboxBaseProps = SelectionProps &
/**
* Callback when the open/closed state of the dropdown changes
*/
// eslint-disable-next-line @nx/workspace-consistent-callback-type -- can't change type of existing callback
onOpenChange?: (e: ComboboxBaseOpenEvents, data: ComboboxBaseOpenChangeData) => void;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export type SelectionProps = {
multiselect?: boolean;

/* Callback when an option is selected */
// eslint-disable-next-line @nx/workspace-consistent-callback-type -- can't change type of existing callback
onOptionSelect?: (event: SelectionEvents, data: OptionOnSelectData) => void;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export type DatePickerProps = Omit<ComponentProps<Partial<DatePickerSlots>>, 'de
/**
* Callback issued when a date is selected
*/
// eslint-disable-next-line @nx/workspace-consistent-callback-type -- can't change type of existing callback
onSelectDate?: (date: Date | null | undefined) => void;

/**
Expand Down Expand Up @@ -84,11 +85,13 @@ export type DatePickerProps = Omit<ComponentProps<Partial<DatePickerSlots>>, 'de
/**
* Callback to run when the DatePicker's open state changes
*/
// 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 @nx/workspace-consistent-callback-type -- can't change type of existing callback
onValidationResult?: (data: DatePickerValidationResultData) => void;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export type DialogProps = ComponentProps<Partial<DialogSlots>> & {
* @param data - A data object with relevant information,
* such as open value and type of interaction that created the event
*/
// 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}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export type InputProps = Omit<
/**
* Called when the user changes the input's value.
*/
// eslint-disable-next-line @nx/workspace-consistent-callback-type -- can't change type of existing callback
onChange?: (ev: React.ChangeEvent<HTMLInputElement>, data: InputOnChangeData) => void;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export type MenuProps = ComponentProps<MenuSlots> &
* 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 @nx/workspace-consistent-callback-type -- can't change type of existing callback
onOpenChange?: (e: MenuOpenEvent, data: MenuOpenChangeData) => void;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export type MenuListProps = ComponentProps<MenuListSlots> & {
* @param event - React's original SyntheticEvent
* @param data - A data object with relevant information
*/
// eslint-disable-next-line @nx/workspace-consistent-callback-type -- can't change type of existing callback
onCheckedValueChange?: (e: MenuCheckedValueChangeEvent, data: MenuCheckedValueChangeData) => void;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ export type MenuTriggerChildProps<Type extends ARIAButtonType = ARIAButtonType,
'aria-expanded'?: boolean;
id: string;
ref: React.Ref<never>;
/* eslint-disable @nx/workspace-consistent-callback-type -- can't change type of existing callback */
onMouseEnter: React.MouseEventHandler<HTMLButtonElement & HTMLAnchorElement & HTMLDivElement>;
onMouseLeave: React.MouseEventHandler<HTMLButtonElement & HTMLAnchorElement & HTMLDivElement>;
onMouseMove: React.MouseEventHandler<HTMLButtonElement & HTMLAnchorElement & HTMLDivElement>;
onContextMenu: React.MouseEventHandler<HTMLButtonElement & HTMLAnchorElement & HTMLDivElement>;
/* eslint-enable @nx/workspace-consistent-callback-type */
}
>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export type ListProps = ComponentProps<ListSlots> & {
/**
* Callback for selection change events, used for both controlled and uncontrolled (as notification)
*/
// eslint-disable-next-line @nx/workspace-consistent-callback-type -- can't change type of existing callback
onSelectionChange?: (event: React.SyntheticEvent, data: { selectedItems: SelectionItemId[] }) => void;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export type PopoverProps = Pick<PortalProps, 'mountNode'> & {
* 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 @nx/workspace-consistent-callback-type -- can't change type of existing callback
onOpenChange?: (e: OpenPopoverEvents, data: OnOpenChangeData) => void;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ export type PopoverTriggerChildProps<Type extends ARIAButtonType = ARIAButtonTyp
Props & {
'aria-expanded'?: 'true' | 'false';
ref: React.Ref<unknown>;
/* eslint-disable @nx/workspace-consistent-callback-type -- can't change type of existing callback */
onMouseEnter: React.MouseEventHandler<HTMLButtonElement & HTMLAnchorElement & HTMLDivElement>;
onMouseLeave: React.MouseEventHandler<HTMLButtonElement & HTMLAnchorElement & HTMLDivElement>;
onContextMenu: React.MouseEventHandler<HTMLButtonElement & HTMLAnchorElement & HTMLDivElement>;
/* eslint-enable @nx/workspace-consistent-callback-type */
}
>;
Loading
Loading