From 07b83832d3aff82b9a49d446db04079e80153870 Mon Sep 17 00:00:00 2001 From: MUI bot <2109932+Janpot@users.noreply.github.com> Date: Wed, 2 Oct 2024 10:11:21 +0200 Subject: [PATCH 1/3] [code-infra] Forbid calling Error without new --- .eslintignore | 1 - .eslintrc.js | 14 ++++++++++++-- .../components/ApiPage/definitions/classes.ts | 4 ++-- .../test-utils/src/createRenderer.tsx | 2 +- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/.eslintignore b/.eslintignore index 8100e5ec04840b..ec34e0c6403844 100644 --- a/.eslintignore +++ b/.eslintignore @@ -16,7 +16,6 @@ /packages/mui-icons-material/material-icons/ /packages/mui-icons-material/src/*.js /packages/mui-icons-material/templateSvgIcon.js -/packages/mui-utils/macros/__fixtures__/ # Ignore fixtures /packages-internal/scripts/typescript-to-proptypes/test/*/* /test/bundling/fixtures/**/*.fixture.js diff --git a/.eslintrc.js b/.eslintrc.js index 038be57d26624c..85939da23aab3e 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,3 +1,9 @@ +// @ts-check + +/** + * @typedef {import('eslint').Linter.Config} Config + */ + const path = require('path'); const OneLevelImportMessage = [ @@ -39,7 +45,7 @@ const NO_RESTRICTED_IMPORTS_PATTERNS_DEEPLY_NESTED = [ }, ]; -module.exports = { +module.exports = /** @type {Config} */ ({ root: true, // So parent files don't get applied env: { es6: true, @@ -228,6 +234,10 @@ module.exports = { "The 'use client' pragma can't be used with export * in the same module. This is not supported by Next.js.", selector: 'ExpressionStatement[expression.value="use client"] ~ ExportAllDeclaration', }, + { + message: 'Avoid calling Error without `new`. Use `new Error()` instead.', + selector: "CallExpression[callee.name='Error']", + }, ], // We re-export default in many places, remove when https://github.com/airbnb/javascript/issues/2500 gets resolved @@ -526,4 +536,4 @@ module.exports = { }, }, ], -}; +}); diff --git a/docs/src/modules/components/ApiPage/definitions/classes.ts b/docs/src/modules/components/ApiPage/definitions/classes.ts index ac8a8ef0e57d3e..055f640e0006a4 100644 --- a/docs/src/modules/components/ApiPage/definitions/classes.ts +++ b/docs/src/modules/components/ApiPage/definitions/classes.ts @@ -60,14 +60,14 @@ export function getClassApiDefinitions(params: GetClassApiDefinitionsParams): Cl if (description.includes('{{conditions}}')) { if (!conditions) { - throw Error(errorMessage(componentName, classDefinition.className, 'conditions')); + throw new Error(errorMessage(componentName, classDefinition.className, 'conditions')); } description = description.replace(/{{conditions}}/, conditions); } if (description.includes('{{nodeName}}')) { if (!nodeName) { - throw Error(errorMessage(componentName, classDefinition.className, 'nodeName')); + throw new Error(errorMessage(componentName, classDefinition.className, 'nodeName')); } description = description.replace(/{{nodeName}}/, nodeName); } diff --git a/packages-internal/test-utils/src/createRenderer.tsx b/packages-internal/test-utils/src/createRenderer.tsx index f7107db5c1afe8..692174acbdc113 100644 --- a/packages-internal/test-utils/src/createRenderer.tsx +++ b/packages-internal/test-utils/src/createRenderer.tsx @@ -545,7 +545,7 @@ export function createRenderer(globalOptions: CreateRendererOptions = {}): Rende afterEach(() => { if (!clock.isReal()) { - const error = Error( + const error = new Error( "Can't cleanup before fake timers are restored.\n" + 'Be sure to:\n' + ' 1. Only use `clock` from `createRenderer`.\n' + From 7a11757c96c12df498760c464b0352b27a1f1f9c Mon Sep 17 00:00:00 2001 From: Jan Potoms <2109932+Janpot@users.noreply.github.com> Date: Wed, 2 Oct 2024 13:22:03 +0200 Subject: [PATCH 2/3] Update .eslintrc.js Co-authored-by: Marija Najdova Signed-off-by: Jan Potoms <2109932+Janpot@users.noreply.github.com> --- .eslintrc.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.eslintrc.js b/.eslintrc.js index 85939da23aab3e..0f9e902764c1ee 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -235,7 +235,7 @@ module.exports = /** @type {Config} */ ({ selector: 'ExpressionStatement[expression.value="use client"] ~ ExportAllDeclaration', }, { - message: 'Avoid calling Error without `new`. Use `new Error()` instead.', + message: 'Do not call Error without `new`. Use `new Error()` instead.', selector: "CallExpression[callee.name='Error']", }, ], From 9e5b148a241678832d414ecaffd6f8a4a27de44d Mon Sep 17 00:00:00 2001 From: MUI bot <2109932+Janpot@users.noreply.github.com> Date: Wed, 2 Oct 2024 17:44:04 +0200 Subject: [PATCH 3/3] Revert "Missing material base popper" This reverts commit bb9f21bbef23ec65b8c90d22fa823dd4bd673695. --- .eslintrc.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.eslintrc.js b/.eslintrc.js index 0f9e902764c1ee..e0f4b9c8d01018 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -235,7 +235,7 @@ module.exports = /** @type {Config} */ ({ selector: 'ExpressionStatement[expression.value="use client"] ~ ExportAllDeclaration', }, { - message: 'Do not call Error without `new`. Use `new Error()` instead.', + message: 'Do not call `Error(...)` without `new`. Use `new Error(...)` instead.', selector: "CallExpression[callee.name='Error']", }, ],