[code-infra] Lint rule to disallow guarded throw#1074
Conversation
✅ Deploy Preview for mui-internal ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Bundle size report
Check out the code infra dashboard for more information about this PR. |
There was a problem hiding this comment.
Pull request overview
Adds an ESLint rule to prevent throw statements from living inside branches whose execution depends on process.env.NODE_ENV, aligning with the goal of avoiding environment-dependent control-flow differences and supporting the earlier “skip error minification in dev-only branches” work.
Changes:
- Introduces
mui/no-guarded-throwrule plus a dedicated RuleTester suite. - Refactors
require-dev-wrapperto reuse new shared NODE_ENV “inside if-check” utilities. - Enables the new rule in the core ESLint config and wires it into the
muiplugin export list.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/test-utils/src/chaiPlugin.ts | Suppresses the new rule for a dev-only rethrow in an existing matcher implementation. |
| packages/code-infra/src/eslint/mui/rules/require-dev-wrapper.mjs | Uses a shared helper to detect NODE_ENV guard ancestry. |
| packages/code-infra/src/eslint/mui/rules/nodeEnvUtils.mjs | Adds shared utilities for detecting NODE_ENV binary comparisons and ancestry. |
| packages/code-infra/src/eslint/mui/rules/no-guarded-throw.mjs | Adds the new rule implementation that reports throws under NODE_ENV-dependent if branches. |
| packages/code-infra/src/eslint/mui/rules/no-guarded-throw.test.mjs | Adds tests covering common NODE_ENV-guard shapes (including composed conditions). |
| packages/code-infra/src/eslint/mui/index.mjs | Registers the new rule in the plugin entry point. |
| packages/code-infra/src/eslint/mui/config.mjs | Enables mui/no-guarded-throw as an error in the core config. |
Deploy previewhttps://deploy-preview-1074--mui-internal.netlify.app/ Bundle sizeTotal Size Change: 0B(0.00%) - Total Gzip Change: 0B(0.00%) Show details for 25 more bundles@mui/internal-docs-infra/abstractCreateDemo parsed: 0B(0.00%) gzip: 0B(0.00%) PerformanceTotal duration: 16.91 ms -0.06 ms(-0.4%) | Renders: 4 (+0) | Paint: 70.30 ms -3.50 ms(-4.7%)
Check out the code infra dashboard for more information about this PR. |
Implement #1069 (comment)
Make it a lint error to throw inside of a block that is branching into
process.env.NODE_ENVone way or the other.