Skip to content

Commit

Permalink
[code-infra] Replace all instances of e with event and add eslint…
Browse files Browse the repository at this point in the history
… rule (#43866)
  • Loading branch information
samuelsycamore authored Sep 30, 2024
1 parent f2d9398 commit 371f7e2
Show file tree
Hide file tree
Showing 43 changed files with 232 additions and 175 deletions.
2 changes: 2 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ module.exports = {
'react/jsx-no-useless-fragment': ['error', { allowExpressions: true }],
'lines-around-directive': 'off',
...(ENABLE_REACT_COMPILER_PLUGIN ? { 'react-compiler/react-compiler': 'error' } : {}),
// Prevent the use of `e` as a shorthand for `event`, `error`, etc.
'id-denylist': ['error', 'e'],
},
overrides: [
{
Expand Down
8 changes: 4 additions & 4 deletions docs/data/joy/components/list/ExampleNavigationMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ const useRovingIndex = (options) => {
}
},
tabIndex: activeIndex === index ? 0 : -1,
onKeyDown: (e) => {
onKeyDown: (event) => {
if (Number.isInteger(activeIndex)) {
if (e.key === (vertical ? 'ArrowDown' : 'ArrowRight')) {
if (event.key === (vertical ? 'ArrowDown' : 'ArrowRight')) {
focusNext();
}
if (e.key === (vertical ? 'ArrowUp' : 'ArrowLeft')) {
if (event.key === (vertical ? 'ArrowUp' : 'ArrowLeft')) {
focusPrevious();
}
handlers.onKeyDown?.(e, { setActiveIndex });
handlers.onKeyDown?.(event, { setActiveIndex });
}
},
onClick: () => {
Expand Down
8 changes: 4 additions & 4 deletions docs/data/joy/components/list/ExampleNavigationMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ const useRovingIndex = (options?: Options) => {
}
},
tabIndex: activeIndex === index ? 0 : -1,
onKeyDown: (e: React.KeyboardEvent<HTMLAnchorElement>) => {
onKeyDown: (event: React.KeyboardEvent<HTMLAnchorElement>) => {
if (Number.isInteger(activeIndex)) {
if (e.key === (vertical ? 'ArrowDown' : 'ArrowRight')) {
if (event.key === (vertical ? 'ArrowDown' : 'ArrowRight')) {
focusNext();
}
if (e.key === (vertical ? 'ArrowUp' : 'ArrowLeft')) {
if (event.key === (vertical ? 'ArrowUp' : 'ArrowLeft')) {
focusPrevious();
}
handlers.onKeyDown?.(e, { setActiveIndex });
handlers.onKeyDown?.(event, { setActiveIndex });
}
},
onClick: () => {
Expand Down
2 changes: 1 addition & 1 deletion docs/data/joy/components/select/SelectClearable.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default function SelectClearable() {
action={action}
value={value}
placeholder="Favorite pet…"
onChange={(e, newValue) => setValue(newValue)}
onChange={(event, newValue) => setValue(newValue)}
{...(value && {
// display the button and remove select indicator
// when user has selected a value
Expand Down
2 changes: 1 addition & 1 deletion docs/data/joy/components/select/SelectClearable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default function SelectClearable() {
action={action}
value={value}
placeholder="Favorite pet…"
onChange={(e, newValue) => setValue(newValue)}
onChange={(event, newValue) => setValue(newValue)}
{...(value && {
// display the button and remove select indicator
// when user has selected a value
Expand Down
2 changes: 1 addition & 1 deletion docs/data/joy/components/select/SelectUsage.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default function SelectUsage() {
defaultListboxOpen
action={action}
value={value}
onChange={(e, newValue) => setValue(newValue)}
onChange={(event, newValue) => setValue(newValue)}
sx={{ minWidth: 160, mb: 20 }}
>
<Option value="react">React</Option>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ export default function MessageInput(props: MessageInputProps) {
placeholder="Type something here…"
aria-label="Message"
ref={textAreaRef}
onChange={(e) => {
setTextAreaValue(e.target.value);
onChange={(event) => {
setTextAreaValue(event.target.value);
}}
value={textAreaValue}
minRows={3}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default function ColorModeSelect(props) {
return (
<Select
value={mode}
onChange={(e) => setMode(e.target.value)}
onChange={(event) => setMode(event.target.value)}
SelectDisplayProps={{
'data-screenshot': 'toggle-mode',
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ export default function ColorModeSelect(props: SelectProps) {
return (
<Select
value={mode}
onChange={(e) => setMode(e.target.value as 'system' | 'light' | 'dark')}
onChange={(event) =>
setMode(event.target.value as 'system' | 'light' | 'dark')
}
SelectDisplayProps={{
// @ts-ignore
'data-screenshot': 'toggle-mode',
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/experiments/base/components-gallery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ export default function ComponentsGallery() {
const settingsOpen = Boolean(settingsAnchor);
const settingsId = settingsOpen ? 'settings-popup' : undefined;

const colorPickerSliderChangeHandler = (e: Event, value: number | number[]) => {
const colorPickerSliderChangeHandler = (event: Event, value: number | number[]) => {
setRootStyles(`
:root {
--primary-50: ${value}, 90%, 97%;
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/experiments/base/tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export default function UnstyledTabsIntroduction() {
<input
type="checkbox"
checked={selectionFollowsFocus}
onChange={(e) => setSelectionFollowsFocus(e.target.checked)}
onChange={(event) => setSelectionFollowsFocus(event.target.checked)}
/>{' '}
Selection follows focus
</label>
Expand Down
2 changes: 1 addition & 1 deletion docs/src/modules/components/DemoSandbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ function getTheme(outerTheme, injectTheme) {
if (injectTheme && Object.prototype.toString.call(injectTheme) === '[object Object]') {
try {
return deepmerge(resultTheme, injectTheme);
} catch (e) {
} catch {
return resultTheme;
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/api-docs-builder/ApiBuilders/HookApiBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ const extractInfoFromType = async (
result = Object.values(properties)
.filter((property) => !property.tags.ignore)
.sort((a, b) => a.name.localeCompare(b.name));
} catch (e) {
} catch {
console.error(`No declaration for ${typeName}`);
}

Expand Down
10 changes: 6 additions & 4 deletions packages/mui-base/src/Badge/Badge.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ const polymorphicComponentTest = () => {
slots={{
root: 'button',
}}
onClick={(e: React.MouseEvent<HTMLButtonElement>) => e.currentTarget.checkValidity()}
onClick={(event: React.MouseEvent<HTMLButtonElement>) =>
event.currentTarget.checkValidity()
}
/>

<Badge<'button'>
Expand All @@ -71,9 +73,9 @@ const polymorphicComponentTest = () => {
ref={(elem) => {
expectType<HTMLButtonElement | null, typeof elem>(elem);
}}
onClick={(e) => {
expectType<React.MouseEvent<HTMLButtonElement, MouseEvent>, typeof e>(e);
e.currentTarget.checkValidity();
onClick={(event) => {
expectType<React.MouseEvent<HTMLButtonElement, MouseEvent>, typeof event>(event);
event.currentTarget.checkValidity();
}}
/>

Expand Down
12 changes: 7 additions & 5 deletions packages/mui-base/src/Button/Button.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ const polymorphicComponentTest = () => {
ref={(elem) => {
expectType<HTMLButtonElement | null, typeof elem>(elem);
}}
onClick={(e) => {
expectType<React.MouseEvent<HTMLButtonElement, MouseEvent>, typeof e>(e);
onClick={(event) => {
expectType<React.MouseEvent<HTMLButtonElement, MouseEvent>, typeof event>(event);
}}
type="submit"
/>
Expand All @@ -60,16 +60,18 @@ const polymorphicComponentTest = () => {
<Button<'svg'> viewBox="" />

<Button
onClick={(e: React.MouseEvent<HTMLButtonElement>) => e.currentTarget.checkValidity()}
onClick={(event: React.MouseEvent<HTMLButtonElement>) =>
event.currentTarget.checkValidity()
}
/>

<Button<'div'>
slotProps={{ root: 'div' }}
ref={(elem) => {
expectType<HTMLDivElement | null, typeof elem>(elem);
}}
onClick={(e) => {
expectType<React.MouseEvent<HTMLDivElement, MouseEvent>, typeof e>(e);
onClick={(event) => {
expectType<React.MouseEvent<HTMLDivElement, MouseEvent>, typeof event>(event);
}}
/>
</div>
Expand Down
10 changes: 6 additions & 4 deletions packages/mui-base/src/FormControl/FormControl.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ function FormControlTest() {
slots={{
root: 'button',
}}
onClick={(e: React.MouseEvent<HTMLButtonElement>) => e.currentTarget.checkValidity()}
onClick={(event: React.MouseEvent<HTMLButtonElement>) =>
event.currentTarget.checkValidity()
}
/>

<FormControl<'button'>
Expand All @@ -51,9 +53,9 @@ function FormControlTest() {
ref={(elem) => {
expectType<HTMLButtonElement | null, typeof elem>(elem);
}}
onClick={(e) => {
expectType<React.MouseEvent<HTMLButtonElement, MouseEvent>, typeof e>(e);
e.currentTarget.checkValidity();
onClick={(event) => {
expectType<React.MouseEvent<HTMLButtonElement, MouseEvent>, typeof event>(event);
event.currentTarget.checkValidity();
}}
/>
</div>
Expand Down
10 changes: 6 additions & 4 deletions packages/mui-base/src/Input/Input.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ const polymorphicComponentTest = () => {
slots={{
root: 'button',
}}
onClick={(e: React.MouseEvent<HTMLButtonElement>) => e.currentTarget.checkValidity()}
onClick={(event: React.MouseEvent<HTMLButtonElement>) =>
event.currentTarget.checkValidity()
}
/>

<Input<'button'>
Expand All @@ -66,9 +68,9 @@ const polymorphicComponentTest = () => {
ref={(elem) => {
expectType<HTMLButtonElement | null, typeof elem>(elem);
}}
onMouseDown={(e) => {
expectType<React.MouseEvent<HTMLButtonElement, MouseEvent>, typeof e>(e);
e.currentTarget.checkValidity();
onMouseDown={(event) => {
expectType<React.MouseEvent<HTMLButtonElement, MouseEvent>, typeof event>(event);
event.currentTarget.checkValidity();
}}
/>
</div>
Expand Down
4 changes: 2 additions & 2 deletions packages/mui-base/src/Input/Input.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ describe('<Input />', () => {
) {
const { onChange, ownerState, ...other } = props;

const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
onChange(e.target.value, OUTPUT_VALUE);
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
onChange(event.target.value, OUTPUT_VALUE);
};

return <input ref={ref} onChange={handleChange} {...other} />;
Expand Down
10 changes: 6 additions & 4 deletions packages/mui-base/src/Menu/Menu.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ const polymorphicComponentTest = () => {
slots={{
root: 'button',
}}
onClick={(e: React.MouseEvent<HTMLButtonElement>) => e.currentTarget.checkValidity()}
onClick={(event: React.MouseEvent<HTMLButtonElement>) =>
event.currentTarget.checkValidity()
}
/>

<Menu<'button'>
Expand All @@ -49,9 +51,9 @@ const polymorphicComponentTest = () => {
ref={(elem) => {
expectType<HTMLButtonElement | null, typeof elem>(elem);
}}
onMouseDown={(e) => {
expectType<React.MouseEvent<HTMLButtonElement, MouseEvent>, typeof e>(e);
e.currentTarget.checkValidity();
onMouseDown={(event) => {
expectType<React.MouseEvent<HTMLButtonElement, MouseEvent>, typeof event>(event);
event.currentTarget.checkValidity();
}}
/>
</div>
Expand Down
10 changes: 6 additions & 4 deletions packages/mui-base/src/MenuItem/MenuItem.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ const polymorphicComponentTest = () => {
slots={{
root: 'button',
}}
onClick={(e: React.MouseEvent<HTMLButtonElement>) => e.currentTarget.checkValidity()}
onClick={(event: React.MouseEvent<HTMLButtonElement>) =>
event.currentTarget.checkValidity()
}
/>

<MenuItem<'button'>
Expand All @@ -49,9 +51,9 @@ const polymorphicComponentTest = () => {
ref={(elem) => {
expectType<HTMLButtonElement | null, typeof elem>(elem);
}}
onMouseDown={(e) => {
expectType<React.MouseEvent<HTMLButtonElement, MouseEvent>, typeof e>(e);
e.currentTarget.checkValidity();
onMouseDown={(event) => {
expectType<React.MouseEvent<HTMLButtonElement, MouseEvent>, typeof event>(event);
event.currentTarget.checkValidity();
}}
/>
</div>
Expand Down
10 changes: 6 additions & 4 deletions packages/mui-base/src/Modal/Modal.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ const polymorphicComponentTest = () => {
slots={{
root: 'button',
}}
onClick={(e: React.MouseEvent<HTMLButtonElement>) => e.currentTarget.checkValidity()}
onClick={(event: React.MouseEvent<HTMLButtonElement>) =>
event.currentTarget.checkValidity()
}
open
>
<div />
Expand All @@ -77,9 +79,9 @@ const polymorphicComponentTest = () => {
ref={(elem) => {
expectType<HTMLButtonElement | null, typeof elem>(elem);
}}
onMouseDown={(e) => {
expectType<React.MouseEvent<HTMLButtonElement, MouseEvent>, typeof e>(e);
e.currentTarget.checkValidity();
onMouseDown={(event) => {
expectType<React.MouseEvent<HTMLButtonElement, MouseEvent>, typeof event>(event);
event.currentTarget.checkValidity();
}}
open
>
Expand Down
6 changes: 3 additions & 3 deletions packages/mui-base/src/Modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,12 @@ const Modal = React.forwardRef(function Modal<RootComponentType extends React.El
getSlotProps: (otherHandlers: EventHandlers) => {
return getBackdropProps({
...otherHandlers,
onClick: (e: React.MouseEvent) => {
onClick: (event: React.MouseEvent) => {
if (onBackdropClick) {
onBackdropClick(e);
onBackdropClick(event);
}
if (otherHandlers?.onClick) {
otherHandlers.onClick(e);
otherHandlers.onClick(event);
}
},
});
Expand Down
10 changes: 6 additions & 4 deletions packages/mui-base/src/Option/Option.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ const polymorphicComponentTest = () => {
slots={{
root: 'button',
}}
onClick={(e: React.MouseEvent<HTMLButtonElement>) => e.currentTarget.checkValidity()}
onClick={(event: React.MouseEvent<HTMLButtonElement>) =>
event.currentTarget.checkValidity()
}
/>

<Option<number, 'button'>
Expand All @@ -64,9 +66,9 @@ const polymorphicComponentTest = () => {
ref={(elem) => {
expectType<HTMLButtonElement | null, typeof elem>(elem);
}}
onMouseDown={(e) => {
expectType<React.MouseEvent<HTMLButtonElement, MouseEvent>, typeof e>(e);
e.currentTarget.checkValidity();
onMouseDown={(event) => {
expectType<React.MouseEvent<HTMLButtonElement, MouseEvent>, typeof event>(event);
event.currentTarget.checkValidity();
}}
/>
</div>
Expand Down
10 changes: 6 additions & 4 deletions packages/mui-base/src/OptionGroup/OptionGroup.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ const polymorphicComponentTest = () => {
slots={{
root: 'button',
}}
onClick={(e: React.MouseEvent<HTMLButtonElement>) => e.currentTarget.checkValidity()}
onClick={(event: React.MouseEvent<HTMLButtonElement>) =>
event.currentTarget.checkValidity()
}
/>

<OptionGroup<'button'>
Expand All @@ -76,9 +78,9 @@ const polymorphicComponentTest = () => {
ref={(elem) => {
expectType<HTMLButtonElement | null, typeof elem>(elem);
}}
onMouseDown={(e) => {
expectType<React.MouseEvent<HTMLButtonElement, MouseEvent>, typeof e>(e);
e.currentTarget.checkValidity();
onMouseDown={(event) => {
expectType<React.MouseEvent<HTMLButtonElement, MouseEvent>, typeof event>(event);
event.currentTarget.checkValidity();
}}
/>
</div>
Expand Down
Loading

0 comments on commit 371f7e2

Please sign in to comment.