Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 10, 2025

Adds material-ui/no-restricted-imports rule to replace complex no-restricted-imports configurations with robust glob pattern matching on import source strings.

Implementation

  • Rule: packages/code-infra/src/eslint/material-ui/rules/no-restricted-imports.mjs

    • Restricts imports by source string patterns (e.g., '@mui/material/Box') rather than resolved file paths
    • Uses minimatch for glob patterns: @mui/material/*, @mui/*/internal/**, ./**/*.css
    • Supports custom error messages per pattern
    • Handles both ESM (import) and CommonJS (require())
  • Tests: 17 test cases covering glob patterns, wildcards, named/namespace imports, CommonJS, custom messages

  • Export: Added to material-ui plugin in index.mjs

  • Documentation: Added ESLint plugin section to README with usage examples

Usage

// eslint.config.mjs
{
  rules: {
    'material-ui/no-restricted-imports': [
      'error',
      [
        {
          pattern: '@mui/material/*',
          message: 'Use the default import from @mui/material instead.'
        },
        {
          pattern: '@mui/*/internal/**',
          message: 'Do not import from internal modules.'
        }
      ]
    ]
  }
}

Comparison with existing rule

no-restricted-resolved-imports matches resolved file paths (after module resolution). This new rule matches import source strings directly, making it more suitable for restricting module/package imports by pattern.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • iojs.org
    • Triggering command: curl --fail --compressed -q -L -s REDACTED -o - (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>[code-infra] Create a custom eslint rule for restricted imports</issue_title>
<issue_description># Feature request

Summary

We've been using no-restricted-imports with complex configuration to restrict certain import paths. Makes sense to have a more robust rule specific to the use case.

More context here - mui/base-ui#2054 (comment)

Examples in other libraries

Motivation

</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@mui-bot
Copy link

mui-bot commented Nov 10, 2025

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.

Copilot AI changed the title [WIP] Create a custom eslint rule for restricted imports Add custom ESLint rule for pattern-based import restrictions Nov 10, 2025
Copilot AI requested a review from brijeshb42 November 10, 2025 06:57
Copilot finished work on behalf of brijeshb42 November 10, 2025 06:57
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Nov 24, 2025
@zannager zannager added the scope: code-infra Involves the code-infra product (https://www.notion.so/mui-org/5562c14178aa42af97bc1fa5114000cd). label Nov 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: out-of-date The pull request has merge conflicts and can't be merged. scope: code-infra Involves the code-infra product (https://www.notion.so/mui-org/5562c14178aa42af97bc1fa5114000cd).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[code-infra] Create a custom eslint rule for restricted imports

4 participants