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

[code-infra] Forbid calling Error without new #43963

Merged
merged 5 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 12 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
// @ts-check

/**
* @typedef {import('eslint').Linter.Config} Config
*/

const path = require('path');

const OneLevelImportMessage = [
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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: 'Do not call `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
Expand Down Expand Up @@ -526,4 +536,4 @@ module.exports = {
},
},
],
};
});
4 changes: 2 additions & 2 deletions docs/src/modules/components/ApiPage/definitions/classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion packages-internal/test-utils/src/createRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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' +
Expand Down