Skip to content

Commit fbf8e3e

Browse files
committed
front: enable @typescript-eslint/no-unsafe-return
Part of #8772 See https://typescript-eslint.io/rules/no-unsafe-return/
1 parent e50b41a commit fbf8e3e

File tree

6 files changed

+22
-11
lines changed

6 files changed

+22
-11
lines changed

front/.eslintrc

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"@typescript-eslint/no-shadow": "error",
4545
"@typescript-eslint/no-use-before-define": "error",
4646
"@typescript-eslint/no-unnecessary-type-assertion": "error",
47+
"@typescript-eslint/no-unsafe-return": "error",
4748

4849
"@typescript-eslint/ban-types": [
4950
"error",

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

+15-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { useState, useRef, useEffect, useCallback, useMemo } from 'react';
22

33
import Form, { getDefaultRegistry } from '@rjsf/core';
4-
import type { FieldProps } from '@rjsf/utils';
4+
import type { FieldProps, RJSFSchema } from '@rjsf/utils';
55
import validator from '@rjsf/validator-ajv8';
6+
import type { GeoJsonProperties, Geometry } from 'geojson';
67
import type { JSONSchema7 } from 'json-schema';
78
import { omit, head, max as fnMax, min as fnMin, isNil } from 'lodash';
89
import { useTranslation } from 'react-i18next';
@@ -34,7 +35,13 @@ import HelpModal from './HelpModal';
3435
import { LinearMetadataTooltip } from './tooltip';
3536
import 'common/IntervalsDataViz/style.scss';
3637

37-
const IntervalEditorComponent = (props: FieldProps) => {
38+
export type FormContext = {
39+
geometry: Geometry;
40+
length: number;
41+
isCreation: boolean;
42+
};
43+
44+
const IntervalEditorComponent = (props: FieldProps<GeoJsonProperties, RJSFSchema, FormContext>) => {
3845
const { name, formContext, formData, schema, onChange, registry } = props;
3946
const { openModal, closeModal } = useModal();
4047
const { t } = useTranslation();
@@ -59,10 +66,10 @@ const IntervalEditorComponent = (props: FieldProps) => {
5966

6067
// Get the distance of the geometry
6168
const distance = useMemo(() => {
62-
if (!isNil(formContext.length)) {
69+
if (!isNil(formContext?.length)) {
6370
return formContext.length;
6471
}
65-
if (formContext.geometry?.type === 'LineString') {
72+
if (formContext?.geometry?.type === 'LineString') {
6673
return getLineStringDistance(formContext.geometry);
6774
}
6875
return 0;
@@ -414,16 +421,16 @@ const IntervalEditorComponent = (props: FieldProps) => {
414421
);
415422
};
416423

417-
export const FormComponent = (props: FieldProps) => {
424+
export const FormComponent = (props: FieldProps<GeoJsonProperties, RJSFSchema, FormContext>) => {
418425
const { name, formContext, schema, registry } = props;
419426
const Fields = getDefaultRegistry().fields;
420427

421428
// Get the distance of the geometry
422429
const distance = useMemo(() => {
423-
if (!isNil(formContext.length)) {
424-
return formContext.length!;
430+
if (!isNil(formContext?.length)) {
431+
return formContext.length;
425432
}
426-
if (formContext.geometry?.type === 'LineString') {
433+
if (formContext?.geometry?.type === 'LineString') {
427434
return getLineStringDistance(formContext.geometry);
428435
}
429436
return 0;

front/src/applications/editor/data/utils.ts

+1
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ export function nestEntity(entity: EditorEntity, type: EditoastType): EditorEnti
134134

135135
if (isLast) props[k] = oldProperties[key];
136136
else props[k] = props[k] || {};
137+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
137138
return props[k];
138139
}, newProperties);
139140
});

front/src/common/Map/Layers/GeoJSONs.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ interface EditorSourceProps {
418418
export const EditorSource = ({ id, data, layers, layerOrder }: EditorSourceProps) => {
419419
const dataFingerPrint =
420420
data.type === 'FeatureCollection'
421-
? data.features.map((f) => f.properties?.id).concat()
421+
? data.features.map((f) => f.properties?.id as unknown).concat()
422422
: data.properties?.id;
423423
return (
424424
<Source type="geojson" id={id} data={data}>

front/src/common/api/documentApi.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { NewDocumentResponse } from 'common/api/osrdEditoastApi';
12
import mainConfig from 'config/config';
23

34
export const getDocument = async (documentKey: number): Promise<Blob> => {
@@ -13,6 +14,6 @@ export const postDocument = async (image: Blob) => {
1314
},
1415
body: image,
1516
});
16-
const data = await res.json();
17+
const data: NewDocumentResponse = await res.json();
1718
return data.document_key;
1819
};

front/src/modules/simulationResult/components/ChartHelpers/enableInteractivity.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,8 @@ export const enableInteractivity = <
302302
setChart(newChart);
303303
})
304304
.filter(
305-
(event) => (event.button === 0 || event.button === 1) && (event.ctrlKey || event.shiftKey)
305+
(event: MouseEvent) =>
306+
(event.button === 0 || event.button === 1) && (event.ctrlKey || event.shiftKey)
306307
);
307308

308309
// Updates in real time the position of the pointer and the vertical/horizontal guidelines

0 commit comments

Comments
 (0)