Skip to content

[code-infra] Lint rule to disallow guarded throw#1074

Merged
Janpot merged 15 commits intomasterfrom
new-feature
Apr 30, 2026
Merged

[code-infra] Lint rule to disallow guarded throw#1074
Janpot merged 15 commits intomasterfrom
new-feature

Conversation

@Janpot
Copy link
Copy Markdown
Member

@Janpot Janpot commented Jan 27, 2026

Implement #1069 (comment)

Make it a lint error to throw inside of a block that is branching into process.env.NODE_ENV one way or the other.

@netlify
Copy link
Copy Markdown

netlify Bot commented Jan 27, 2026

Deploy Preview for mui-internal ready!

Name Link
🔨 Latest commit fe3d901
🔍 Latest deploy log https://app.netlify.com/projects/mui-internal/deploys/6978d6e6c1fd080008ab9ad3
😎 Deploy Preview https://deploy-preview-1074--mui-internal.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@Janpot Janpot added the scope: code-infra Involves the code-infra product (https://www.notion.so/mui-org/5562c14178aa42af97bc1fa5114000cd). label Jan 27, 2026
@oliviertassinari oliviertassinari added the type: new feature Expand the scope of the product to solve a new problem. label Jan 27, 2026
@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Jan 30, 2026
@github-actions github-actions Bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Jan 30, 2026
@mui-bot
Copy link
Copy Markdown

mui-bot commented Jan 30, 2026

Bundle size report

Bundle Parsed size Gzip size
@base-ui-components/react 0B(0.00%) 0B(0.00%)
@mui/x-charts-pro 0B(0.00%) 0B(0.00%)

Details of bundle changes


Check out the code infra dashboard for more information about this PR.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-throw rule plus a dedicated RuleTester suite.
  • Refactors require-dev-wrapper to reuse new shared NODE_ENV “inside if-check” utilities.
  • Enables the new rule in the core ESLint config and wires it into the mui plugin 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.

Comment thread packages/code-infra/src/eslint/mui/rules/no-guarded-throw.mjs
Comment thread packages/test-utils/src/chaiPlugin.ts
@Janpot Janpot requested a review from a team March 10, 2026 12:56
@code-infra-dashboard
Copy link
Copy Markdown

code-infra-dashboard Bot commented Apr 30, 2026

Deploy preview

https://deploy-preview-1074--mui-internal.netlify.app/

Bundle size

Total Size Change: 0B(0.00%) - Total Gzip Change: 0B(0.00%)
Files: 25 total (0 added, 0 removed, 0 changed)

Show details for 25 more bundles

@mui/internal-docs-infra/abstractCreateDemoparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/abstractCreateDemoClientparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/abstractCreateTypesparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/CodeControllerContextparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/CodeExternalsContextparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/CodeHighlighterparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/CodeHighlighter/errorsparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/CodeHighlighter/typesparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/CodeProviderparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/createDemoDataparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/createDemoData/typesparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/createSitemapparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/createSitemap/typesparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useCodeparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useCopierparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useDemoparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useErrorsparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useLocalStorageStateparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/usePreferenceparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useSearchparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useSearch/typesparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useTypeparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useTypesparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useUrlHashStateparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/withDocsInfraparsed: 0B(0.00%) gzip: 0B(0.00%)

Details of bundle changes

Performance

Total duration: 16.91 ms -0.06 ms(-0.4%) | Renders: 4 (+0) | Paint: 70.30 ms -3.50 ms(-4.7%)

Test Duration Renders
DataGrid mount with paint timing 2.00 ms 🔺+0.09 ms(+4.7%) 1 (+0)
Counter click 4.15 ms ▼-0.09 ms(-2.0%) 2 (+0)
HeavyList mount 10.76 ms ▼-0.06 ms(-0.6%) 1 (+0)

details


Check out the code infra dashboard for more information about this PR.

@Janpot Janpot merged commit c53e489 into master Apr 30, 2026
13 checks passed
@Janpot Janpot deleted the new-feature branch April 30, 2026 11:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: code-infra Involves the code-infra product (https://www.notion.so/mui-org/5562c14178aa42af97bc1fa5114000cd). type: new feature Expand the scope of the product to solve a new problem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants