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] Refactor ESLint config to disallow root level imports #13130

Merged
merged 10 commits into from
May 15, 2024
130 changes: 89 additions & 41 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,85 @@ const path = require('path');

// TODO move this helper to @mui/monorepo/.eslintrc
// It needs to know about the parent "no-restricted-imports" to not override them.
const buildPackageRestrictedImports = (packageName, root) => ({
files: [`packages/${root}/src/**/*{.ts,.tsx,.js}`],
excludedFiles: ['*.d.ts', '*.spec.ts', '*.spec.tsx', '**.test.tx', '**.test.tsx'],
rules: {
'no-restricted-imports': [
'error',
{
paths: [
{
name: packageName,
message: 'Use relative import instead',
},
{
name: '@mui/material',
message: 'Use @mui/utils or a more specific import instead',
},
],
patterns: [
// TODO move rule into main repo to allow deep @mui/monorepo imports
{
group: ['@mui/*/*/*'],
message: 'Use less deep import instead',
},
{
group: [`${packageName}/*`, `${packageName}/**`],
message: 'Use relative import instead',
},
],
},
],
const buildPackageRestrictedImports = (packageName, root, allowRootImports = true) => [
{
files: [`packages/${root}/src/**/*{.ts,.tsx,.js}`],
excludedFiles: ['*.d.ts', '*.spec.ts', '*.spec.tsx', '**.test.tx', '**.test.tsx'],
rules: {
'no-restricted-imports': [
'error',
{
paths: [
{
name: packageName,
message: 'Use relative import instead',
},
{
name: '@mui/material',
message: 'Use @mui/utils or a more specific import instead',
},
],
patterns: [
// TODO move rule into main repo to allow deep @mui/monorepo imports
{
group: ['@mui/*/*/*'],
message: 'Use less deep import instead',
},
{
group: [`${packageName}/*`, `${packageName}/**`],
message: 'Use relative import instead',
},
],
},
],
},
},
});
...(allowRootImports
? []
: [
{
files: [
`packages/${root}/src/**/*.test{.ts,.tsx,.js}`,
`packages/${root}/src/**/*.spec{.ts,.tsx,.js}`,
'docs/data/**/*{.ts,.tsx,.js}',
],
excludedFiles: ['*.d.ts'],
rules: {
'no-restricted-imports': [
'error',
{
paths: [
{
name: '@mui/x-charts',
message: 'Use deeper import instead',
},
{
name: '@mui/x-codemod',
message: 'Use deeper import instead',
},
{
name: '@mui/x-date-pickers',
message: 'Use deeper import instead',
},
{
name: '@mui/x-date-pickers-pro',
message: 'Use deeper import instead',
},
{
name: '@mui/x-tree-view',
message: 'Use deeper import instead',
},
{
name: '@mui/x-tree-view-pro',
message: 'Use deeper import instead',
},
],
},
],
},
},
]),
];

module.exports = {
...baseline,
Expand Down Expand Up @@ -159,15 +206,16 @@ module.exports = {
],
},
},
buildPackageRestrictedImports('@mui/x-charts', 'x-charts'),
buildPackageRestrictedImports('@mui/x-data-grid', 'x-data-grid'),
buildPackageRestrictedImports('@mui/x-data-grid-pro', 'x-data-grid-pro'),
buildPackageRestrictedImports('@mui/x-data-grid-premium', 'x-data-grid-premium'),
buildPackageRestrictedImports('@mui/x-data-grid-generator', 'x-data-grid-generator'),
buildPackageRestrictedImports('@mui/x-pickers', 'x-pickers'),
buildPackageRestrictedImports('@mui/x-pickers-pro', 'x-pickers-pro'),
buildPackageRestrictedImports('@mui/x-tree-view', 'x-tree-view'),
buildPackageRestrictedImports('@mui/x-tree-view-pro', 'x-tree-view-pro'),
buildPackageRestrictedImports('@mui/x-license', 'x-license'),
...buildPackageRestrictedImports('@mui/x-charts', 'x-charts', false),
...buildPackageRestrictedImports('@mui/x-codemod', 'x-codemod', false),
...buildPackageRestrictedImports('@mui/x-data-grid', 'x-data-grid'),
...buildPackageRestrictedImports('@mui/x-data-grid-pro', 'x-data-grid-pro'),
...buildPackageRestrictedImports('@mui/x-data-grid-premium', 'x-data-grid-premium'),
...buildPackageRestrictedImports('@mui/x-data-grid-generator', 'x-data-grid-generator'),
...buildPackageRestrictedImports('@mui/x-date-pickers', 'x-date-pickers', false),
...buildPackageRestrictedImports('@mui/x-date-pickers-pro', 'x-date-pickers-pro', false),
Comment on lines +215 to +216
Copy link
Member Author

Choose a reason for hiding this comment

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

Notice the package name and path fixes - technically ESLint was not working on Pickers packages

...buildPackageRestrictedImports('@mui/x-tree-view', 'x-tree-view', false),
...buildPackageRestrictedImports('@mui/x-tree-view-pro', 'x-tree-view-pro', false),
...buildPackageRestrictedImports('@mui/x-license', 'x-license'),
],
};
3 changes: 2 additions & 1 deletion docs/data/charts/areas-demo/TinyAreaChart.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from 'react';
import { ChartContainer, AreaPlot } from '@mui/x-charts';
import { ChartContainer } from '@mui/x-charts/ChartContainer';
import { AreaPlot } from '@mui/x-charts/LineChart';

const uData = [4000, 3000, 2000, 2780, 1890, 2390, 3490];
const xLabels = [
Expand Down
3 changes: 2 additions & 1 deletion docs/data/charts/areas-demo/TinyAreaChart.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from 'react';
import { ChartContainer, AreaPlot } from '@mui/x-charts';
import { ChartContainer } from '@mui/x-charts/ChartContainer';
import { AreaPlot } from '@mui/x-charts/LineChart';

const uData = [4000, 3000, 2000, 2780, 1890, 2390, 3490];
const xLabels = [
Expand Down
2 changes: 1 addition & 1 deletion docs/data/charts/bar-demo/PositiveAndNegativeBarChart.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { BarChart } from '@mui/x-charts/BarChart';
import { AxisConfig } from '@mui/x-charts';
import { AxisConfig } from '@mui/x-charts/models';

const uData = [4000, 3000, 2000, 2780, 1890, 2390, 3490];
const pData = [2400, 1398, -9800, 3908, 4800, -3800, 4300];
Expand Down
3 changes: 2 additions & 1 deletion docs/data/charts/bar-demo/TinyBarChart.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from 'react';
import { ChartContainer, BarPlot } from '@mui/x-charts';
import { ChartContainer } from '@mui/x-charts/ChartContainer';
import { BarPlot } from '@mui/x-charts/BarChart';

const uData = [4000, 3000, 2000, 2780, 1890, 2390, 3490];
const xLabels = [
Expand Down
3 changes: 2 additions & 1 deletion docs/data/charts/bar-demo/TinyBarChart.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from 'react';
import { ChartContainer, BarPlot } from '@mui/x-charts';
import { ChartContainer } from '@mui/x-charts/ChartContainer';
import { BarPlot } from '@mui/x-charts/BarChart';

const uData = [4000, 3000, 2000, 2780, 1890, 2390, 3490];
const xLabels = [
Expand Down
2 changes: 1 addition & 1 deletion docs/data/charts/bars/BarsDataset.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { BarChart } from '@mui/x-charts/BarChart';
import { axisClasses } from '@mui/x-charts';
import { axisClasses } from '@mui/x-charts/ChartsAxis';

const chartSetting = {
yAxis: [
Expand Down
2 changes: 1 addition & 1 deletion docs/data/charts/bars/BarsDataset.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { BarChart } from '@mui/x-charts/BarChart';
import { axisClasses } from '@mui/x-charts';
import { axisClasses } from '@mui/x-charts/ChartsAxis';

const chartSetting = {
yAxis: [
Expand Down
4 changes: 3 additions & 1 deletion docs/data/charts/components/BasicScaleDemo.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import * as React from 'react';
import { styled } from '@mui/material/styles';
import { ResponsiveChartContainer, LinePlot, useDrawingArea } from '@mui/x-charts';
import { ResponsiveChartContainer } from '@mui/x-charts/ResponsiveChartContainer';
import { LinePlot } from '@mui/x-charts/LineChart';
import { useDrawingArea } from '@mui/x-charts/hooks';

const StyledPath = styled('path')(({ theme }) => ({
fill: 'none',
Expand Down
4 changes: 3 additions & 1 deletion docs/data/charts/components/BasicScaleDemo.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import * as React from 'react';
import { styled } from '@mui/material/styles';
import { ResponsiveChartContainer, LinePlot, useDrawingArea } from '@mui/x-charts';
import { ResponsiveChartContainer } from '@mui/x-charts/ResponsiveChartContainer';
import { LinePlot } from '@mui/x-charts/LineChart';
import { useDrawingArea } from '@mui/x-charts/hooks';

const StyledPath = styled('path')(({ theme }) => ({
fill: 'none',
Expand Down
10 changes: 3 additions & 7 deletions docs/data/charts/components/OriginDemo.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import * as React from 'react';
import { styled } from '@mui/material/styles';

import {
ResponsiveChartContainer,
LinePlot,
useDrawingArea,
useYScale,
useXScale,
} from '@mui/x-charts';
import { ResponsiveChartContainer } from '@mui/x-charts/ResponsiveChartContainer';
import { LinePlot } from '@mui/x-charts/LineChart';
import { useDrawingArea, useXScale, useYScale } from '@mui/x-charts/hooks';

const x = Array.from({ length: 21 }, (_, index) => -1 + 0.2 * index);
const linear = x.map((v) => -1 + v);
Expand Down
10 changes: 3 additions & 7 deletions docs/data/charts/components/OriginDemo.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import * as React from 'react';
import { styled } from '@mui/material/styles';
import { ScaleLinear } from 'd3-scale';
import {
ResponsiveChartContainer,
LinePlot,
useDrawingArea,
useYScale,
useXScale,
} from '@mui/x-charts';
import { ResponsiveChartContainer } from '@mui/x-charts/ResponsiveChartContainer';
import { LinePlot } from '@mui/x-charts/LineChart';
import { useDrawingArea, useXScale, useYScale } from '@mui/x-charts/hooks';

const x = Array.from({ length: 21 }, (_, index) => -1 + 0.2 * index);
const linear = x.map((v) => -1 + v);
Expand Down
11 changes: 4 additions & 7 deletions docs/data/charts/components/ScaleDemo.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import * as React from 'react';

import { styled } from '@mui/material/styles';
import {
ResponsiveChartContainer,
LinePlot,
ChartsYAxis,
useDrawingArea,
useYScale,
} from '@mui/x-charts';
import { ResponsiveChartContainer } from '@mui/x-charts/ResponsiveChartContainer';
import { LinePlot } from '@mui/x-charts/LineChart';
import { ChartsYAxis } from '@mui/x-charts/ChartsYAxis';
import { useDrawingArea, useYScale } from '@mui/x-charts/hooks';

const StyledPath = styled('path')(({ theme }) => ({
fill: 'none',
Expand Down
11 changes: 4 additions & 7 deletions docs/data/charts/components/ScaleDemo.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import * as React from 'react';
import { ScaleLinear } from 'd3-scale';
import { styled } from '@mui/material/styles';
import {
ResponsiveChartContainer,
LinePlot,
ChartsYAxis,
useDrawingArea,
useYScale,
} from '@mui/x-charts';
import { ResponsiveChartContainer } from '@mui/x-charts/ResponsiveChartContainer';
import { LinePlot } from '@mui/x-charts/LineChart';
import { ChartsYAxis } from '@mui/x-charts/ChartsYAxis';
import { useDrawingArea, useYScale } from '@mui/x-charts/hooks';

const StyledPath = styled('path')(({ theme }) => ({
fill: 'none',
Expand Down
2 changes: 1 addition & 1 deletion docs/data/charts/line-demo/LineChartWithReferenceLines.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { ChartContainer } from '@mui/x-charts/ChartContainer';
import { ChartsReferenceLine } from '@mui/x-charts';
import { ChartsReferenceLine } from '@mui/x-charts/ChartsReferenceLine';
import { LinePlot, MarkPlot } from '@mui/x-charts/LineChart';
import { ChartsXAxis } from '@mui/x-charts/ChartsXAxis';
import { ChartsYAxis } from '@mui/x-charts/ChartsYAxis';
Expand Down
2 changes: 1 addition & 1 deletion docs/data/charts/line-demo/LineChartWithReferenceLines.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { ChartContainer } from '@mui/x-charts/ChartContainer';
import { ChartsReferenceLine } from '@mui/x-charts';
import { ChartsReferenceLine } from '@mui/x-charts/ChartsReferenceLine';
import { LinePlot, MarkPlot } from '@mui/x-charts/LineChart';
import { ChartsXAxis } from '@mui/x-charts/ChartsXAxis';
import { ChartsYAxis } from '@mui/x-charts/ChartsYAxis';
Expand Down
2 changes: 1 addition & 1 deletion docs/data/charts/line-demo/TinyLineChart.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { ChartContainer } from '@mui/x-charts';
import { ChartContainer } from '@mui/x-charts/ChartContainer';
import {
LinePlot,
MarkPlot,
Expand Down
2 changes: 1 addition & 1 deletion docs/data/charts/line-demo/TinyLineChart.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { ChartContainer } from '@mui/x-charts';
import { ChartContainer } from '@mui/x-charts/ChartContainer';
import {
LinePlot,
MarkPlot,
Expand Down
2 changes: 1 addition & 1 deletion docs/data/charts/pie-demo/PieChartWithCustomizedLabel.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { DefaultizedPieValueType } from '@mui/x-charts';
import { DefaultizedPieValueType } from '@mui/x-charts/models';
import { PieChart, pieArcLabelClasses } from '@mui/x-charts/PieChart';

const data = [
Expand Down
2 changes: 1 addition & 1 deletion docs/data/charts/scatter-demo/MultipleYAxesScatterChart.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { ScatterChart } from '@mui/x-charts/ScatterChart';
import { axisClasses } from '@mui/x-charts';
import { axisClasses } from '@mui/x-charts/ChartsAxis';

const data1 = [
{ x: 100, y: 200, id: 1 },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { ScatterChart } from '@mui/x-charts/ScatterChart';
import { axisClasses } from '@mui/x-charts';
import { axisClasses } from '@mui/x-charts/ChartsAxis';

const data1 = [
{ x: 100, y: 200, id: 1 },
Expand Down
2 changes: 1 addition & 1 deletion docs/data/charts/scatter/ColorScale.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { ScatterChart } from '@mui/x-charts/ScatterChart';
import { ScatterValueType } from '@mui/x-charts';
import { ScatterValueType } from '@mui/x-charts/models';
import Stack from '@mui/material/Stack';
import TextField from '@mui/material/TextField';
import MenuItem from '@mui/material/MenuItem';
Expand Down
2 changes: 1 addition & 1 deletion docs/data/charts/styling/ColorTemplate.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { ScatterChart } from '@mui/x-charts/ScatterChart';
import { ScatterValueType } from '@mui/x-charts';
import { ScatterValueType } from '@mui/x-charts/models';
import Stack from '@mui/material/Stack';
import TextField from '@mui/material/TextField';
import MenuItem from '@mui/material/MenuItem';
Expand Down
2 changes: 1 addition & 1 deletion docs/data/charts/styling/MuiColorTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Brightness4Icon from '@mui/icons-material/Brightness4';
import Brightness7Icon from '@mui/icons-material/Brightness7';
import { Chance } from 'chance';
import { ScatterChart } from '@mui/x-charts/ScatterChart';
import { ScatterValueType } from '@mui/x-charts';
import { ScatterValueType } from '@mui/x-charts/models';
import {
blueberryTwilightPalette,
mangoFusionPalette,
Expand Down
2 changes: 1 addition & 1 deletion docs/data/charts/tooltip/AxisFormatter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { BarChart } from '@mui/x-charts/BarChart';
import { axisClasses } from '@mui/x-charts';
import { axisClasses } from '@mui/x-charts/ChartsAxis';

const dataset = [
{ name: 'Austria', code: 'AT', gdp: 471 },
Expand Down
2 changes: 1 addition & 1 deletion docs/data/charts/tooltip/AxisFormatter.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { BarChart, BarChartProps } from '@mui/x-charts/BarChart';
import { axisClasses } from '@mui/x-charts';
import { axisClasses } from '@mui/x-charts/ChartsAxis';

const dataset = [
{ name: 'Austria', code: 'AT', gdp: 471 },
Expand Down
2 changes: 1 addition & 1 deletion docs/data/charts/tooltip/ElementHighlights.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import TextField from '@mui/material/TextField';
import MenuItem from '@mui/material/MenuItem';
import ToggleButtonGroup from '@mui/material/ToggleButtonGroup';
import ToggleButton from '@mui/material/ToggleButton';
import { HighlightScope } from '@mui/x-charts';
import { HighlightScope } from '@mui/x-charts/context';
import { BarChart } from '@mui/x-charts/BarChart';
import { LineChart } from '@mui/x-charts/LineChart';
import { ScatterChart } from '@mui/x-charts/ScatterChart';
Expand Down
Loading
Loading