diff --git a/apps/pigment-css-vite-app/src/Slider/ZeroSlider.tsx b/apps/pigment-css-vite-app/src/Slider/ZeroSlider.tsx index e7f8b23b07411a..b6880196baf583 100644 --- a/apps/pigment-css-vite-app/src/Slider/ZeroSlider.tsx +++ b/apps/pigment-css-vite-app/src/Slider/ZeroSlider.tsx @@ -847,7 +847,7 @@ const Slider = React.forwardRef(function Slider(pr let markActive; if (track === false) { - markActive = values.indexOf(mark.value) !== -1; + markActive = values.includes(mark.value); } else { markActive = (track === 'normal' && diff --git a/apps/pigment-css-vite-app/src/pages/fixtures/index.tsx b/apps/pigment-css-vite-app/src/pages/fixtures/index.tsx index bacf026ccd1f03..2d30a1fffb7aee 100644 --- a/apps/pigment-css-vite-app/src/pages/fixtures/index.tsx +++ b/apps/pigment-css-vite-app/src/pages/fixtures/index.tsx @@ -21,7 +21,7 @@ export default function Layout() { ); const demosRoutes = (materialUIRoute?.route.children ?? []).filter( - (item) => !!item.path && item.path.indexOf('react-pagination') < 0, + (item) => !!item.path && !item.path.includes('react-pagination'), ); return ( diff --git a/docs/data/joy/components/autocomplete/FixedTags.js b/docs/data/joy/components/autocomplete/FixedTags.js index 91744804a2f22e..8ec8c371fe6897 100644 --- a/docs/data/joy/components/autocomplete/FixedTags.js +++ b/docs/data/joy/components/autocomplete/FixedTags.js @@ -18,7 +18,7 @@ export default function FixedTags() { onChange={(event, newValue) => { setValue([ ...fixedOptions, - ...newValue.filter((option) => fixedOptions.indexOf(option) === -1), + ...newValue.filter((option) => !fixedOptions.includes(option)), ]); }} options={top100Films} @@ -30,7 +30,7 @@ export default function FixedTags() { color="neutral" sx={{ minWidth: 0 }} {...getTagProps({ index })} - disabled={fixedOptions.indexOf(option) !== -1} + disabled={fixedOptions.includes(option)} > {option.title} diff --git a/docs/data/joy/components/autocomplete/FixedTags.tsx b/docs/data/joy/components/autocomplete/FixedTags.tsx index 91744804a2f22e..8ec8c371fe6897 100644 --- a/docs/data/joy/components/autocomplete/FixedTags.tsx +++ b/docs/data/joy/components/autocomplete/FixedTags.tsx @@ -18,7 +18,7 @@ export default function FixedTags() { onChange={(event, newValue) => { setValue([ ...fixedOptions, - ...newValue.filter((option) => fixedOptions.indexOf(option) === -1), + ...newValue.filter((option) => !fixedOptions.includes(option)), ]); }} options={top100Films} @@ -30,7 +30,7 @@ export default function FixedTags() { color="neutral" sx={{ minWidth: 0 }} {...getTagProps({ index })} - disabled={fixedOptions.indexOf(option) !== -1} + disabled={fixedOptions.includes(option)} > {option.title} diff --git a/docs/data/joy/components/table/TableSortAndSelection.js b/docs/data/joy/components/table/TableSortAndSelection.js index 7bd636f8216085..cf6884353ab22a 100644 --- a/docs/data/joy/components/table/TableSortAndSelection.js +++ b/docs/data/joy/components/table/TableSortAndSelection.js @@ -290,7 +290,6 @@ export default function TableSortAndSelection() { ? rows.length : Math.min(rows.length, (page + 1) * rowsPerPage); }; - const isSelected = (name) => selected.indexOf(name) !== -1; // Avoid a layout jump when reaching the last page with empty rows. const emptyRows = page > 0 ? Math.max(0, (1 + page) * rowsPerPage - rows.length) : 0; @@ -329,7 +328,7 @@ export default function TableSortAndSelection() { .sort(getComparator(order, orderBy)) .slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage) .map((row, index) => { - const isItemSelected = isSelected(row.name); + const isItemSelected = selected.includes(row.name); const labelId = `enhanced-table-checkbox-${index}`; return ( diff --git a/docs/data/joy/components/table/TableSortAndSelection.tsx b/docs/data/joy/components/table/TableSortAndSelection.tsx index d3137602ecd65d..a2b8aa7878c107 100644 --- a/docs/data/joy/components/table/TableSortAndSelection.tsx +++ b/docs/data/joy/components/table/TableSortAndSelection.tsx @@ -331,7 +331,6 @@ export default function TableSortAndSelection() { ? rows.length : Math.min(rows.length, (page + 1) * rowsPerPage); }; - const isSelected = (name: string) => selected.indexOf(name) !== -1; // Avoid a layout jump when reaching the last page with empty rows. const emptyRows = page > 0 ? Math.max(0, (1 + page) * rowsPerPage - rows.length) : 0; @@ -370,7 +369,7 @@ export default function TableSortAndSelection() { .sort(getComparator(order, orderBy)) .slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage) .map((row, index) => { - const isItemSelected = isSelected(row.name); + const isItemSelected = selected.includes(row.name); const labelId = `enhanced-table-checkbox-${index}`; return ( diff --git a/docs/data/material/components/autocomplete/FixedTags.js b/docs/data/material/components/autocomplete/FixedTags.js index 982b9f1f35c706..d566945bc90681 100644 --- a/docs/data/material/components/autocomplete/FixedTags.js +++ b/docs/data/material/components/autocomplete/FixedTags.js @@ -15,7 +15,7 @@ export default function FixedTags() { onChange={(event, newValue) => { setValue([ ...fixedOptions, - ...newValue.filter((option) => fixedOptions.indexOf(option) === -1), + ...newValue.filter((option) => !fixedOptions.includes(option)), ]); }} options={top100Films} @@ -28,7 +28,7 @@ export default function FixedTags() { key={key} label={option.title} {...tagProps} - disabled={fixedOptions.indexOf(option) !== -1} + disabled={fixedOptions.includes(option)} /> ); }) diff --git a/docs/data/material/components/autocomplete/FixedTags.tsx b/docs/data/material/components/autocomplete/FixedTags.tsx index 982b9f1f35c706..d566945bc90681 100644 --- a/docs/data/material/components/autocomplete/FixedTags.tsx +++ b/docs/data/material/components/autocomplete/FixedTags.tsx @@ -15,7 +15,7 @@ export default function FixedTags() { onChange={(event, newValue) => { setValue([ ...fixedOptions, - ...newValue.filter((option) => fixedOptions.indexOf(option) === -1), + ...newValue.filter((option) => !fixedOptions.includes(option)), ]); }} options={top100Films} @@ -28,7 +28,7 @@ export default function FixedTags() { key={key} label={option.title} {...tagProps} - disabled={fixedOptions.indexOf(option) !== -1} + disabled={fixedOptions.includes(option)} /> ); }) diff --git a/docs/data/material/components/lists/CheckboxList.js b/docs/data/material/components/lists/CheckboxList.js index 87bb3a2c9ff2e0..b5d5b3b496fefb 100644 --- a/docs/data/material/components/lists/CheckboxList.js +++ b/docs/data/material/components/lists/CheckboxList.js @@ -43,7 +43,7 @@ export default function CheckboxList() { } diff --git a/docs/data/material/components/lists/CheckboxListSecondary.tsx b/docs/data/material/components/lists/CheckboxListSecondary.tsx index ace469bb7f2358..658ae453fa6dae 100644 --- a/docs/data/material/components/lists/CheckboxListSecondary.tsx +++ b/docs/data/material/components/lists/CheckboxListSecondary.tsx @@ -34,7 +34,7 @@ export default function CheckboxListSecondary() { } diff --git a/docs/data/material/components/lists/SwitchListSecondary.js b/docs/data/material/components/lists/SwitchListSecondary.js index 3e7e4bd74463fd..fd70e3b215221d 100644 --- a/docs/data/material/components/lists/SwitchListSecondary.js +++ b/docs/data/material/components/lists/SwitchListSecondary.js @@ -37,7 +37,7 @@ export default function SwitchListSecondary() { { let theme; - if (importName.indexOf('Outlined') !== -1) { + if (importName.includes('Outlined')) { theme = 'Outlined'; - } else if (importName.indexOf('TwoTone') !== -1) { + } else if (importName.includes('TwoTone')) { theme = 'Two tone'; - } else if (importName.indexOf('Rounded') !== -1) { + } else if (importName.includes('Rounded')) { theme = 'Rounded'; - } else if (importName.indexOf('Sharp') !== -1) { + } else if (importName.includes('Sharp')) { theme = 'Sharp'; } else { theme = 'Filled'; diff --git a/docs/data/material/components/selects/MultipleSelect.js b/docs/data/material/components/selects/MultipleSelect.js index 52eb975e339b73..c337e1bd15ee04 100644 --- a/docs/data/material/components/selects/MultipleSelect.js +++ b/docs/data/material/components/selects/MultipleSelect.js @@ -32,10 +32,9 @@ const names = [ function getStyles(name, personName, theme) { return { - fontWeight: - personName.indexOf(name) === -1 - ? theme.typography.fontWeightRegular - : theme.typography.fontWeightMedium, + fontWeight: personName.includes(name) + ? theme.typography.fontWeightMedium + : theme.typography.fontWeightRegular, }; } diff --git a/docs/data/material/components/selects/MultipleSelect.tsx b/docs/data/material/components/selects/MultipleSelect.tsx index 3846eb20e06840..4275c97aae3a79 100644 --- a/docs/data/material/components/selects/MultipleSelect.tsx +++ b/docs/data/material/components/selects/MultipleSelect.tsx @@ -32,10 +32,9 @@ const names = [ function getStyles(name: string, personName: string[], theme: Theme) { return { - fontWeight: - personName.indexOf(name) === -1 - ? theme.typography.fontWeightRegular - : theme.typography.fontWeightMedium, + fontWeight: personName.includes(name) + ? theme.typography.fontWeightMedium + : theme.typography.fontWeightRegular, }; } diff --git a/docs/data/material/components/selects/MultipleSelectCheckmarks.js b/docs/data/material/components/selects/MultipleSelectCheckmarks.js index 18a0ebb6ef9af4..8e60a77a56a5f8 100644 --- a/docs/data/material/components/selects/MultipleSelectCheckmarks.js +++ b/docs/data/material/components/selects/MultipleSelectCheckmarks.js @@ -60,7 +60,7 @@ export default function MultipleSelectCheckmarks() { > {names.map((name) => ( - -1} /> + ))} diff --git a/docs/data/material/components/selects/MultipleSelectCheckmarks.tsx b/docs/data/material/components/selects/MultipleSelectCheckmarks.tsx index 9a101306a67d06..2c64d5eec6b3a3 100644 --- a/docs/data/material/components/selects/MultipleSelectCheckmarks.tsx +++ b/docs/data/material/components/selects/MultipleSelectCheckmarks.tsx @@ -60,7 +60,7 @@ export default function MultipleSelectCheckmarks() { > {names.map((name) => ( - -1} /> + ))} diff --git a/docs/data/material/components/selects/MultipleSelectChip.js b/docs/data/material/components/selects/MultipleSelectChip.js index 845a9d12d079ec..65c24741595082 100644 --- a/docs/data/material/components/selects/MultipleSelectChip.js +++ b/docs/data/material/components/selects/MultipleSelectChip.js @@ -34,10 +34,9 @@ const names = [ function getStyles(name, personName, theme) { return { - fontWeight: - personName.indexOf(name) === -1 - ? theme.typography.fontWeightRegular - : theme.typography.fontWeightMedium, + fontWeight: personName.includes(name) + ? theme.typography.fontWeightMedium + : theme.typography.fontWeightRegular, }; } diff --git a/docs/data/material/components/selects/MultipleSelectChip.tsx b/docs/data/material/components/selects/MultipleSelectChip.tsx index c22f6a1dbd762c..e61caeb9659156 100644 --- a/docs/data/material/components/selects/MultipleSelectChip.tsx +++ b/docs/data/material/components/selects/MultipleSelectChip.tsx @@ -34,10 +34,9 @@ const names = [ function getStyles(name: string, personName: readonly string[], theme: Theme) { return { - fontWeight: - personName.indexOf(name) === -1 - ? theme.typography.fontWeightRegular - : theme.typography.fontWeightMedium, + fontWeight: personName.includes(name) + ? theme.typography.fontWeightMedium + : theme.typography.fontWeightRegular, }; } diff --git a/docs/data/material/components/selects/MultipleSelectPlaceholder.js b/docs/data/material/components/selects/MultipleSelectPlaceholder.js index 8f0279a5ab2805..d13d2d03f09d9f 100644 --- a/docs/data/material/components/selects/MultipleSelectPlaceholder.js +++ b/docs/data/material/components/selects/MultipleSelectPlaceholder.js @@ -31,10 +31,9 @@ const names = [ function getStyles(name, personName, theme) { return { - fontWeight: - personName.indexOf(name) === -1 - ? theme.typography.fontWeightRegular - : theme.typography.fontWeightMedium, + fontWeight: personName.includes(name) + ? theme.typography.fontWeightMedium + : theme.typography.fontWeightRegular, }; } diff --git a/docs/data/material/components/selects/MultipleSelectPlaceholder.tsx b/docs/data/material/components/selects/MultipleSelectPlaceholder.tsx index 451ca2d1da71c0..5c7bace02ab3bb 100644 --- a/docs/data/material/components/selects/MultipleSelectPlaceholder.tsx +++ b/docs/data/material/components/selects/MultipleSelectPlaceholder.tsx @@ -31,10 +31,9 @@ const names = [ function getStyles(name: string, personName: readonly string[], theme: Theme) { return { - fontWeight: - personName.indexOf(name) === -1 - ? theme.typography.fontWeightRegular - : theme.typography.fontWeightMedium, + fontWeight: personName.includes(name) + ? theme.typography.fontWeightMedium + : theme.typography.fontWeightRegular, }; } diff --git a/docs/data/material/components/table/EnhancedTable.js b/docs/data/material/components/table/EnhancedTable.js index ef9b29dec845f4..cdbf33f6755b31 100644 --- a/docs/data/material/components/table/EnhancedTable.js +++ b/docs/data/material/components/table/EnhancedTable.js @@ -264,8 +264,6 @@ export default function EnhancedTable() { setDense(event.target.checked); }; - const isSelected = (id) => selected.indexOf(id) !== -1; - // Avoid a layout jump when reaching the last page with empty rows. const emptyRows = page > 0 ? Math.max(0, (1 + page) * rowsPerPage - rows.length) : 0; @@ -298,7 +296,7 @@ export default function EnhancedTable() { /> {visibleRows.map((row, index) => { - const isItemSelected = isSelected(row.id); + const isItemSelected = selected.includes(row.id); const labelId = `enhanced-table-checkbox-${index}`; return ( diff --git a/docs/data/material/components/table/EnhancedTable.tsx b/docs/data/material/components/table/EnhancedTable.tsx index a02a4d0ca9469d..b306f56f872ece 100644 --- a/docs/data/material/components/table/EnhancedTable.tsx +++ b/docs/data/material/components/table/EnhancedTable.tsx @@ -295,8 +295,6 @@ export default function EnhancedTable() { setDense(event.target.checked); }; - const isSelected = (id: number) => selected.indexOf(id) !== -1; - // Avoid a layout jump when reaching the last page with empty rows. const emptyRows = page > 0 ? Math.max(0, (1 + page) * rowsPerPage - rows.length) : 0; @@ -329,7 +327,7 @@ export default function EnhancedTable() { /> {visibleRows.map((row, index) => { - const isItemSelected = isSelected(row.id); + const isItemSelected = selected.includes(row.id); const labelId = `enhanced-table-checkbox-${index}`; return ( diff --git a/docs/data/material/components/transfer-list/SelectAllTransferList.js b/docs/data/material/components/transfer-list/SelectAllTransferList.js index 432b83dfff6ab6..6347236b758a30 100644 --- a/docs/data/material/components/transfer-list/SelectAllTransferList.js +++ b/docs/data/material/components/transfer-list/SelectAllTransferList.js @@ -11,11 +11,11 @@ import Button from '@mui/material/Button'; import Divider from '@mui/material/Divider'; function not(a, b) { - return a.filter((value) => b.indexOf(value) === -1); + return a.filter((value) => !b.includes(value)); } function intersection(a, b) { - return a.filter((value) => b.indexOf(value) !== -1); + return a.filter((value) => b.includes(value)); } function union(a, b) { @@ -108,7 +108,7 @@ export default function SelectAllTransferList() { > b.indexOf(value) === -1); + return a.filter((value) => !b.includes(value)); } function intersection(a: readonly number[], b: readonly number[]) { - return a.filter((value) => b.indexOf(value) !== -1); + return a.filter((value) => b.includes(value)); } function union(a: readonly number[], b: readonly number[]) { @@ -109,7 +109,7 @@ export default function SelectAllTransferList() { > b.indexOf(value) === -1); + return a.filter((value) => !b.includes(value)); } function intersection(a, b) { - return a.filter((value) => b.indexOf(value) !== -1); + return a.filter((value) => b.includes(value)); } export default function TransferList() { @@ -73,7 +73,7 @@ export default function TransferList() { > b.indexOf(value) === -1); + return a.filter((value) => !b.includes(value)); } function intersection(a: readonly number[], b: readonly number[]) { - return a.filter((value) => b.indexOf(value) !== -1); + return a.filter((value) => b.includes(value)); } export default function TransferList() { @@ -73,7 +73,7 @@ export default function TransferList() { > = 1) { - const topLevel = activePageParents - .map((parentPage) => parentPage.pathname) - .includes(page.pathname); + const topLevel = activePageParents.some(({ pathname }) => pathname === page.pathname); let firstChild = page.children[0]; diff --git a/docs/src/modules/components/AppSearch.js b/docs/src/modules/components/AppSearch.js index 3cb6aa1ad1d01b..201a926960567f 100644 --- a/docs/src/modules/components/AppSearch.js +++ b/docs/src/modules/components/AppSearch.js @@ -345,7 +345,7 @@ export default function AppSearch(props) { const facetFilterLanguage = LANGUAGES_SSR.includes(userLanguage) ? `language:${userLanguage}` : `language:en`; - const macOS = window.navigator.platform.toUpperCase().indexOf('MAC') >= 0; + const macOS = window.navigator.platform.toUpperCase().includes('MAC'); const onOpen = React.useCallback(() => { setIsOpen(true); }, [setIsOpen]); diff --git a/docs/src/modules/components/ComponentsApiContent.tsx b/docs/src/modules/components/ComponentsApiContent.tsx index 24610915c556a0..3582471c333123 100644 --- a/docs/src/modules/components/ComponentsApiContent.tsx +++ b/docs/src/modules/components/ComponentsApiContent.tsx @@ -74,8 +74,8 @@ export default function ComponentsApiContent(props: ComponentsApiContentProps) { // There are legacy links where the the components had the Unstyled suffix // This effects makes sure that the anchors will be correct with the renames React.useEffect(() => { - const anchor = router.asPath.indexOf('#') >= 0 ? router.asPath.split('#')[1] : null; - if (router.isReady && anchor && anchor.indexOf('-unstyled') >= 0) { + const anchor = router.asPath.includes('#') ? router.asPath.split('#')[1] : null; + if (router.isReady && anchor && anchor.includes('-unstyled')) { router.replace( { hash: `${anchor.replace('-unstyled', '')}`, diff --git a/docs/src/modules/components/MarkdownDocsV2.js b/docs/src/modules/components/MarkdownDocsV2.js index 37be334cf1543f..b5f6b75ca5f798 100644 --- a/docs/src/modules/components/MarkdownDocsV2.js +++ b/docs/src/modules/components/MarkdownDocsV2.js @@ -198,7 +198,7 @@ export default function MarkdownDocsV2(props) { // process the elements before the tabs component while (i < localizedDoc.rendered.length && !done) { const renderedMarkdownOrDemo = localizedDoc.rendered[i]; - if (renderedMarkdownOrDemo.component && renderedMarkdownOrDemo.component.indexOf('Tabs') >= 0) { + if (renderedMarkdownOrDemo.component && renderedMarkdownOrDemo.component.includes('Tabs')) { done = true; } commonElements.push( diff --git a/docs/src/modules/utils/codeStylingSolution.js b/docs/src/modules/utils/codeStylingSolution.js index b9182fbfcdcc00..a49890a92bf38e 100644 --- a/docs/src/modules/utils/codeStylingSolution.js +++ b/docs/src/modules/utils/codeStylingSolution.js @@ -34,13 +34,13 @@ export function CodeStylingProvider(props) { } if (typeof window !== 'undefined') { - if (window.location.hash.indexOf('tailwind-') >= 0) { + if (window.location.hash.includes('tailwind-')) { return CODE_STYLING.TAILWIND; } - if (window.location.hash.indexOf('css-') >= 0) { + if (window.location.hash.includes('css-')) { return CODE_STYLING.CSS; } - if (window.location.hash.indexOf('system-') >= 0) { + if (window.location.hash.includes('system-')) { return CODE_STYLING.SYSTEM; } } diff --git a/docs/src/modules/utils/findActivePage.ts b/docs/src/modules/utils/findActivePage.ts index eae8dd1385f7b5..331ff3ee5954b0 100644 --- a/docs/src/modules/utils/findActivePage.ts +++ b/docs/src/modules/utils/findActivePage.ts @@ -22,7 +22,7 @@ export default function findActivePage( map[childPathname] = child; const isChildApiPathname = - child.pathname.indexOf('components-api') >= 0 || child.pathname.indexOf('hooks-api') >= 0; + child.pathname.includes('components-api') || child.pathname.includes('hooks-api'); if (!isChildApiPathname && mapParent[childPathname]) { throw new Error(`Duplicated pathname ${child.pathname} in pages`); diff --git a/examples/material-ui-cra-styled-components/src/serviceWorker.js b/examples/material-ui-cra-styled-components/src/serviceWorker.js index b04b771a82613a..261141ea84e54d 100644 --- a/examples/material-ui-cra-styled-components/src/serviceWorker.js +++ b/examples/material-ui-cra-styled-components/src/serviceWorker.js @@ -108,7 +108,7 @@ function checkValidServiceWorker(swUrl, config) { const contentType = response.headers.get('content-type'); if ( response.status === 404 || - (contentType != null && contentType.indexOf('javascript') === -1) + (contentType != null && !contentType.includes('javascript')) ) { // No service worker found. Probably a different app. Reload the page. navigator.serviceWorker.ready.then(registration => { diff --git a/packages-internal/docs-utils/src/index.ts b/packages-internal/docs-utils/src/index.ts index f056c1cf5aad07..24b8a1709e48e8 100644 --- a/packages-internal/docs-utils/src/index.ts +++ b/packages-internal/docs-utils/src/index.ts @@ -24,14 +24,14 @@ export function fixLineEndings(source: string, target: string): string { * @param filename - the file of the styled or regular mui component */ export function getUnstyledFilename(filename: string, definitionFile: boolean = false): string { - if (filename.indexOf('mui-base') > -1) { + if (filename.includes('mui-base')) { return filename; } let unstyledFile = ''; - const separator = filename.indexOf('/') > -1 ? '/' : '\\'; + const separator = filename.includes('/') ? '/' : '\\'; - if (filename.indexOf('mui-base') === -1) { + if (!filename.includes('mui-base')) { unstyledFile = filename .replace(/.d.ts$/, '') .replace(/.tsx?$/, '') diff --git a/packages-internal/test-utils/src/describeConformance.tsx b/packages-internal/test-utils/src/describeConformance.tsx index 744f4fdb8ad241..1dc386ddd76277 100644 --- a/packages-internal/test-utils/src/describeConformance.tsx +++ b/packages-internal/test-utils/src/describeConformance.tsx @@ -812,7 +812,7 @@ function testThemeStyleOverrides( } // `styleKey` in some tests is `foo` or `bar`, so need to check if it is a valid classKey. - const isStyleKeyExists = classKeys.indexOf(testStateOverrides.styleKey) !== -1; + const isStyleKeyExists = classKeys.includes(testStateOverrides.styleKey); if (!isStyleKeyExists) { return; @@ -1059,8 +1059,7 @@ function describeConformance( } = getOptions(); let filteredTests = Object.keys(fullSuite).filter( - (testKey) => - only.indexOf(testKey) !== -1 && skip.indexOf(testKey as keyof typeof fullSuite) === -1, + (testKey) => only.includes(testKey) && !skip.includes(testKey as keyof typeof fullSuite), ) as (keyof typeof fullSuite)[]; const slotBasedTests = ['slotsProp', 'slotPropsProp', 'slotPropsCallback']; diff --git a/packages-internal/test-utils/src/initMatchers.ts b/packages-internal/test-utils/src/initMatchers.ts index e0f23f9070426b..7152482da1ebfa 100644 --- a/packages-internal/test-utils/src/initMatchers.ts +++ b/packages-internal/test-utils/src/initMatchers.ts @@ -543,8 +543,8 @@ chai.use((chaiAPI, utils) => { // Ignore legacy root deprecation warnings // TODO: Remove once we no longer use legacy roots. if ( - format.indexOf('Use createRoot instead.') !== -1 || - format.indexOf('Use hydrateRoot instead.') !== -1 + format.includes('Use createRoot instead.') || + format.includes('Use hydrateRoot instead.') ) { return; } diff --git a/packages-internal/test-utils/src/mochaHooks.js b/packages-internal/test-utils/src/mochaHooks.js index 45a086c83c300f..58b71ee141df5f 100644 --- a/packages-internal/test-utils/src/mochaHooks.js +++ b/packages-internal/test-utils/src/mochaHooks.js @@ -88,7 +88,7 @@ function createUnexpectedConsoleMessagesHooks(Mocha, methodName, expectedMatcher if (process.env.NODE_ENV === 'production') { // TODO: mock scheduler - if (message.indexOf('act(...) is not supported in production builds of React') !== -1) { + if (message.includes('act(...) is not supported in production builds of React')) { return; } } @@ -96,13 +96,13 @@ function createUnexpectedConsoleMessagesHooks(Mocha, methodName, expectedMatcher // Ignore legacy root deprecation warnings // TODO: Remove once we no longer use legacy roots. if ( - message.indexOf('Use createRoot instead.') !== -1 || - message.indexOf('Use hydrateRoot instead.') !== -1 + message.includes('Use createRoot instead.') || + message.includes('Use hydrateRoot instead.') ) { return; } - if (message.indexOf('Warning: useLayoutEffect does nothing on the server') !== -1) { + if (message.includes('Warning: useLayoutEffect does nothing on the server')) { // Controversial warning that is commonly ignored by switching to `useEffect` on the server. // https://github.com/facebook/react/issues/14927 // However, this switch doesn't work since it relies on environment sniffing and we test SSR in a browser environment. @@ -112,9 +112,9 @@ function createUnexpectedConsoleMessagesHooks(Mocha, methodName, expectedMatcher // Unclear why this is an issue for the current occurrences of this warning. // TODO: Revisit once https://github.com/facebook/react/issues/22796 is resolved if ( - message.indexOf( + message.includes( 'Detected multiple renderers concurrently rendering the same context provider.', - ) !== -1 + ) ) { return; } diff --git a/packages/api-docs-builder-core/baseUi/generateBaseUiApiPages.ts b/packages/api-docs-builder-core/baseUi/generateBaseUiApiPages.ts index 4b895543163c24..5476ee3efb978d 100644 --- a/packages/api-docs-builder-core/baseUi/generateBaseUiApiPages.ts +++ b/packages/api-docs-builder-core/baseUi/generateBaseUiApiPages.ts @@ -18,8 +18,7 @@ export async function generateBaseUIApiPages() { // for example base-ui below. if ( productName === 'base' && - (markdown.filename.indexOf('\\components\\') >= 0 || - markdown.filename.indexOf('/components/') >= 0) + (markdown.filename.includes('\\components\\') || markdown.filename.includes('/components/')) ) { const { components, hooks } = markdownHeaders; diff --git a/packages/api-docs-builder/ApiBuilders/ComponentApiBuilder.ts b/packages/api-docs-builder/ApiBuilders/ComponentApiBuilder.ts index f8f3bb247b2c81..5446662321a161 100644 --- a/packages/api-docs-builder/ApiBuilders/ComponentApiBuilder.ts +++ b/packages/api-docs-builder/ApiBuilders/ComponentApiBuilder.ts @@ -338,7 +338,7 @@ const generateApiPage = async ( demos: ``, - cssComponent: cssComponents.indexOf(reactApi.name) >= 0, + cssComponent: cssComponents.includes(reactApi.name), deprecated: reactApi.deprecated, }; @@ -496,7 +496,7 @@ const attachPropsTable = ( const requiredProp = prop.required || - /\.isRequired/.test(prop.type.raw) || + prop.type.raw?.includes('.isRequired') || (chainedPropType !== false && chainedPropType.required); const deprecation = (propDescriptor.description || '').match(/@deprecated(\s+(?.*))?/); @@ -592,7 +592,7 @@ const defaultGetComponentImports = (name: string, filename: string) => { let namedImportName = name; const defaultImportName = name; - if (/Unstable_/.test(githubPath)) { + if (githubPath.includes('Unstable_')) { namedImportName = `Unstable_${name} as ${name}`; } diff --git a/packages/api-docs-builder/buildApiUtils.ts b/packages/api-docs-builder/buildApiUtils.ts index 0cdbe1ccf7c9a7..f1babef885fdfb 100644 --- a/packages/api-docs-builder/buildApiUtils.ts +++ b/packages/api-docs-builder/buildApiUtils.ts @@ -97,7 +97,7 @@ export function parseFile(filename: string) { return { src, shouldSkip: - filename.indexOf('internal') !== -1 || + filename.includes('internal') || !!src.match(/@ignore - internal component\./) || !!src.match(/@ignore - internal hook\./) || !!src.match(/@ignore - do not document\./), diff --git a/packages/eslint-plugin-material-ui/src/rules/disallow-active-element-as-key-event-target.js b/packages/eslint-plugin-material-ui/src/rules/disallow-active-element-as-key-event-target.js index f6d240b878f375..0305c1d3ed7809 100644 --- a/packages/eslint-plugin-material-ui/src/rules/disallow-active-element-as-key-event-target.js +++ b/packages/eslint-plugin-material-ui/src/rules/disallow-active-element-as-key-event-target.js @@ -32,7 +32,7 @@ const rule = { } = node; const isFireKeyboardEvent = callee.type === 'MemberExpression' && - keyboardEventDispatchers.indexOf(callee.property.name) !== -1 && + keyboardEventDispatchers.includes(callee.property.name) && callee.object.name === 'fireEvent'; const targetsDocumentActiveElement = firstArgument !== undefined && diff --git a/packages/markdown/loader.js b/packages/markdown/loader.js index f6ebfec5290245..62a90a2fda9d7e 100644 --- a/packages/markdown/loader.js +++ b/packages/markdown/loader.js @@ -85,7 +85,7 @@ module.exports = async function demoLoader() { if ( filename.startsWith(englishFilename) && matchNotEnglishMarkdown !== null && - options.languagesInProgress.indexOf(matchNotEnglishMarkdown[1]) !== -1 + options.languagesInProgress.includes(matchNotEnglishMarkdown[1]) ) { return { filename, diff --git a/packages/markdown/parseMarkdown.js b/packages/markdown/parseMarkdown.js index f13fcf239c365b..f570d613be4a4d 100644 --- a/packages/markdown/parseMarkdown.js +++ b/packages/markdown/parseMarkdown.js @@ -79,7 +79,7 @@ function checkUrlHealth(href, linkText, context) { * It needs to be: * /material-ui/customization/theming/ */ - if (url.pathname[url.pathname.length - 1] !== '/') { + if (!url.pathname.endsWith('/')) { throw new Error( [ 'docs-infra: Missing trailing slash. The following link:', @@ -145,7 +145,7 @@ function getHeaders(markdown) { while ((regexMatches = headerKeyValueRegExp.exec(header)) !== null) { const key = regexMatches[1]; let value = regexMatches[2].replace(/(.*)/, '$1'); - if (value[0] === '[') { + if (value.startsWith('[')) { // Need double quotes to JSON parse. value = value.replace(/'/g, '"'); // Remove the comma after the last value e.g. ["foo", "bar",] -> ["foo", "bar"]. @@ -387,7 +387,7 @@ function createRender(context) { more += ` title="${title}"`; } - if (noSEOadvantage.some((domain) => href.indexOf(domain) !== -1)) { + if (noSEOadvantage.some((domain) => href.includes(domain))) { more = ' target="_blank" rel="noopener nofollow"'; } diff --git a/packages/markdown/prepareMarkdown.js b/packages/markdown/prepareMarkdown.js index a57976e92f6ff6..69c6c8e7e69589 100644 --- a/packages/markdown/prepareMarkdown.js +++ b/packages/markdown/prepareMarkdown.js @@ -36,7 +36,7 @@ function resolveComponentApiUrl(productId, componentPkg, component) { if (productId === 'x-tree-view') { return `/x/api/tree-view/${kebabCase(component)}/`; } - if (componentPkg === 'mui-base' || BaseUIReexportedComponents.indexOf(component) >= 0) { + if (componentPkg === 'mui-base' || BaseUIReexportedComponents.includes(component)) { return `/base-ui/react-${kebabCase(component)}/components-api/#${kebabCase(component)}`; } if (productId === 'toolpad-core') { diff --git a/packages/mui-base/src/ClickAwayListener/ClickAwayListener.tsx b/packages/mui-base/src/ClickAwayListener/ClickAwayListener.tsx index a7c7c49148d2d5..8f6fe7e07c8f54 100644 --- a/packages/mui-base/src/ClickAwayListener/ClickAwayListener.tsx +++ b/packages/mui-base/src/ClickAwayListener/ClickAwayListener.tsx @@ -132,7 +132,7 @@ function ClickAwayListener(props: ClickAwayListenerProps): React.JSX.Element { // If not enough, can use https://github.com/DieterHolvoet/event-propagation-path/blob/master/propagationPath.js if (event.composedPath) { - insideDOM = event.composedPath().indexOf(nodeRef.current) > -1; + insideDOM = event.composedPath().includes(nodeRef.current); } else { insideDOM = !doc.documentElement.contains( diff --git a/packages/mui-base/src/Slider/Slider.tsx b/packages/mui-base/src/Slider/Slider.tsx index 3ae33136e6c711..9f978eddcaa0ac 100644 --- a/packages/mui-base/src/Slider/Slider.tsx +++ b/packages/mui-base/src/Slider/Slider.tsx @@ -223,7 +223,7 @@ const Slider = React.forwardRef(function Slider { - const isNotExcludedElement = blacklist.indexOf(element) === -1; + const isNotExcludedElement = !blacklist.includes(element); const isNotForbiddenElement = !isAriaHiddenForbiddenOnElement(element); if (isNotExcludedElement && isNotForbiddenElement) { ariaHidden(element, show); @@ -247,10 +247,7 @@ export class ModalManager { } mount(modal: Modal, props: ManagedModalProps): void { - const containerIndex = findIndexOf( - this.containers, - (item) => item.modals.indexOf(modal) !== -1, - ); + const containerIndex = findIndexOf(this.containers, (item) => item.modals.includes(modal)); const containerInfo = this.containers[containerIndex]; if (!containerInfo.restore) { @@ -265,10 +262,7 @@ export class ModalManager { return modalIndex; } - const containerIndex = findIndexOf( - this.containers, - (item) => item.modals.indexOf(modal) !== -1, - ); + const containerIndex = findIndexOf(this.containers, (item) => item.modals.includes(modal)); const containerInfo = this.containers[containerIndex]; containerInfo.modals.splice(containerInfo.modals.indexOf(modal), 1); diff --git a/packages/mui-base/src/useAutocomplete/useAutocomplete.js b/packages/mui-base/src/useAutocomplete/useAutocomplete.js index 8285bd54eefa53..dab2279888d4ce 100644 --- a/packages/mui-base/src/useAutocomplete/useAutocomplete.js +++ b/packages/mui-base/src/useAutocomplete/useAutocomplete.js @@ -44,9 +44,7 @@ export function createFilterOptions(config = {}) { candidate = stripDiacritics(candidate); } - return matchFrom === 'start' - ? candidate.startsWith(input) - : candidate.indexOf(input) > -1; + return matchFrom === 'start' ? candidate.startsWith(input) : candidate.includes(input); }); return typeof limit === 'number' ? filteredOptions.slice(0, limit) : filteredOptions; @@ -784,7 +782,7 @@ export function useAutocomplete(props) { return; } - if (focusedTag !== -1 && ['ArrowLeft', 'ArrowRight'].indexOf(event.key) === -1) { + if (focusedTag !== -1 && !['ArrowLeft', 'ArrowRight'].includes(event.key)) { setFocusedTag(-1); focusTag(-1); } diff --git a/packages/mui-base/src/useSlider/useSlider.ts b/packages/mui-base/src/useSlider/useSlider.ts index 5fe4fdf97ecb0e..ba42bf40568592 100644 --- a/packages/mui-base/src/useSlider/useSlider.ts +++ b/packages/mui-base/src/useSlider/useSlider.ts @@ -419,7 +419,7 @@ export function useSlider(parameters: UseSliderParameters): UseSliderReturnValue percent = (finger.x - left) / width; } - if (axis.indexOf('-reverse') !== -1) { + if (axis.includes('-reverse')) { percent = 1 - percent; } diff --git a/packages/mui-base/test/describeConformanceUnstyled.tsx b/packages/mui-base/test/describeConformanceUnstyled.tsx index cd8a29c547b055..68441d19b65ecd 100644 --- a/packages/mui-base/test/describeConformanceUnstyled.tsx +++ b/packages/mui-base/test/describeConformanceUnstyled.tsx @@ -190,7 +190,7 @@ function testSlotsProp( }); it('uses the component provided in the `component` prop when both `component` and `slots.root` are provided', async () => { - if (skip && skip.indexOf('componentProp') >= 0) { + if (skip && skip.includes('componentProp')) { return; } @@ -419,8 +419,7 @@ function describeConformance( const { after: runAfterHook = () => {}, only = Object.keys(fullSuite), skip = [] } = getOptions(); const filteredTests = Object.keys(fullSuite).filter( - (testKey) => - only.indexOf(testKey) !== -1 && skip.indexOf(testKey as keyof typeof fullSuite) === -1, + (testKey) => only.includes(testKey) && !skip.includes(testKey as keyof typeof fullSuite), ) as (keyof typeof fullSuite)[]; after(runAfterHook); diff --git a/packages/mui-codemod/src/v1.0.0/color-imports.js b/packages/mui-codemod/src/v1.0.0/color-imports.js index c87088429c85fd..f2c70a2e314e43 100644 --- a/packages/mui-codemod/src/v1.0.0/color-imports.js +++ b/packages/mui-codemod/src/v1.0.0/color-imports.js @@ -31,7 +31,7 @@ function colorAccent(colorIdentifier) { * @param {string} colorPalette */ function colorImportPath(colorPalette) { - return commonColors.indexOf(colorPalette) !== -1 ? 'common' : colorPalette; + return commonColors.includes(colorPalette) ? 'common' : colorPalette; } /** @@ -89,7 +89,7 @@ function transformMemberImports(j, root, importPath, targetPath) { const colorIdentifier = j.identifier(colorModuleName); // import color module (if not already imported) - if (importDeclarations.map((p) => p.source.value).indexOf(modulePath) === -1) { + if (!importDeclarations.map((p) => p.source.value).includes(modulePath)) { importDeclarations.push( j.importDeclaration( [j.importDefaultSpecifier(colorIdentifier)], diff --git a/packages/mui-codemod/src/v5.0.0/theme-spacing.test/large-actual.js b/packages/mui-codemod/src/v5.0.0/theme-spacing.test/large-actual.js index 631c75ba8fa7a3..e42a1360ad5b04 100644 --- a/packages/mui-codemod/src/v5.0.0/theme-spacing.test/large-actual.js +++ b/packages/mui-codemod/src/v5.0.0/theme-spacing.test/large-actual.js @@ -211,8 +211,8 @@ export default function AppSearch() { const [isOpen, setIsOpen] = React.useState(false); const [initialQuery, setInitialQuery] = React.useState(undefined); const facetFilterLanguage = - LANGUAGES_SSR.indexOf(userLanguage) !== -1 ? `language:${userLanguage}` : `language:en`; - const macOS = window.navigator.platform.toUpperCase().indexOf('MAC') >= 0; + LANGUAGES_SSR.includes(userLanguage) ? `language:${userLanguage}` : `language:en`; + const macOS = window.navigator.platform.toUpperCase().includes('MAC'); const onOpen = React.useCallback(() => { setIsOpen(true); }, [setIsOpen]); diff --git a/packages/mui-codemod/src/v5.0.0/theme-spacing.test/large-expected.js b/packages/mui-codemod/src/v5.0.0/theme-spacing.test/large-expected.js index e83202eae425e5..57bf678f419c7c 100644 --- a/packages/mui-codemod/src/v5.0.0/theme-spacing.test/large-expected.js +++ b/packages/mui-codemod/src/v5.0.0/theme-spacing.test/large-expected.js @@ -211,8 +211,8 @@ export default function AppSearch() { const [isOpen, setIsOpen] = React.useState(false); const [initialQuery, setInitialQuery] = React.useState(undefined); const facetFilterLanguage = - LANGUAGES_SSR.indexOf(userLanguage) !== -1 ? `language:${userLanguage}` : `language:en`; - const macOS = window.navigator.platform.toUpperCase().indexOf('MAC') >= 0; + LANGUAGES_SSR.includes(userLanguage) ? `language:${userLanguage}` : `language:en`; + const macOS = window.navigator.platform.toUpperCase().includes('MAC'); const onOpen = React.useCallback(() => { setIsOpen(true); }, [setIsOpen]); diff --git a/packages/mui-codemod/src/v6.0.0/list-item-button-prop/list-item-button-prop.js b/packages/mui-codemod/src/v6.0.0/list-item-button-prop/list-item-button-prop.js index 22dd7082c0e611..9c24da2eab10ff 100644 --- a/packages/mui-codemod/src/v6.0.0/list-item-button-prop/list-item-button-prop.js +++ b/packages/mui-codemod/src/v6.0.0/list-item-button-prop/list-item-button-prop.js @@ -81,7 +81,7 @@ export default function transformer(file, api, options) { .filter((path) => { path.node.specifiers.forEach((specifier) => { if (specifier.type === 'ImportDefaultSpecifier') { - if (importsToRemove.indexOf(specifier.local.name) >= 0) { + if (importsToRemove.includes(specifier.local.name)) { path.node.specifiers = path.node.specifiers.filter((spec) => spec !== specifier); } } @@ -101,7 +101,7 @@ export default function transformer(file, api, options) { if ( specifier.type === 'ImportSpecifier' && specifier.imported.name === 'ListItem' && - importsToRemove.indexOf(specifier.local.name) >= 0 + importsToRemove.includes(specifier.local.name) ) { path.node.specifiers = path.node.specifiers.filter((spec) => spec !== specifier); } diff --git a/packages/mui-docs/src/CodeCopy/CodeCopy.tsx b/packages/mui-docs/src/CodeCopy/CodeCopy.tsx index b811544d8b3679..e0d3cdf971e77c 100644 --- a/packages/mui-docs/src/CodeCopy/CodeCopy.tsx +++ b/packages/mui-docs/src/CodeCopy/CodeCopy.tsx @@ -44,7 +44,7 @@ function InitCodeCopy() { React.useEffect(() => { let key = 'Ctrl + '; if (typeof window !== 'undefined') { - const macOS = window.navigator.platform.toUpperCase().indexOf('MAC') >= 0; + const macOS = window.navigator.platform.toUpperCase().includes('MAC'); if (macOS) { key = '⌘'; } diff --git a/packages/mui-docs/src/CodeCopy/CodeCopyButton.tsx b/packages/mui-docs/src/CodeCopy/CodeCopyButton.tsx index 4b90ca5e71b1d3..1cc7dd5c7cd247 100644 --- a/packages/mui-docs/src/CodeCopy/CodeCopyButton.tsx +++ b/packages/mui-docs/src/CodeCopy/CodeCopyButton.tsx @@ -9,7 +9,7 @@ export function CodeCopyButton(props: CodeCopyButtonProps) { const { code, ...other } = props; const { copy, isCopied } = useClipboardCopy(); // This component is designed to be wrapped in NoSsr - const macOS = window.navigator.platform.toUpperCase().indexOf('MAC') >= 0; + const macOS = window.navigator.platform.toUpperCase().includes('MAC'); const key = macOS ? '⌘' : 'Ctrl + '; return ( diff --git a/packages/mui-envinfo/envinfo.js b/packages/mui-envinfo/envinfo.js index bb13937b0a000f..855e26a0745077 100755 --- a/packages/mui-envinfo/envinfo.js +++ b/packages/mui-envinfo/envinfo.js @@ -1,7 +1,7 @@ #!/usr/bin/env node const envinfo = require('envinfo'); -const json = process.argv.indexOf('--json') !== -1; +const json = process.argv.includes('--json'); envinfo .run( { diff --git a/packages/mui-icons-material/builder.mjs b/packages/mui-icons-material/builder.mjs index 536c23339a9bfa..56b8e003e76248 100755 --- a/packages/mui-icons-material/builder.mjs +++ b/packages/mui-icons-material/builder.mjs @@ -66,7 +66,7 @@ function removeNoise(input, prevInput = null) { let output = input; noises.forEach(([search, replace]) => { - if (output.indexOf(search) !== -1) { + if (output.includes(search)) { output = output.replace(search, replace); } }); diff --git a/packages/mui-material/src/ClickAwayListener/ClickAwayListener.tsx b/packages/mui-material/src/ClickAwayListener/ClickAwayListener.tsx index 57d83c6b9d053a..5b1aa759ee8ad3 100644 --- a/packages/mui-material/src/ClickAwayListener/ClickAwayListener.tsx +++ b/packages/mui-material/src/ClickAwayListener/ClickAwayListener.tsx @@ -133,7 +133,7 @@ function ClickAwayListener(props: ClickAwayListenerProps): React.JSX.Element { // If not enough, can use https://github.com/DieterHolvoet/event-propagation-path/blob/master/propagationPath.js if (event.composedPath) { - insideDOM = event.composedPath().indexOf(nodeRef.current) > -1; + insideDOM = event.composedPath().includes(nodeRef.current); } else { insideDOM = !doc.documentElement.contains( diff --git a/packages/mui-material/src/Modal/ModalManager.ts b/packages/mui-material/src/Modal/ModalManager.ts index 81470c4864f831..4fc0695d96d04c 100644 --- a/packages/mui-material/src/Modal/ModalManager.ts +++ b/packages/mui-material/src/Modal/ModalManager.ts @@ -51,7 +51,7 @@ function isAriaHiddenForbiddenOnElement(element: Element): boolean { 'SOURCE', 'TRACK', ]; - const isForbiddenTagName = forbiddenTagNames.indexOf(element.tagName) !== -1; + const isForbiddenTagName = forbiddenTagNames.includes(element.tagName); const isInputHidden = element.tagName === 'INPUT' && element.getAttribute('type') === 'hidden'; return isForbiddenTagName || isInputHidden; } @@ -66,7 +66,7 @@ function ariaHiddenSiblings( const blacklist = [mountElement, currentElement, ...elementsToExclude]; [].forEach.call(container.children, (element: Element) => { - const isNotExcludedElement = blacklist.indexOf(element) === -1; + const isNotExcludedElement = !blacklist.includes(element); const isNotForbiddenElement = !isAriaHiddenForbiddenOnElement(element); if (isNotExcludedElement && isNotForbiddenElement) { ariaHidden(element, show); @@ -247,10 +247,7 @@ export class ModalManager { } mount(modal: Modal, props: ManagedModalProps): void { - const containerIndex = findIndexOf( - this.containers, - (item) => item.modals.indexOf(modal) !== -1, - ); + const containerIndex = findIndexOf(this.containers, (item) => item.modals.includes(modal)); const containerInfo = this.containers[containerIndex]; if (!containerInfo.restore) { @@ -265,10 +262,7 @@ export class ModalManager { return modalIndex; } - const containerIndex = findIndexOf( - this.containers, - (item) => item.modals.indexOf(modal) !== -1, - ); + const containerIndex = findIndexOf(this.containers, (item) => item.modals.includes(modal)); const containerInfo = this.containers[containerIndex]; containerInfo.modals.splice(containerInfo.modals.indexOf(modal), 1); diff --git a/packages/mui-material/src/Slider/useSlider.ts b/packages/mui-material/src/Slider/useSlider.ts index d36189f6a72022..0cd7ba016c3387 100644 --- a/packages/mui-material/src/Slider/useSlider.ts +++ b/packages/mui-material/src/Slider/useSlider.ts @@ -415,13 +415,13 @@ export function useSlider(parameters: UseSliderParameters): UseSliderReturnValue const { width, height, bottom, left } = slider!.getBoundingClientRect(); let percent; - if (axis.indexOf('vertical') === 0) { + if (axis.startsWith('vertical')) { percent = (bottom - finger.y) / height; } else { percent = (finger.x - left) / width; } - if (axis.indexOf('-reverse') !== -1) { + if (axis.includes('-reverse')) { percent = 1 - percent; } diff --git a/packages/mui-material/src/ToggleButtonGroup/isValueSelected.js b/packages/mui-material/src/ToggleButtonGroup/isValueSelected.js index 068c06c00173f4..a1c44bfd4e7c48 100644 --- a/packages/mui-material/src/ToggleButtonGroup/isValueSelected.js +++ b/packages/mui-material/src/ToggleButtonGroup/isValueSelected.js @@ -6,7 +6,7 @@ export default function isValueSelected(value, candidate) { } if (Array.isArray(candidate)) { - return candidate.indexOf(value) >= 0; + return candidate.includes(value); } return value === candidate; diff --git a/packages/mui-material/src/useAutocomplete/useAutocomplete.js b/packages/mui-material/src/useAutocomplete/useAutocomplete.js index 264a6e2218acdf..35789e85e2917c 100644 --- a/packages/mui-material/src/useAutocomplete/useAutocomplete.js +++ b/packages/mui-material/src/useAutocomplete/useAutocomplete.js @@ -44,9 +44,7 @@ export function createFilterOptions(config = {}) { candidate = stripDiacritics(candidate); } - return matchFrom === 'start' - ? candidate.indexOf(input) === 0 - : candidate.indexOf(input) > -1; + return matchFrom === 'start' ? candidate.startsWith(input) : candidate.includes(input); }); return typeof limit === 'number' ? filteredOptions.slice(0, limit) : filteredOptions; @@ -762,7 +760,7 @@ function useAutocomplete(props) { return; } - if (focusedTag !== -1 && ['ArrowLeft', 'ArrowRight'].indexOf(event.key) === -1) { + if (focusedTag !== -1 && !['ArrowLeft', 'ArrowRight'].includes(event.key)) { setFocusedTag(-1); focusTag(-1); } diff --git a/packages/mui-styles/src/createGenerateClassName/createGenerateClassName.js b/packages/mui-styles/src/createGenerateClassName/createGenerateClassName.js index 5571eefcd73c48..cc510c54c9f2ac 100644 --- a/packages/mui-styles/src/createGenerateClassName/createGenerateClassName.js +++ b/packages/mui-styles/src/createGenerateClassName/createGenerateClassName.js @@ -52,7 +52,7 @@ export default function createGenerateClassName(options = {}) { // Is a global static MUI style? if (name && name.startsWith('Mui') && !styleSheet.options.link && !disableGlobal) { // We can use a shorthand class name, we never use the keys to style the components. - if (stateClasses.indexOf(rule.key) !== -1) { + if (stateClasses.includes(rule.key)) { return `Mui-${rule.key}`; } diff --git a/packages/mui-styles/src/makeStyles/makeStyles.js b/packages/mui-styles/src/makeStyles/makeStyles.js index ceaa03778448e6..d18086cb7e6f9a 100644 --- a/packages/mui-styles/src/makeStyles/makeStyles.js +++ b/packages/mui-styles/src/makeStyles/makeStyles.js @@ -262,12 +262,7 @@ export default function makeStyles(stylesOrCreator, options = {}) { 'MuiTimelineDot', ]; - if ( - name && - supportedComponents.indexOf(name) >= 0 && - props.variant && - !classes[props.variant] - ) { + if (name && supportedComponents.includes(name) && props.variant && !classes[props.variant]) { console.error( [ `MUI: You are using a variant value \`${props.variant}\` for which you didn't define styles.`, diff --git a/packages/mui-styles/src/styled/styled.js b/packages/mui-styles/src/styled/styled.js index 071bed8cf4f95a..e6743a3c4d2bd8 100644 --- a/packages/mui-styles/src/styled/styled.js +++ b/packages/mui-styles/src/styled/styled.js @@ -9,7 +9,7 @@ function omit(input, fields) { const output = {}; Object.keys(input).forEach((prop) => { - if (fields.indexOf(prop) === -1) { + if (!fields.includes(prop)) { output[prop] = input[prop]; } }); diff --git a/packages/mui-system/src/cssVars/cssVarsParser.ts b/packages/mui-system/src/cssVars/cssVarsParser.ts index 0e4113f55fb7bc..a3bcde5e99ff10 100644 --- a/packages/mui-system/src/cssVars/cssVarsParser.ts +++ b/packages/mui-system/src/cssVars/cssVarsParser.ts @@ -88,7 +88,7 @@ const getCssValue = (keys: string[], value: string | number) => { return value; } const lastKey = keys[keys.length - 1]; - if (lastKey.toLowerCase().indexOf('opacity') >= 0) { + if (lastKey.toLowerCase().includes('opacity')) { // opacity values are unitless return value; } diff --git a/packages/mui-utils/src/requirePropFactory/requirePropFactory.test.js b/packages/mui-utils/src/requirePropFactory/requirePropFactory.test.js index e0651ee376ce02..01e39f5a242462 100644 --- a/packages/mui-utils/src/requirePropFactory/requirePropFactory.test.js +++ b/packages/mui-utils/src/requirePropFactory/requirePropFactory.test.js @@ -105,11 +105,11 @@ describe('requirePropFactory', () => { }); it('returned error message should have propFullName', () => { - expect(result.message.indexOf(propFullName) > -1).to.equal(true); + expect(result.message.includes(propFullName)).to.equal(true); }); it('returned error message should not have propName', () => { - expect(result.message.indexOf(propName)).to.equal(-1); + expect(result.message.includes(propName)).to.equal(false); }); }); }); diff --git a/scripts/build.mjs b/scripts/build.mjs index 27054ee0ac17fe..56e8efbd87ab73 100644 --- a/scripts/build.mjs +++ b/scripts/build.mjs @@ -20,7 +20,7 @@ const validBundles = [ async function run(argv) { const { bundle, largeFiles, outDir: relativeOutDir, verbose } = argv; - if (validBundles.indexOf(bundle) === -1) { + if (!validBundles.includes(bundle)) { throw new TypeError( `Unrecognized bundle '${bundle}'. Did you mean one of "${validBundles.join('", "')}"?`, ); diff --git a/scripts/buildTypes.mjs b/scripts/buildTypes.mjs index f2a4e0d9e4f5fc..0cb6dd8afce7dd 100644 --- a/scripts/buildTypes.mjs +++ b/scripts/buildTypes.mjs @@ -38,7 +38,7 @@ async function rewriteImportPaths(declarationFile, publishDir) { if ( // Only consider React components basename[0] === basename[0].toUpperCase() && - code.indexOf("import PropTypes from 'prop-types';") !== -1 + code.includes("import PropTypes from 'prop-types';") ) { throw new Error( [ diff --git a/scripts/sizeSnapshot/webpack.config.js b/scripts/sizeSnapshot/webpack.config.js index f447355857520b..e366985ba7d5db 100644 --- a/scripts/sizeSnapshot/webpack.config.js +++ b/scripts/sizeSnapshot/webpack.config.js @@ -32,7 +32,7 @@ async function getWebpackEntries() { const componentName = path.basename(path.dirname(componentPath)); let entryName = componentName; - if (['Popper'].indexOf(componentName) !== -1) { + if (['Popper'].includes(componentName)) { entryName = `@material-ui/core/${componentName}`; }