Skip to content

Commit 7e37183

Browse files
committed
front: add eslint rule to ban React.FC
1 parent 074ce44 commit 7e37183

File tree

16 files changed

+43
-48
lines changed

16 files changed

+43
-48
lines changed

front/.eslintrc

+4-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@
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+
"React.FunctionComponent": "Useless and has some drawbacks, see https://github.com/facebook/create-react-app/pull/8177",
55+
"React.FunctionalComponent": "Preact specific, useless and has some drawbacks, see https://github.com/facebook/create-react-app/pull/8177"
5356
}
5457
}
5558
],

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/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/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/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/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

front/src/applications/editor/tools/trackEdition/components/TrackEditionLeftPanel.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { useAppDispatch } from 'store';
2525

2626
import AttachedRangesItemsList from './AttachedRangesItemsList';
2727

28-
const TrackEditionLeftPanel: React.FC = () => {
28+
const TrackEditionLeftPanel = () => {
2929
const dispatch = useAppDispatch();
3030
const { t } = useTranslation();
3131
const infraID = useInfraID();

front/src/common/Map/Buttons/ButtonMapInfraErrors.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ interface ButtonMapInfraErrorsProps {
1212
editorState: EditorState;
1313
}
1414

15-
const ButtonMapInfraErrors: React.FC<ButtonMapInfraErrorsProps> = ({ editorState }) => {
15+
const ButtonMapInfraErrors = ({ editorState }: ButtonMapInfraErrorsProps) => {
1616
const dispatch = useAppDispatch();
1717
const { t } = useTranslation('translation');
1818
const [isActive, setIsActive] = useState(true);

front/src/common/Map/MapModalHeader.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ type MapModalHeaderProps = {
88
textLight?: boolean;
99
};
1010

11-
const MapModalHeader: React.FC<MapModalHeaderProps> = ({ closeAction, title, textLight }) => (
11+
const MapModalHeader = ({ closeAction, title, textLight }: MapModalHeaderProps) => (
1212
<div className="d-flex justify-content-between align-items-start">
1313
<div className={cx('h2', { 'text-light': textLight })}>{title}</div>
1414
<button

front/src/modules/rollingStock/components/RollingStock2Img.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ import type {
1010
RollingStockWithLiveries,
1111
} from 'common/api/osrdEditoastApi';
1212

13-
const RollingStock2Img: React.FC<{
13+
type RollingStock2ImgProps = {
1414
rollingStock: RollingStockWithLiveries | LightRollingStockWithLiveries;
15-
}> = ({ rollingStock }) => {
15+
};
16+
17+
const RollingStock2Img = ({ rollingStock }: RollingStock2ImgProps) => {
1618
// as the image is stored in the database and can be fetched only through api (authentication needed),
1719
// the direct url can not be given to the <img /> directly. Thus the image is fetched, and a new
1820
// url is generated and stored in imageUrl (then used in <img />).

front/src/stories/IntervalsEditor.stories.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ type IntervalsEditorProps = {
3434
units: string[];
3535
};
3636

37-
const IntervalsEditorWrapper: React.FC<IntervalsEditorProps> = (props) => {
37+
const IntervalsEditorWrapper = (props: IntervalsEditorProps) => {
3838
const { data, intervalType, selectOptions, totalLength, units = [] } = props;
3939
const [persistedData, setData] = useState<IntervalItem[]>(
4040
fixLinearMetadataItems(data.filter(notEmpty), totalLength)

0 commit comments

Comments
 (0)