Skip to content

Commit 237f5aa

Browse files
committed
refactor(ui): set @typescript-eslint/no-non-null-assertion to error
1 parent 8a91f3e commit 237f5aa

27 files changed

Lines changed: 102 additions & 45 deletions

File tree

.eslintrc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
"ignoreProperties": true
8282
}
8383
],
84+
"@typescript-eslint/no-non-null-assertion": "error",
8485
"no-unused-vars": "off",
8586
"@typescript-eslint/no-unused-vars": [
8687
"error",

packages/platform/src/app/Routes.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,11 +238,12 @@ export const AppRoutes = React.memo(() => {
238238

239239
const title = (() => {
240240
if (matches) {
241-
const match = nth(matches, -1)!;
242-
const { title } = match.route.data ?? {};
243-
return isFunction(title) ? title(match.params) : title;
241+
const match = nth(matches, -1);
242+
if (match) {
243+
const { title } = match.route.data ?? {};
244+
return isFunction(title) ? title(match.params) : title;
245+
}
244246
}
245-
return undefined;
246247
})();
247248
useEffect(() => {
248249
if (isUndefined(title)) {

packages/platform/src/app/components/map/MapMarkerCluster.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ export function AppMapMarkerCluster<T extends MarkerClusterDataOption>(props: Ap
103103
if (!isUndefined(color)) {
104104
content.style.color = color;
105105
}
106+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
106107
content.firstElementChild!.innerHTML = String(context.count);
107108

108109
context.marker.setOffset(new AMap.Pixel(-size / 2, -size / 2));

packages/platform/src/app/components/table/Table.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ export function AppTable<T = any>(props: AppTableProps<T>): JSX.Element | null {
174174
dPlacement="bottom-right"
175175
onItemClick={(id) => {
176176
if (actions[id].link) {
177+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
177178
navigate(actions[id].link!);
178179
} else {
179180
return actions[id].onclick?.();
@@ -261,6 +262,7 @@ export function AppTable<T = any>(props: AppTableProps<T>): JSX.Element | null {
261262
dPlacement="bottom-right"
262263
onItemClick={(id) => {
263264
if (actions[id].link) {
265+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
264266
navigate(actions[id].link!);
265267
} else {
266268
return actions[id].onclick?.();
@@ -313,6 +315,7 @@ export function AppTable<T = any>(props: AppTableProps<T>): JSX.Element | null {
313315
<DCard.Action
314316
title="edit"
315317
onClick={() => {
318+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
316319
navigate(action.link!);
317320
}}
318321
>
@@ -341,6 +344,7 @@ export function AppTable<T = any>(props: AppTableProps<T>): JSX.Element | null {
341344
dPlacement="bottom-right"
342345
onItemClick={(id) => {
343346
if (actions[id].link) {
347+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
344348
navigate(actions[id].link!);
345349
} else {
346350
return actions[id].onclick?.();

packages/platform/src/app/core/http/mock.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ if (environment.http.mock) {
127127
mock.onGet(/\/api\/v1\/device\/[0-9]+/).reply((config) => {
128128
return new Promise((resolve) => {
129129
setTimeout(() => {
130+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
130131
resolve([200, deviceList.find((device) => device.id === Number(config.url!.match(/[0-9]+$/)![0]))]);
131132
}, 500);
132133
});

packages/platform/src/app/core/http/useHttp.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export function useHttp() {
3030

3131
const http = useEventCallback(
3232
<T = any, D = any>(
33-
config: AxiosRequestConfig<D>,
33+
config: AxiosRequestConfig<D> & { url: string },
3434
options?: { unmount?: boolean; authorization?: boolean }
3535
): Observable<T> & { abort: () => void } => {
3636
const { unmount = true, authorization = true } = options ?? {};
@@ -55,7 +55,7 @@ export function useHttp() {
5555
const req = of({
5656
...config,
5757
baseURL: environment.http.baseURL,
58-
url: environment.http.transformURL(config.url!),
58+
url: environment.http.transformURL(config.url),
5959
headers,
6060
signal: controller.signal,
6161
}).pipe(

packages/platform/src/app/routes/list/standard-table/detail/Detail.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export default AppRoute(() => {
2222
const deviceApi = useAPI(http, '/device');
2323

2424
const { id: _id } = useParams();
25+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
2526
const id = Number(_id!);
2627

2728
const [deviceLoading, setDeviceLoading] = useState(true);

packages/platform/src/app/routes/login/Login.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ export default AppRoute(() => {
7979
error: (error) => {
8080
setLoginLoading(false);
8181
NotificationService.open({
82-
dTitle: error.response!.status,
83-
dDescription: error.response!.statusText,
82+
dTitle: error.response.status,
83+
dDescription: error.response.statusText,
8484
dType: 'error',
8585
});
8686
},
@@ -134,16 +134,16 @@ export default AppRoute(() => {
134134
<DForm.Item
135135
dFormControls={{
136136
username: {
137-
required: t('routes.login.Please enter your name')!,
138-
checkValue: t('routes.login.Username')!,
137+
required: t('routes.login.Please enter your name'),
138+
checkValue: t('routes.login.Username'),
139139
},
140140
}}
141141
>
142142
{({ username }) => (
143143
<DInput dFormControl={username} dPrefix={<UserOutlined />} dPlaceholder={t('routes.login.Username')} />
144144
)}
145145
</DForm.Item>
146-
<DForm.Item dFormControls={{ password: t('routes.login.Please enter your password')! }}>
146+
<DForm.Item dFormControls={{ password: t('routes.login.Please enter your password') }}>
147147
{({ password }) => (
148148
<DInput
149149
dFormControl={password}
@@ -164,12 +164,12 @@ export default AppRoute(() => {
164164
panel: (
165165
<DForm onSubmit={handleSubmit} dUpdate={updatePhoneForm} dLabelWidth={0}>
166166
<DForm.Group dFormGroup={phoneForm}>
167-
<DForm.Item dFormControls={{ phone: t('routes.login.Please enter your phone number')! }}>
167+
<DForm.Item dFormControls={{ phone: t('routes.login.Please enter your phone number') }}>
168168
{({ phone }) => (
169169
<DInput dFormControl={phone} dPrefix={<MobileOutlined />} dPlaceholder={t('routes.login.Phone number')} />
170170
)}
171171
</DForm.Item>
172-
<DForm.Item dFormControls={{ code: t('routes.login.Please enter verification code')! }} dSpan>
172+
<DForm.Item dFormControls={{ code: t('routes.login.Please enter verification code') }} dSpan>
173173
{({ code }) => <DInput dFormControl={code} dPlaceholder={t('routes.login.Verification code')} />}
174174
</DForm.Item>
175175
<DForm.Item dLabelWidth={8} dSpan="auto">

packages/site/executors/build-base/build-base.impl.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/no-non-null-assertion */
12
import type { ExecutorContext } from '@nrwl/devkit';
23
import type { FSWatcher } from 'fs-extra';
34

packages/site/src/app/components/route/component/DemoBox.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/no-non-null-assertion */
12
import { useRef, useState } from 'react';
23
import { useTranslation } from 'react-i18next';
34
import { useLocation } from 'react-router-dom';

0 commit comments

Comments
 (0)