Skip to content

Commit 311a706

Browse files
committed
[IGNORE] eslint: upgrade deps + enable experimental react-hooks rules
Signed-off-by: Guillaume LADORME <Gladorme@users.noreply.github.com>
1 parent abc66ca commit 311a706

File tree

43 files changed

+374
-210
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+374
-210
lines changed

.eslintrc.js

Lines changed: 56 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111
// See the License for the specific language governing permissions and
1212
// limitations under the License.
1313

14+
// Base eslint configuration for typescript projects
1415
module.exports = {
1516
extends: [
1617
'eslint:recommended',
1718
'plugin:react/recommended',
18-
'plugin:react-hooks/recommended',
19+
'plugin:react-hooks/recommended-legacy',
1920
'plugin:jsx-a11y/recommended',
2021
'plugin:@typescript-eslint/recommended',
2122
'plugin:prettier/recommended',
@@ -48,30 +49,73 @@ module.exports = {
4849
},
4950

5051
rules: {
51-
'prettier/prettier': 'error',
52-
'@typescript-eslint/explicit-function-return-type': 'off',
53-
'@typescript-eslint/explicit-module-boundary-types': 'off',
52+
'@typescript-eslint/explicit-function-return-type': 'error',
53+
'@typescript-eslint/explicit-module-boundary-types': 'error',
5454
'@typescript-eslint/array-type': [
5555
'error',
5656
{
5757
default: 'array-simple',
5858
},
5959
],
60-
'import/order': 'error',
60+
'@typescript-eslint/no-unused-vars': [
61+
'error',
62+
{
63+
argsIgnorePattern: '^_',
64+
varsIgnorePattern: '^_',
65+
caughtErrorsIgnorePattern: '^_',
66+
},
67+
],
6168
// you must disable the base rule as it can report incorrect errors
6269
'no-unused-vars': 'off',
63-
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
6470

65-
'react/prop-types': 'off',
66-
'react-hooks/exhaustive-deps': 'error',
67-
// Not necessary in React 17
68-
'react/react-in-jsx-scope': 'off',
69-
'react/jsx-curly-brace-presence': ['error', { props: 'never', children: 'never', propElementValues: 'always' }],
71+
'prettier/prettier': 'error',
72+
73+
eqeqeq: ['error', 'always'],
7074

7175
// We use this rule instead of the core eslint `no-duplicate-imports`
7276
// because it avoids false errors on cases where we have a regular
73-
// import and an `import type`.
77+
// import and an `import type`
7478
'import/no-duplicates': 'error',
79+
'import/order': 'error',
80+
81+
// Not necessary in React 17
82+
'react/react-in-jsx-scope': 'off',
83+
'react/jsx-curly-brace-presence': ['error', { props: 'never', children: 'never', propElementValues: 'always' }],
84+
'react-hooks/exhaustive-deps': 'error',
85+
'react-hooks/error-boundaries': 'error',
86+
'react-hooks/globals': 'error',
87+
'react-hooks/immutability': 'error',
88+
'react-hooks/purity': 'error',
89+
'react-hooks/refs': 'error',
90+
'react-hooks/set-state-in-effect': 'error',
91+
'react-hooks/set-state-in-render': 'error',
92+
'react-hooks/static-components': 'error',
93+
'react-hooks/unsupported-syntax': 'error',
94+
'react-hooks/use-memo': 'error',
95+
96+
'no-restricted-imports': [
97+
'error',
98+
{
99+
patterns: [
100+
{
101+
/**
102+
* This library is gigantic and named imports end up slowing down builds/blowing out bundle sizes,
103+
* so this prevents that style of import.
104+
*/
105+
group: ['mdi-material-ui', '!mdi-material-ui/'],
106+
message: `
107+
Please use the default import from the icon file directly rather than using a named import.
108+
109+
Good:
110+
import IconName from 'mdi-material-ui/IconName';
111+
112+
Bad:
113+
import { IconName } from 'mdi-material-ui';
114+
`,
115+
},
116+
],
117+
},
118+
],
75119
},
76120

77121
ignorePatterns: ['**/dist'],

barchart/src/BarChartBase.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { GridComponent, DatasetComponent, TitleComponent, TooltipComponent } fro
2020
import { CanvasRenderer } from 'echarts/renderers';
2121
import { Box } from '@mui/material';
2222

23+
// eslint-disable-next-line react-hooks/rules-of-hooks
2324
use([EChartsBarChart, GridComponent, DatasetComponent, TitleComponent, TooltipComponent, CanvasRenderer]);
2425

2526
const BAR_WIN_WIDTH = 14;
@@ -120,7 +121,7 @@ export function BarChartBase(props: BarChartBaseProps): ReactElement {
120121
sx={{ overflow: 'auto' }}
121122
>
122123
<EChart
123-
sx={{
124+
style={{
124125
minHeight: height,
125126
height: data ? data.length * (BAR_WIN_WIDTH + BAR_GAP) : '100%',
126127
}}

datasourcevariable/src/DatasourceVariable.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313

1414
import { OptionsEditorProps, useListPluginMetadata, VariablePlugin } from '@perses-dev/plugin-system';
1515
import { Autocomplete, TextField } from '@mui/material';
16-
import { useEffect, useMemo } from 'react';
16+
import { ReactElement, useEffect, useMemo } from 'react';
1717

1818
type StaticListVariableOptions = {
1919
datasourcePluginKind: string;
2020
};
2121

2222
const EMPTY_SELECTED_KIND = { label: '', value: '' };
2323

24-
export const DatasourceVariableOptionEditor = (props: OptionsEditorProps<StaticListVariableOptions>) => {
24+
export const DatasourceVariableOptionEditor = (props: OptionsEditorProps<StaticListVariableOptions>): ReactElement => {
2525
const { onChange, value } = props;
2626
const { datasourcePluginKind } = value;
2727
const { data: datasourcePlugins } = useListPluginMetadata(['Datasource']);

flamechart/src/components/CustomBreadcrumb.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const StyledBreadcrumb = styled(Chip)(({ theme }) => {
4747
export function CustomBreadcrumb(props: CustomBreadcrumbProps): ReactElement {
4848
const { totalValue, totalSample, otherItemSample, onSelectedIdChange } = props;
4949

50-
const handleClick = (event: React.MouseEvent<Element, MouseEvent>) => {
50+
const handleClick = (event: React.MouseEvent<Element, MouseEvent>): void => {
5151
event.preventDefault();
5252
onSelectedIdChange(0);
5353
};

flamechart/src/components/FlameChart.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ export function FlameChart(props: FlameChartProps): ReactElement {
220220
const flameChart = useMemo(
221221
() => (
222222
<EChart
223-
sx={{
223+
style={{
224224
width: width,
225225
height: height - 2 * CONTAINER_PADDING - BREADCRUMB_SPACE,
226226
}}

flamechart/src/components/FlameChartPanel.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ export const FlameChartPanel: FC<FlameChartPanelProps> = (props) => {
4444

4545
// keep liveSpec up to date
4646
useEffect(() => {
47+
// TODO: improve this logic to avoid useState in useEffect
48+
// eslint-disable-next-line react-hooks/set-state-in-effect
4749
setLiveSpec(spec);
4850
setSelectedId(0);
4951
setSearchValue('');
@@ -68,13 +70,13 @@ export const FlameChartPanel: FC<FlameChartPanelProps> = (props) => {
6870

6971
const noDataTextStyle = (chartsTheme.noDataOption.title as TitleComponentOption).textStyle as SxProps;
7072

71-
const onChangePalette = (newPalette: 'package-name' | 'value') => {
73+
const onChangePalette = (newPalette: 'package-name' | 'value'): void => {
7274
setLiveSpec((prev) => {
7375
return { ...prev, palette: newPalette };
7476
});
7577
};
7678

77-
const onDisplayChange = (value: 'table' | 'flame-graph' | 'both' | 'none') => {
79+
const onDisplayChange = (value: 'table' | 'flame-graph' | 'both' | 'none'): void => {
7880
let showTable = true;
7981
let showFlameGraph = true;
8082
if (value === 'table') {

flamechart/src/components/Settings.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,27 +39,27 @@ export function Settings(props: SettingsProps): ReactElement {
3939
minWidth: 'auto',
4040
};
4141

42-
const handleChangeColorShemeClick = (event: React.MouseEvent<HTMLElement>) => {
42+
const handleChangeColorShemeClick = (event: React.MouseEvent<HTMLElement>): void => {
4343
setAnchorEl(event.currentTarget);
4444
};
4545

46-
const handleByPackageNameClick = () => {
46+
const handleByPackageNameClick = (): void => {
4747
onChangePalette('package-name');
4848
handleClose();
4949
};
5050

51-
const handleByValueClick = () => {
51+
const handleByValueClick = (): void => {
5252
onChangePalette('value');
5353
handleClose();
5454
};
5555

56-
const handleClose = () => {
56+
const handleClose = (): void => {
5757
setAnchorEl(null);
5858
};
5959

60-
const isTableSelected = () => selectedView === 'table';
61-
const isFlameGraphSelected = () => selectedView === 'flame-graph';
62-
const isBothSelected = () => selectedView === 'both';
60+
const isTableSelected = (): boolean => selectedView === 'table';
61+
const isFlameGraphSelected = (): boolean => selectedView === 'flame-graph';
62+
const isBothSelected = (): boolean => selectedView === 'both';
6363

6464
// Update selected view based on the value of showTable and showFlameGraph
6565
const selectedView: 'table' | 'flame-graph' | 'both' | 'none' = useMemo(() => {

flamechart/src/components/TableChart.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export function TableChart(props: TableChartProps): ReactElement {
5858
align: 'left',
5959
enableSorting: true,
6060
width: 0.5 * availableWidth,
61-
cell: (ctx) => {
61+
cell: (ctx): ReactElement => {
6262
const cellValue = ctx.getValue();
6363
return (
6464
<Link
@@ -84,7 +84,7 @@ export function TableChart(props: TableChartProps): ReactElement {
8484
align: 'right',
8585
enableSorting: true,
8686
width: 0.25 * availableWidth - SCROLL_BAR_WIDTH,
87-
cell: (ctx) => {
87+
cell: (ctx): string => {
8888
const cellValue = ctx.getValue();
8989
return formatItemValue(unit, cellValue);
9090
},
@@ -96,7 +96,7 @@ export function TableChart(props: TableChartProps): ReactElement {
9696
align: 'right',
9797
enableSorting: true,
9898
width: 0.25 * availableWidth,
99-
cell: (ctx) => {
99+
cell: (ctx): string => {
100100
const cellValue = ctx.getValue();
101101
return formatItemValue(unit, cellValue);
102102
},

flamechart/src/utils/data-transform.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { filterStackTraceById, buildSamples } from './data-transform';
1717
import { getSpanColor } from './palette-gen';
1818

1919
// define the structuredClone function
20-
global.structuredClone = (val) => JSON.parse(JSON.stringify(val));
20+
global.structuredClone = (val): unknown => JSON.parse(JSON.stringify(val));
2121

2222
describe('filterStackTraceById', () => {
2323
const emptyJson: StackTrace = {} as StackTrace;

gaugechart/src/GaugeChartBase.tsx

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@
1212
// limitations under the License.
1313

1414
import { EChart, useChartsTheme } from '@perses-dev/components';
15-
import { formatValue, useDeepMemo, FormatOptions } from '@perses-dev/core';
15+
import { formatValue, FormatOptions } from '@perses-dev/core';
1616
import { use, EChartsCoreOption } from 'echarts/core';
1717
import { GaugeChart as EChartsGaugeChart, GaugeSeriesOption } from 'echarts/charts';
1818
import { GridComponent, TitleComponent, TooltipComponent } from 'echarts/components';
1919
import { CanvasRenderer } from 'echarts/renderers';
20-
import { ReactElement } from 'react';
20+
import { ReactElement, useMemo } from 'react';
2121

22+
// eslint-disable-next-line react-hooks/rules-of-hooks
2223
use([EChartsGaugeChart, GridComponent, TitleComponent, TooltipComponent, CanvasRenderer]);
2324

2425
// adjusts when to show pointer icon
@@ -48,7 +49,7 @@ export function GaugeChartBase(props: GaugeChartBaseProps): ReactElement {
4849
const chartsTheme = useChartsTheme();
4950

5051
// useDeepMemo ensures value size util does not rerun everytime you hover on the chart
51-
const option: EChartsCoreOption = useDeepMemo(() => {
52+
const option: EChartsCoreOption = useMemo(() => {
5253
if (data.value === undefined) return chartsTheme.noDataOption;
5354

5455
// Base configuration shared by both series (= progress & scale)
@@ -168,13 +169,27 @@ export function GaugeChartBase(props: GaugeChartBaseProps): ReactElement {
168169
},
169170
],
170171
};
171-
}, [data, width, height, chartsTheme, format, axisLine, max, valueFontSize, progressWidth, titleFontSize]);
172+
}, [
173+
axisLine,
174+
chartsTheme.echartsTheme.textStyle?.color,
175+
chartsTheme.noDataOption,
176+
data.label,
177+
data.value,
178+
format,
179+
max,
180+
progressWidth,
181+
titleFontSize,
182+
valueFontSize,
183+
width,
184+
]);
172185

173186
return (
174187
<EChart
175-
sx={{
188+
style={{
176189
width: width,
177190
height: height,
191+
}}
192+
sx={{
178193
padding: `${chartsTheme.container.padding.default}px`,
179194
}}
180195
option={option}

0 commit comments

Comments
 (0)