From 4c62a991b32f38317d1b47070b651f6541ae6ee0 Mon Sep 17 00:00:00 2001 From: Olivier Tassinari Date: Sat, 5 Dec 2020 18:04:47 +0100 Subject: [PATCH] [core] Prefer other over rest --- packages/material-ui-lab/src/TreeView/descendants.js | 6 +++--- .../internal/pickers/wrappers/makeWrapperComponent.tsx | 9 +++------ .../src/propsToClassKey/propsToClassKey.js | 4 ++-- .../src/SliderUnstyled/SliderUnstyled.test.js | 4 ++-- packages/material-ui/src/Box/Box.spec.tsx | 4 ++-- packages/material-ui/src/styles/experimentalStyled.js | 4 ++-- .../typescript-to-proptypes/test/unused-prop/input.tsx | 4 ++-- .../typescript-to-proptypes/test/unused-prop/output.js | 4 ++-- 8 files changed, 18 insertions(+), 21 deletions(-) diff --git a/packages/material-ui-lab/src/TreeView/descendants.js b/packages/material-ui-lab/src/TreeView/descendants.js index 57d998f8c3ab2c..9c4ac6edeeaa79 100644 --- a/packages/material-ui-lab/src/TreeView/descendants.js +++ b/packages/material-ui-lab/src/TreeView/descendants.js @@ -129,14 +129,14 @@ export function DescendantProvider(props) { const [items, set] = React.useState([]); - const registerDescendant = React.useCallback(({ element, ...rest }) => { + const registerDescendant = React.useCallback(({ element, ...other }) => { set((oldItems) => { let newItems; if (oldItems.length === 0) { // If there are no items, register at index 0 and bail. return [ { - ...rest, + ...other, element, index: 0, }, @@ -163,7 +163,7 @@ export function DescendantProvider(props) { // elements come or go from our component. const newItem = { - ...rest, + ...other, element, index, }; diff --git a/packages/material-ui-lab/src/internal/pickers/wrappers/makeWrapperComponent.tsx b/packages/material-ui-lab/src/internal/pickers/wrappers/makeWrapperComponent.tsx index 2bda113086d3bf..6290388b6a4f89 100644 --- a/packages/material-ui-lab/src/internal/pickers/wrappers/makeWrapperComponent.tsx +++ b/packages/material-ui-lab/src/internal/pickers/wrappers/makeWrapperComponent.tsx @@ -29,7 +29,6 @@ export function makeWrapperComponent( const { disableCloseOnSelect, cancelText, - children, clearable, clearText, DateInputProps, @@ -46,7 +45,7 @@ export function makeWrapperComponent( todayText, value, wrapperProps, - ...restPropsForTextField + ...other } = props; const TypedWrapper = Wrapper as SomeWrapper; @@ -65,10 +64,8 @@ export function makeWrapperComponent( PureDateInputComponent={PureDateInputComponent} displayStaticWrapperAs={displayStaticWrapperAs} {...wrapperProps} - {...restPropsForTextField} - > - {children} - + {...other} + /> ); } diff --git a/packages/material-ui-styles/src/propsToClassKey/propsToClassKey.js b/packages/material-ui-styles/src/propsToClassKey/propsToClassKey.js index 1f1ccda57547dd..589803f613be92 100644 --- a/packages/material-ui-styles/src/propsToClassKey/propsToClassKey.js +++ b/packages/material-ui-styles/src/propsToClassKey/propsToClassKey.js @@ -19,11 +19,11 @@ function isEmpty(string) { * @param {object} props - the properties for which the classKey should be created */ export default function propsToClassKey(props) { - const { variant, ...rest } = props; + const { variant, ...other } = props; let classKey = variant || ''; - Object.keys(rest) + Object.keys(other) .sort() .forEach((key) => { if (key === 'color') { diff --git a/packages/material-ui-unstyled/src/SliderUnstyled/SliderUnstyled.test.js b/packages/material-ui-unstyled/src/SliderUnstyled/SliderUnstyled.test.js index 4d41d10c28f1a7..d23c6caf57a39d 100644 --- a/packages/material-ui-unstyled/src/SliderUnstyled/SliderUnstyled.test.js +++ b/packages/material-ui-unstyled/src/SliderUnstyled/SliderUnstyled.test.js @@ -26,10 +26,10 @@ describe('', () => { let theme = null; const Root = React.forwardRef( - ({ styleProps: stylePropsProp, theme: themeProp, ...rest }, ref) => { + ({ styleProps: stylePropsProp, theme: themeProp, ...other }, ref) => { styleProps = stylePropsProp; theme = themeProp; - return ; + return ; }, ); diff --git a/packages/material-ui/src/Box/Box.spec.tsx b/packages/material-ui/src/Box/Box.spec.tsx index e3a919eca550fd..afd1c4be34577f 100644 --- a/packages/material-ui/src/Box/Box.spec.tsx +++ b/packages/material-ui/src/Box/Box.spec.tsx @@ -6,8 +6,8 @@ interface TestProps { } function Test(props: TestProps) { - const { test, ...rest } = props; - return {test}; + const { test, ...other } = props; + return {test}; } function ResponsiveTest() { diff --git a/packages/material-ui/src/styles/experimentalStyled.js b/packages/material-ui/src/styles/experimentalStyled.js index 9f53d7879c0572..9d66e52f3ccc43 100644 --- a/packages/material-ui/src/styles/experimentalStyled.js +++ b/packages/material-ui/src/styles/experimentalStyled.js @@ -69,10 +69,10 @@ const experimentalStyled = (tag, options, muiOptions = {}) => { const expressionsWithDefaultTheme = expressions ? expressions.map((stylesArg) => { return typeof stylesArg === 'function' - ? ({ theme: themeInput, ...rest }) => { + ? ({ theme: themeInput, ...oter }) => { return stylesArg({ theme: isEmpty(themeInput) ? defaultTheme : themeInput, - ...rest, + ...oter, }); } : stylesArg; diff --git a/packages/typescript-to-proptypes/test/unused-prop/input.tsx b/packages/typescript-to-proptypes/test/unused-prop/input.tsx index f802738d21e761..a5ed0fefbff370 100644 --- a/packages/typescript-to-proptypes/test/unused-prop/input.tsx +++ b/packages/typescript-to-proptypes/test/unused-prop/input.tsx @@ -7,10 +7,10 @@ type Props = { }; export default function Foo(props: Props) { - const { foo, ...rest } = props; + const { foo, ...other } = props; return ( -
+
{foo}
); diff --git a/packages/typescript-to-proptypes/test/unused-prop/output.js b/packages/typescript-to-proptypes/test/unused-prop/output.js index 7bbebdd468ff92..583bc1c0564aa8 100644 --- a/packages/typescript-to-proptypes/test/unused-prop/output.js +++ b/packages/typescript-to-proptypes/test/unused-prop/output.js @@ -1,9 +1,9 @@ import * as React from 'react'; import PropTypes from 'prop-types'; function Foo(props) { - const { foo, ...rest } = props; + const { foo, ...other } = props; return ( -
+
{foo}
);