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

[core] Restrict import path with ESLint #41970

Merged
merged 2 commits into from
May 1, 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
40 changes: 18 additions & 22 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const path = require('path');
const { rules: baseStyleRules } = require('eslint-config-airbnb-base/rules/style');

const forbidTopLevelMessage = [
'Prefer one level nested imports to avoid bundling everything in dev mode',
const OneLevelImportMessage = [
'Prefer one level nested imports to avoid bundling everything in dev mode or breaking CJS/ESM split.',
'See https://github.com/mui/material-ui/pull/24147 for the kind of win it can unlock.',
].join('\n');
// This only applies to packages published from this monorepo.
Expand Down Expand Up @@ -65,7 +65,20 @@ module.exports = {
'no-restricted-imports': [
'error',
{
patterns: ['@mui/*/*/*'],
patterns: [
{
group: [
'@mui/*/*/*',
'@pigment-css/*/*/*',
'@base_ui/*/*/*',
// Allow any import depth with any internal packages
'!@mui/internal-*/**',
// TODO delete, @mui/docs should be @mui/internal-docs
'!@mui/docs/**',
Copy link
Member Author

Choose a reason for hiding this comment

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

We should rename this one to @mui/internal-docs. @mui/docs was exporting public packages, it's not the case anymore.

],
message: OneLevelImportMessage,
},
],
},
],
'no-continue': 'off',
Expand Down Expand Up @@ -331,23 +344,6 @@ module.exports = {
'import/export': 'off', // Not sure why it doesn't work
},
},
{
files: ['*.tsx'],
excludedFiles: '*.spec.tsx',
rules: {
// WARNING: If updated, make sure these rules are merged with `no-restricted-imports` (#ts-source-files)
'no-restricted-imports': [
'error',
{
patterns: [
// Allow deeper imports for TypeScript types. TODO remove
'@mui/*/*/*/*',
],
},
],
},
},
// Files used for generating TypeScript declaration files (#ts-source-files)
{
files: ['packages/*/src/**/*.tsx'],
excludedFiles: '*.spec.tsx',
Expand Down Expand Up @@ -429,11 +425,11 @@ module.exports = {
paths: [
{
name: '@mui/material',
message: forbidTopLevelMessage,
message: OneLevelImportMessage,
},
{
name: '@mui/lab',
message: forbidTopLevelMessage,
message: OneLevelImportMessage,
},
],
},
Expand Down
2 changes: 1 addition & 1 deletion apps/pigment-css-vite-app/src/Slider/ZeroSlider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import { isHostComponent, useSlotProps } from '@mui/base/utils';
import { styled } from '@pigment-css/react';
import { capitalize } from '@mui/material/utils';
import SliderValueLabel from '@mui/material/Slider/SliderValueLabel';
import { SliderValueLabel } from '@mui/material/Slider';
import { useSlider, valueToPercent } from '@mui/base/useSlider';
import { alpha, lighten, darken } from '@mui/system/colorManipulator';
import type { Theme } from '@mui/material/styles';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Slide from '@mui/material/Slide';
import CloseIcon from '@mui/icons-material/Close';
import InfoIcon from '@mui/icons-material/Info';
import IconButton from '@mui/material/IconButton';
import { TransitionProps } from '@mui/material/transitions/transition';
import { TransitionProps } from '@mui/material/transitions';

const styles = ({ theme }: { theme: Theme }) =>
({
Expand Down
Loading