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] Add eslint rule to restrict import from ../internals root #13633

Merged
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
44 changes: 30 additions & 14 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
const baseline = require('@mui/monorepo/.eslintrc');
const path = require('path');

const chartsPackages = ['x-charts', 'x-charts-pro'];

const dataGridPackages = [
'x-data-grid',
'x-data-grid-pro',
'x-data-grid-premium',
'x-data-grid-generator',
];

const datePickersPackages = ['x-date-pickers', 'x-date-pickers-pro'];

const treeViewPackages = ['x-tree-view', 'x-tree-view-pro'];

// Enable React Compiler Plugin rules globally
const ENABLE_REACT_COMPILER_PLUGIN = process.env.ENABLE_REACT_COMPILER_PLUGIN ?? false;

Expand Down Expand Up @@ -139,6 +152,18 @@ module.exports = {
...(ENABLE_REACT_COMPILER_PLUGIN ? { 'react-compiler/react-compiler': 'error' } : {}),
// TODO move to @mui/monorepo/.eslintrc, codebase is moving away from default exports
'import/prefer-default-export': 'off',
'import/no-restricted-paths': [
'error',
{
zones: [...chartsPackages, ...datePickersPackages, ...treeViewPackages].map(
(packageName) => ({
target: `./packages/${packageName}/src/**/!(*.test.*|*.spec.*)`,
from: `./packages/${packageName}/src/internals/index.ts`,
message: `Use a more specific import instead. E.g. import { MyInternal } from '../internals/MyInternal';`,
}),
),
},
],
// TODO move rule into the main repo once it has upgraded
'@typescript-eslint/return-await': 'off',
'no-restricted-imports': 'off',
Expand Down Expand Up @@ -167,7 +192,7 @@ module.exports = {
// TODO move to @mui/monorepo/.eslintrc
// TODO Fix <Input> props names to not conflict
'react/jsx-no-duplicate-props': [1, { ignoreCase: false }],
// TOOD move to @mui/monorepo/.eslintrc, these are false positive
// TODO move to @mui/monorepo/.eslintrc, these are false positive
'react/no-unstable-nested-components': ['error', { allowAsProps: true }],
},
overrides: [
Expand Down Expand Up @@ -257,18 +282,9 @@ module.exports = {
...buildPackageRestrictedImports('@mui/x-tree-view-pro', 'x-tree-view-pro', false),
...buildPackageRestrictedImports('@mui/x-license', 'x-license'),

...addReactCompilerRule(['x-charts', 'x-charts-pro'], ENABLE_REACT_COMPILER_PLUGIN_CHARTS),
...addReactCompilerRule(
['x-data-grid', 'x-data-grid-pro', 'x-data-grid-premium', 'x-data-grid-generator'],
ENABLE_REACT_COMPILER_PLUGIN_DATA_GRID,
),
...addReactCompilerRule(
['x-date-pickers', 'x-date-pickers-pro'],
ENABLE_REACT_COMPILER_PLUGIN_DATE_PICKERS,
),
...addReactCompilerRule(
['x-tree-view', 'x-tree-view-pro'],
ENABLE_REACT_COMPILER_PLUGIN_TREE_VIEW,
),
...addReactCompilerRule(chartsPackages, ENABLE_REACT_COMPILER_PLUGIN_CHARTS),
...addReactCompilerRule(dataGridPackages, ENABLE_REACT_COMPILER_PLUGIN_DATA_GRID),
...addReactCompilerRule(datePickersPackages, ENABLE_REACT_COMPILER_PLUGIN_DATE_PICKERS),
...addReactCompilerRule(treeViewPackages, ENABLE_REACT_COMPILER_PLUGIN_TREE_VIEW),
],
};
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { MULTI_SECTION_CLOCK_SECTION_WIDTH } from '../internals/constants/dimens
import { formatMeridiem } from '../internals/utils/date-utils';
import { MakeOptional } from '../internals/models/helpers';
import { pickersToolbarTextClasses } from '../internals/components/pickersToolbarTextClasses';
import { pickersToolbarClasses } from '../internals';
import { pickersToolbarClasses } from '../internals/components/pickersToolbarClasses';
import { PickerValidDate } from '../models';

export interface ExportedDateTimePickerToolbarProps extends ExportedBaseToolbarProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,18 @@ import {
renderDigitalClockTimeView,
renderMultiSectionDigitalClockTimeView,
} from '../timeViewRenderers';
import {
DefaultizedProps,
UsePickerViewsProps,
VIEW_HEIGHT,
isDatePickerView,
isInternalTimeView,
} from '../internals';

import {
multiSectionDigitalClockClasses,
multiSectionDigitalClockSectionClasses,
} from '../MultiSectionDigitalClock';
import { digitalClockClasses } from '../DigitalClock';
import { DesktopDateTimePickerLayout } from './DesktopDateTimePickerLayout';
import { VIEW_HEIGHT } from '../internals/constants/dimensions';
import { DefaultizedProps } from '../internals/models/helpers';
import { UsePickerViewsProps } from '../internals/hooks/usePicker/usePickerViews';
import { isInternalTimeView } from '../internals/utils/time-utils';
import { isDatePickerView } from '../internals/utils/date-utils';

const rendererInterceptor = function rendererInterceptor<
TDate extends PickerValidDate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
usePickerLayout,
} from '../PickersLayout';
import { PickerValidDate } from '../models';
import { DateOrTimeViewWithMeridiem } from '../internals';
import { DateOrTimeViewWithMeridiem } from '../internals/models/common';

/**
* @ignore - internal component.
Expand Down