Skip to content

Commit 9655fc9

Browse files
claraniemersion
andcommitted
front: add eslint rule to ban React.FC
Co-authored-by: Simon Ser <[email protected]>
1 parent 074ce44 commit 9655fc9

File tree

70 files changed

+230
-221
lines changed

Some content is hidden

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

70 files changed

+230
-221
lines changed

front/.eslintrc

+5-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@
4949
"LegacyFilterSpecification": {
5050
"message": "Use ExpressionFilterSpecification instead",
5151
"fixWith": "ExpressionFilterSpecification"
52-
}
52+
},
53+
"React.FC": "Useless and has some drawbacks, see https://github.com/facebook/create-react-app/pull/8177",
54+
"FC": "Useless and has some drawbacks, see https://github.com/facebook/create-react-app/pull/8177",
55+
"React.FunctionComponent": "Useless and has some drawbacks, see https://github.com/facebook/create-react-app/pull/8177",
56+
"React.FunctionalComponent": "Preact specific, useless and has some drawbacks, see https://github.com/facebook/create-react-app/pull/8177"
5357
}
5458
}
5559
],

front/src/applications/editor/components/EntityError.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { type FC, useMemo } from 'react';
1+
import React, { useMemo } from 'react';
22

33
import cx from 'classnames';
44
import { isNil, uniqueId } from 'lodash';
@@ -11,7 +11,7 @@ import { useInfraID } from 'common/osrdContext';
1111

1212
import { InfraErrorLine } from './InfraErrors';
1313

14-
const EntityError: FC<{ entity: EditorEntity; className?: string }> = ({ entity, className }) => {
14+
const EntityError = ({ entity, className }: { entity: EditorEntity; className?: string }) => {
1515
const { t } = useTranslation();
1616
const infraID = useInfraID();
1717
const { data } = osrdEditoastApi.endpoints.getInfraByInfraIdErrors.useQuery(

front/src/applications/editor/components/EntitySumUp.tsx

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { type FC, useEffect, useState, Fragment } from 'react';
1+
import React, { useEffect, useState, Fragment } from 'react';
22

33
import cx from 'classnames';
44
import type { TFunction } from 'i18next';
@@ -299,16 +299,16 @@ function getSumUpContent(
299299
);
300300
}
301301

302-
const EntitySumUp: FC<
303-
{
304-
classes?: Partial<typeof DEFAULT_CLASSES>;
305-
status?: string;
306-
error?: InfraError;
307-
} & (
308-
| { entity: EditorEntity; id?: undefined; objType?: undefined }
309-
| { id: string; objType: EditoastType; entity?: undefined }
310-
)
311-
> = ({ entity, id, objType, classes, status, error }) => {
302+
type EntitySumUpProps = {
303+
classes?: Partial<typeof DEFAULT_CLASSES>;
304+
status?: string;
305+
error?: InfraError;
306+
} & (
307+
| { entity: EditorEntity; id?: undefined; objType?: undefined }
308+
| { id: string; objType: EditoastType; entity?: undefined }
309+
);
310+
311+
const EntitySumUp = ({ entity, id, objType, classes, status, error }: EntitySumUpProps) => {
312312
const dispatch = useAppDispatch();
313313
const { t } = useTranslation();
314314
const infraID = useInfraID();

front/src/applications/editor/components/ForceRemount.tsx

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import React, { type FC, type ReactNode, useEffect, useState } from 'react';
1+
import React, { type ReactNode, useEffect, useState } from 'react';
22

3-
const ForceRemount: FC<{ fingerprint: string; renderChildren: () => ReactNode }> = ({
4-
fingerprint,
5-
renderChildren,
6-
}) => {
3+
type ForceRemountProps = { fingerprint: string; renderChildren: () => ReactNode };
4+
5+
const ForceRemount = ({ fingerprint, renderChildren }: ForceRemountProps) => {
76
const [skipRender, setSkipRender] = useState(false);
87

98
useEffect(() => {

front/src/applications/editor/components/InfraErrors/InfraError.tsx

+4-6
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,13 @@ import InfraErrorDescription from './InfraErrorDescription';
88
import InfraErrorIcon from './InfraErrorIcon';
99
import InfraErrorTypeLabel from './InfraErrorTypeLabel';
1010

11+
type InfraErrorBoxProps = PropsWithChildren<{ error: InfraError; index?: number }>;
12+
1113
/**
1214
* A component that display an infra error.
1315
* If index is provided, we display it with `#` on the left
1416
*/
15-
export const InfraErrorBox: React.FC<PropsWithChildren<{ error: InfraError; index?: number }>> = ({
16-
error,
17-
index,
18-
children,
19-
}) => (
17+
export const InfraErrorBox = ({ error, index, children }: InfraErrorBoxProps) => (
2018
<div className="management-item-content">
2119
<div className="management-item-symbol">
2220
<InfraErrorIcon error={error} />
@@ -34,7 +32,7 @@ export const InfraErrorBox: React.FC<PropsWithChildren<{ error: InfraError; inde
3432
</div>
3533
);
3634

37-
export const InfraErrorLine: React.FC<{ error: InfraError }> = ({ error }) => (
35+
export const InfraErrorLine = ({ error }: { error: InfraError }) => (
3836
<div>
3937
<span className={cx('font-weight-bold', error.is_warning ? 'text-warning' : 'text-danger')}>
4038
<InfraErrorTypeLabel error={error} />

front/src/applications/editor/components/InfraErrors/InfraErrorDescription.tsx

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
import type React from 'react';
2-
31
import { useTranslation } from 'react-i18next';
42

53
import type { InfraError } from 'common/api/osrdEditoastApi';
64

75
/**
86
* A component that display an infra error description.
97
*/
10-
const InfraErrorDescription: React.FC<{ error: InfraError }> = ({ error }) => {
8+
const InfraErrorDescription = ({ error }: { error: InfraError }) => {
119
const { t } = useTranslation();
1210
const i18nKey = `Editor.infra-errors.error-type.${error.error_type}.description`;
1311
return t(i18nKey, error);

front/src/applications/editor/components/InfraErrors/InfraErrorIcon.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { type FC } from 'react';
1+
import React from 'react';
22

33
import cx from 'classnames';
44
import type { IconBaseProps } from 'react-icons';
@@ -12,7 +12,7 @@ import type { InfraError } from 'common/api/osrdEditoastApi';
1212
interface InfraErrorIconProps extends IconBaseProps {
1313
error: InfraError;
1414
}
15-
const InfraErrorIcon: FC<InfraErrorIconProps> = ({ error, ...props }) =>
15+
const InfraErrorIcon = ({ error, ...props }: InfraErrorIconProps) =>
1616
error.is_warning ? (
1717
<BsFillExclamationTriangleFill {...props} className={cx('text-warning', props.className)} />
1818
) : (

front/src/applications/editor/components/InfraErrors/InfraErrorMapControl.tsx

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { type FC, useCallback, useEffect } from 'react';
1+
import React, { useCallback, useEffect } from 'react';
22

33
import { Alert } from '@osrd-project/ui-icons';
44
import { useTranslation } from 'react-i18next';
@@ -16,10 +16,12 @@ import useKeyboardShortcuts from 'utils/hooks/useKeyboardShortcuts';
1616

1717
import InfraErrorsModal from './InfraErrorsModal';
1818

19-
const InfraErrorMapControl: FC<{
19+
type InfraErrorMapControlProps = {
2020
mapRef: MapRef;
2121
switchTool: EditorContextType['switchTool'];
22-
}> = ({ mapRef, switchTool }) => {
22+
};
23+
24+
const InfraErrorMapControl = ({ mapRef, switchTool }: InfraErrorMapControlProps) => {
2325
const dispatch = useAppDispatch();
2426
const { t } = useTranslation();
2527
const { register } = useKeyboardShortcuts();

front/src/applications/editor/components/InfraErrors/InfraErrorTypeLabel.tsx

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
import type React from 'react';
2-
31
import { useTranslation } from 'react-i18next';
42

53
import type { InfraError } from 'common/api/osrdEditoastApi';
64

75
/**
86
* A component that display an infra error type label.
97
*/
10-
const InfraErrorTypeLabel: React.FC<{ error: InfraError }> = ({ error }) => {
8+
const InfraErrorTypeLabel = ({ error }: { error: InfraError }) => {
119
const { t } = useTranslation();
1210
return t(`Editor.infra-errors.error-type.${error.error_type}.name`);
1311
};

front/src/applications/editor/components/InfraErrors/InfraErrorsList.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ interface InfraErrorsListProps {
2929
onErrorClick: (infraId: number, item: InfraError) => void | Promise<void>;
3030
}
3131

32-
const InfraErrorsList: React.FC<InfraErrorsListProps> = ({ infraID, onErrorClick }) => {
32+
const InfraErrorsList = ({ infraID, onErrorClick }: InfraErrorsListProps) => {
3333
const { t } = useTranslation();
3434
const dispatch = useAppDispatch();
3535
const [total, setTotal] = useState<number | null>(null);

front/src/applications/editor/components/InfraErrors/InfraErrorsModal.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { type FC } from 'react';
1+
import React from 'react';
22

33
import { useTranslation } from 'react-i18next';
44

@@ -12,7 +12,7 @@ interface InfraErrorsModalProps {
1212
onErrorClick: (infraId: number, item: InfraError) => void | Promise<void>;
1313
}
1414

15-
const InfraErrorsModal: FC<InfraErrorsModalProps> = ({ onErrorClick }) => {
15+
const InfraErrorsModal = ({ onErrorClick }: InfraErrorsModalProps) => {
1616
const { t } = useTranslation();
1717
const infraID = useInfraID();
1818

front/src/applications/editor/components/LayersModal.tsx

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { type FC, useEffect, useMemo, useState } from 'react';
1+
import React, { useEffect, useMemo, useState } from 'react';
22

33
import {
44
groupBy,
@@ -70,12 +70,7 @@ type LayersModalProps = {
7070
onChange: (args: { newLayers: Set<Layer> }) => void;
7171
};
7272

73-
const LayersModal: FC<LayersModalProps> = ({
74-
initialLayers,
75-
selection,
76-
frozenLayers,
77-
onChange,
78-
}) => {
73+
const LayersModal = ({ initialLayers, selection, frozenLayers, onChange }: LayersModalProps) => {
7974
const dispatch = useAppDispatch();
8075
const { t } = useTranslation();
8176
const { layersSettings } = useSelector(getMap);

front/src/applications/editor/components/LinearMetadata/FormBeginEndWidget.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22

33
import type { WidgetProps } from '@rjsf/utils';
44

5-
export const FormBeginEndWidget: React.FC<WidgetProps> = (props) => {
5+
export const FormBeginEndWidget = (props: WidgetProps) => {
66
const { id, value, required, readonly, onChange, options, schema } = props;
77
return (
88
<div>
@@ -24,4 +24,5 @@ export const FormBeginEndWidget: React.FC<WidgetProps> = (props) => {
2424
</div>
2525
);
2626
};
27+
2728
export default FormBeginEndWidget;

front/src/applications/editor/components/LinearMetadata/FormComponent.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import HelpModal from './HelpModal';
3434
import { LinearMetadataTooltip } from './tooltip';
3535
import 'common/IntervalsDataViz/style.scss';
3636

37-
const IntervalEditorComponent: React.FC<FieldProps> = (props) => {
37+
const IntervalEditorComponent = (props: FieldProps) => {
3838
const { name, formContext, formData, schema, onChange, registry } = props;
3939
const { openModal, closeModal } = useModal();
4040
const { t } = useTranslation();
@@ -414,7 +414,7 @@ const IntervalEditorComponent: React.FC<FieldProps> = (props) => {
414414
);
415415
};
416416

417-
export const FormComponent: React.FC<FieldProps> = (props) => {
417+
export const FormComponent = (props: FieldProps) => {
418418
const { name, formContext, schema, registry } = props;
419419
const Fields = getDefaultRegistry().fields;
420420

front/src/applications/editor/components/LinearMetadata/FormLineStringLength.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ import cx from 'classnames';
55
import { toNumber } from 'lodash';
66
import { useTranslation } from 'react-i18next';
77

8-
export const FormLineStringLength: React.FC<WidgetProps> = (props) => {
8+
export const FormLineStringLength = ({ id, value, required, onChange }: WidgetProps) => {
99
const { t } = useTranslation();
10-
const { id, value, required, onChange } = props;
1110

1211
const [length, setLength] = useState<number>(toNumber(value));
1312

front/src/applications/editor/components/LinearMetadata/HelpModal.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import React, { type FC } from 'react';
1+
import React from 'react';
22

33
import { useTranslation } from 'react-i18next';
44

55
import { Modal } from 'common/BootstrapSNCF/ModalSNCF';
66

7-
const HelpModal: FC = () => {
7+
const HelpModal = () => {
88
const { t } = useTranslation();
99

1010
return (

front/src/applications/editor/tools/pointEdition/components/CustomFlagSignalCheckbox.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import React from 'react';
22

33
import type { WidgetProps } from '@rjsf/utils';
44

5-
const CustomFlagSignalCheckbox: React.FC<WidgetProps> = (props) => {
6-
const { schema, onChange, title, value } = props;
5+
const CustomFlagSignalCheckbox = ({ schema, onChange, title, value }: WidgetProps) => {
76
const FLAG_NAME = 'flag-signal-parameter';
87

98
return (

front/src/applications/editor/tools/pointEdition/components/CustomPosition.tsx

+16-19
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,22 @@ import type { WidgetProps } from '@rjsf/utils';
44

55
import InputSNCF from 'common/BootstrapSNCF/InputSNCF';
66

7-
const CustomPosition: React.FC<WidgetProps> = (props) => {
8-
const { schema, onChange, title, value } = props;
9-
const POINT_NAME = 'point-parameter';
7+
const POINT_NAME = 'point-parameter';
108

11-
return (
12-
<div key={`${POINT_NAME}-${schema.description}`}>
13-
<p>{title}</p>
14-
<InputSNCF
15-
name={POINT_NAME}
16-
id={`${POINT_NAME}-${schema.description}`}
17-
value={value}
18-
onChange={(e) => {
19-
onChange(e.target.value);
20-
}}
21-
type="number"
22-
min={0}
23-
/>
24-
</div>
25-
);
26-
};
9+
const CustomPosition = ({ schema, onChange, title, value }: WidgetProps) => (
10+
<div key={`${POINT_NAME}-${schema.description}`}>
11+
<p>{title}</p>
12+
<InputSNCF
13+
name={POINT_NAME}
14+
id={`${POINT_NAME}-${schema.description}`}
15+
value={value}
16+
onChange={(e) => {
17+
onChange(e.target.value);
18+
}}
19+
type="number"
20+
min={0}
21+
/>
22+
</div>
23+
);
2724

2825
export default CustomPosition;

front/src/applications/editor/tools/rangeEdition/speedSection/SpeedInput.tsx

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { type FC, type InputHTMLAttributes, useEffect, useState } from 'react';
1+
import React, { type InputHTMLAttributes, useEffect, useState } from 'react';
22

33
import { isNumber } from 'lodash';
44

@@ -8,12 +8,12 @@ function msToKmhString(msSpeed: number | undefined): string {
88
return isNumber(msSpeed) ? msToKmh(msSpeed).toFixed(2) : '';
99
}
1010

11-
const SpeedInput: FC<
12-
{
13-
msSpeed: number | undefined;
14-
onChange: (newMsSpeed: number | undefined) => void;
15-
} & Omit<InputHTMLAttributes<HTMLInputElement>, 'value' | 'onChange' | 'type'>
16-
> = ({ msSpeed, onChange, ...attrs }) => {
11+
type SpeedInputProps = {
12+
msSpeed: number | undefined;
13+
onChange: (newMsSpeed: number | undefined) => void;
14+
} & Omit<InputHTMLAttributes<HTMLInputElement>, 'value' | 'onChange' | 'type'>;
15+
16+
const SpeedInput = ({ msSpeed, onChange, ...attrs }: SpeedInputProps) => {
1717
const [kmhSpeed, setKmhSpeed] = useState<string>(msToKmhString(msSpeed));
1818

1919
useEffect(() => {

front/src/applications/editor/tools/rangeEdition/speedSection/SpeedSectionMetadataForm.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { type FC, useContext, useEffect, useState } from 'react';
1+
import React, { useContext, useEffect, useState } from 'react';
22

33
import { cloneDeep, isEmpty, isEqual, map, size } from 'lodash';
44
import { useTranslation } from 'react-i18next';
@@ -32,7 +32,7 @@ const getNewSpeedLimitTag = (
3232

3333
type SpeedSectionMetadataFormProps = { speedLimitTags: string[] };
3434

35-
const SpeedSectionMetadataForm: FC<SpeedSectionMetadataFormProps> = ({ speedLimitTags }) => {
35+
const SpeedSectionMetadataForm = ({ speedLimitTags }: SpeedSectionMetadataFormProps) => {
3636
const { t } = useTranslation();
3737
const {
3838
state: { entity, error },

front/src/applications/editor/tools/rangeEdition/speedSection/SwitchList.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ type SwitchListProps = {
2626
availableSwitchesPositions: AvailableSwitchPositions;
2727
};
2828

29-
const SwitchList: React.FC<SwitchListProps> = ({
29+
const SwitchList = ({
3030
selectedSwitches,
3131
unselectSwitch,
3232
setSwitchSelection,
3333
/** possible positions based on the routes found */
3434
availableSwitchesPositions,
35-
}) => {
35+
}: SwitchListProps) => {
3636
const infraID = useInfraID();
3737
const { data: switchTypes } = useSwitchTypes(infraID);
3838

0 commit comments

Comments
 (0)