Skip to content

Commit 4da7bf0

Browse files
committed
Activate eslint no-unsafe-member-access
Enable the eslint rule no-unsafe-member-access.
1 parent 9893c84 commit 4da7bf0

16 files changed

Lines changed: 100 additions & 69 deletions

eslint.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ export default [
1919
"@typescript-eslint/no-explicit-any": "off",
2020
"@typescript-eslint/no-floating-promises": "off",
2121
"@typescript-eslint/no-misused-promises": "off",
22-
"@typescript-eslint/no-unsafe-member-access": "off",
2322
"@typescript-eslint/no-unused-vars": "off",
2423
"@typescript-eslint/no-unsafe-return": "off",
2524
"@typescript-eslint/require-await": "off",

src/components/events/partials/wizards/NewEventSummary.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ const NewEventSummary = <T extends RequiredFormProps>({
5959
const [uploadAssetsNonTrack, setUploadAssetsNonTrack] = useState<{
6060
name: string,
6161
translate?: string,
62-
value: any,
62+
value: File,
6363
}[]>([]);
6464

6565
const uploadAssetOptions = useAppSelector(state => getAssetUploadOptions(state));
@@ -72,10 +72,10 @@ const NewEventSummary = <T extends RequiredFormProps>({
7272
const uploadAssetsNonTrack: {
7373
name: string,
7474
translate?: string,
75-
value: any,
75+
value: File,
7676
}[] = [];
7777
for (let i = 0; uploadAssetOptions.length > i; i++) {
78-
const fieldValue = formik.values[uploadAssetOptions[i].id];
78+
const fieldValue = formik.values[uploadAssetOptions[i].id] as File;
7979
if (fieldValue) {
8080
const displayOverride = uploadAssetOptions[i].displayOverride as ParseKeys;
8181
setUploadAssetsNonTrack(uploadAssetsNonTrack.concat({

src/components/shared/DropDown.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,19 @@ const DropDown = <T, >({
111111
* contains an `order` field, indicating that a custom ordering for that list
112112
* exists and the list therefore should not be ordered alphabetically.
113113
*/
114-
const hasCustomOrder = unformattedOptions.every(item =>
115-
isJson(item.label) && JSON.parse(item.label).order !== undefined);
114+
const hasCustomOrder = unformattedOptions.every(item => {
115+
if (!isJson(item.label)) {
116+
return false;
117+
}
118+
// TODO: Handle JSON parsing errors
119+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
120+
const parsed = JSON.parse(item.label);
121+
return parsed && typeof parsed === "object" && "order" in parsed;
122+
});
116123

117124
if (hasCustomOrder) {
118125
// Apply custom ordering.
126+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
119127
unformattedOptions.sort((a, b) => JSON.parse(a.label).order - JSON.parse(b.label).order);
120128
} else {
121129
// Apply alphabetical ordering.

src/components/shared/wizard/RenderField.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,14 @@ const RenderField = ({
3939
<div
4040
onClick={() => {
4141
if (editableRef.current) {
42+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
4243
if (editableRef.current.focus) {
43-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
44+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
4445
editableRef.current.focus();
4546
}
47+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
4648
if (editableRef.current.setFocus) {
47-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
49+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
4850
editableRef.current.setFocus(); // For DatePicker
4951
}
5052
}
@@ -123,6 +125,7 @@ const RenderField = ({
123125
{!focused && showCheck && (
124126
<i
125127
className={cn("saved fa fa-check", {
128+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
126129
active: form.initialValues[field.name] !== field.value,
127130
})}
128131
/>

src/components/shared/wizard/RenderMultiField.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ const ShowValue = ({
221221
{showCheck && (
222222
<i
223223
className={cn("saved fa fa-check", {
224+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
224225
active: JSON.stringify(initialValues[field.name] ?? []) !== JSON.stringify(field.value ?? []),
225226
})}
226227
/>

src/slices/eventSlice.ts

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { PayloadAction, SerializedError, createSlice } from "@reduxjs/toolkit";
22
import { eventsTableConfig } from "../configs/tableConfigs/eventsTableConfig";
3-
import axios, { AxiosProgressEvent } from "axios";
3+
import axios, { AxiosError, AxiosProgressEvent } from "axios";
44
import moment from "moment-timezone";
55
import {
66
getURLParams,
@@ -391,41 +391,44 @@ export const updateBulkMetadata = createAppAsyncThunk("events/updateBulkMetadata
391391
})
392392
.catch(err => {
393393
console.error(err);
394-
// if an internal server error occurred, then backend sends further information
395-
if (err.status === 500) {
396-
// backend should send data containing further information about occurred internal error
397-
// if this error data is undefined then an unexpected error occurred
398-
if (!err.data) {
399-
dispatch(
400-
addNotification({ type: "error", key: "BULK_METADATA_UPDATE.UNEXPECTED_ERROR" }),
401-
);
402-
} else {
403-
if (err.data.updated && err.data.updated.length === 0) {
404-
dispatch(
405-
addNotification({ type: "error", key: "BULK_METADATA_UPDATE.NO_EVENTS_UPDATED" }),
406-
);
407-
}
408-
if (err.data.updateFailures && err.data.updateFailures.length > 0) {
409-
dispatch(
410-
addNotification({
411-
type: "warning",
412-
key: "BULK_METADATA_UPDATE.SOME_EVENTS_NOT_UPDATED",
413-
}),
414-
);
415-
}
416-
if (err.data.notFound && err.data.notFound.length > 0) {
394+
if (axios.isAxiosError<{ updated: string[], updateFailures: string[], notFound: string[] }>(err) && err.response) {
395+
// if an internal server error occurred, then backend sends further information
396+
if (err.status === 500) {
397+
// backend should send data containing further information about occurred internal error
398+
// if this error data is undefined then an unexpected error occurred
399+
const data = err.response.data;
400+
if (!data) {
417401
dispatch(
418-
addNotification({
419-
type: "warning",
420-
key: "BULK_ACTIONS.EDIT_EVENTS_METADATA.REQUEST_ERRORS.NOT_FOUND",
421-
}),
402+
addNotification({ type: "error", key: "BULK_METADATA_UPDATE.UNEXPECTED_ERROR" }),
422403
);
404+
} else {
405+
if (data.updated && data.updated.length === 0) {
406+
dispatch(
407+
addNotification({ type: "error", key: "BULK_METADATA_UPDATE.NO_EVENTS_UPDATED" }),
408+
);
409+
}
410+
if (data.updateFailures && data.updateFailures.length > 0) {
411+
dispatch(
412+
addNotification({
413+
type: "warning",
414+
key: "BULK_METADATA_UPDATE.SOME_EVENTS_NOT_UPDATED",
415+
}),
416+
);
417+
}
418+
if (data.notFound && data.notFound.length > 0) {
419+
dispatch(
420+
addNotification({
421+
type: "warning",
422+
key: "BULK_ACTIONS.EDIT_EVENTS_METADATA.REQUEST_ERRORS.NOT_FOUND",
423+
}),
424+
);
425+
}
423426
}
427+
} else {
428+
dispatch(
429+
addNotification({ type: "error", key: "BULK_METADATA_UPDATE.UNEXPECTED_ERROR" }),
430+
);
424431
}
425-
} else {
426-
dispatch(
427-
addNotification({ type: "error", key: "BULK_METADATA_UPDATE.UNEXPECTED_ERROR" }),
428-
);
429432
}
430433
});
431434
});
@@ -680,9 +683,9 @@ export const deleteEvent = createAppAsyncThunk("events/deleteEvent", async (id:
680683
dispatch(addNotification({ type: "success", key: "EVENT_WILL_BE_DELETED" }));
681684
}
682685
})
683-
.catch(res => {
686+
.catch((error: AxiosError) => {
684687
// add error notification depending on status code
685-
if (res.status === 401) {
688+
if (error.status === 401) {
686689
dispatch(addNotification({ type: "error", key: "EVENTS_NOT_DELETED_NOT_AUTHORIZED" }));
687690
} else {
688691
dispatch(addNotification({ type: "error", key: "EVENTS_NOT_DELETED" }));

src/slices/groupDetailsSlice.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { PayloadAction, SerializedError, createSlice } from "@reduxjs/toolkit";
2-
import axios from "axios";
2+
import axios, { AxiosError } from "axios";
33
import { buildGroupBody } from "../utils/resourceUtils";
44
import { addNotification } from "./notificationSlice";
55
import { createAppAsyncThunk } from "../createAsyncThunkWithTypes";
@@ -79,9 +79,9 @@ export const updateGroupDetails = createAppAsyncThunk("groupDetails/updateGroupD
7979
console.info(response);
8080
dispatch(addNotification({ type: "success", key: "GROUP_UPDATED" }));
8181
})
82-
.catch(response => {
83-
console.error(response);
84-
if (response.status === 409) {
82+
.catch((error: AxiosError) => {
83+
console.error(error);
84+
if (error.status === 409) {
8585
dispatch(addNotification({ type: "error", key: "GROUP_CONFLICT" }));
8686
} else {
8787
dispatch(addNotification({ type: "error", key: "GROUP_NOT_SAVED" }));

src/slices/groupSlice.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { PayloadAction, SerializedError, createSlice } from "@reduxjs/toolkit";
22
import { groupsTableConfig } from "../configs/tableConfigs/groupsTableConfig";
3-
import axios from "axios";
3+
import axios, { AxiosError } from "axios";
44
import { buildGroupBody, getURLParams } from "../utils/resourceUtils";
55
import { addNotification } from "./notificationSlice";
66
import { TableConfig } from "../configs/tableConfigs/aclsTableConfig";
@@ -73,9 +73,9 @@ export const postNewGroup = createAppAsyncThunk("groups/postNewGroup", async (va
7373
.then(() => {
7474
dispatch(addNotification({ type: "success", key: "GROUP_ADDED" }));
7575
})
76-
.catch(response => {
77-
console.error(response);
78-
if (response.status === 409) {
76+
.catch((error: AxiosError) => {
77+
console.error(error);
78+
if (error.status === 409) {
7979
dispatch(addNotification({ type: "error", key: "GROUP_CONFLICT" }));
8080
} else {
8181
dispatch(addNotification({ type: "error", key: "GROUP_NOT_SAVED" }));

src/slices/recordingSlice.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { PayloadAction, SerializedError, createSlice } from "@reduxjs/toolkit";
22
import { recordingsTableConfig } from "../configs/tableConfigs/recordingsTableConfig";
3-
import axios from "axios";
3+
import axios, { AxiosError } from "axios";
44
import { getURLParams } from "../utils/resourceUtils";
55
import { addNotification } from "./notificationSlice";
66
import { TableConfig } from "../configs/tableConfigs/aclsTableConfig";
@@ -115,10 +115,10 @@ export const deleteRecording = createAppAsyncThunk("recordings/deleteRecording",
115115
// add success notification
116116
dispatch(addNotification({ type: "success", key: "LOCATION_DELETED" }));
117117
})
118-
.catch(res => {
119-
console.error(res);
118+
.catch((error: AxiosError) => {
119+
console.error(error);
120120
// add error notification depending on status code
121-
if (res.status === 401) {
121+
if (error.status === 401) {
122122
dispatch(
123123
addNotification({ type: "error", key: "LOCATION_NOT_DELETED_NOT_AUTHORIZED" }),
124124
);

src/slices/seriesSlice.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,9 @@ export const postNewSeries = createAppAsyncThunk("series/postNewSeries", async (
228228
}
229229
});
230230

231-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
231+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
232232
tobira["parentPagePath"] = existingPages.pop().path;
233+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
233234
tobira["newPages"] = newPages;
234235
}
235236

@@ -340,8 +341,8 @@ export const deleteMultipleSeries = createAppAsyncThunk("series/deleteMultipleSe
340341
//add success notification
341342
dispatch(addNotification({ type: "success", key: "SERIES_DELETED" }));
342343
})
343-
.catch(res => {
344-
console.error(res);
344+
.catch((error: AxiosError) => {
345+
console.error(error);
345346
//add error notification
346347
dispatch(addNotification({ type: "error", key: "SERIES_NOT_DELETED" }));
347348
});

0 commit comments

Comments
 (0)