Skip to content

Commit 5cb43ec

Browse files
authored
Fix some strict undefined equality checks (#481)
1 parent 8746f1e commit 5cb43ec

File tree

10 files changed

+30
-26
lines changed

10 files changed

+30
-26
lines changed

hwproj.front/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@
6060
"eject": "react-scripts eject"
6161
},
6262
"eslintConfig": {
63-
"extends": "react-app"
63+
"extends": "react-app",
64+
"rules": {
65+
"eqeqeq": [1, "always", { "null": "ignore" }]
66+
}
6467
},
6568
"browserslist": [
6669
">0.2%",

hwproj.front/src/components/Common/HomeworkTags.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const BonusTip: FC = () => <sup style={{color: "green"}}> бонус</sup>
1414

1515
export const getTip = (tagsOwner: { tags?: string[] }) => {
1616
const tags = tagsOwner.tags
17-
if (tags === undefined) return null
17+
if (tags == null) return null
1818
if (tags.includes(TestTag)) return <TestTip/>
1919
if (tags.includes(BonusTag)) return <BonusTip/>
2020
return null

hwproj.front/src/components/Common/MarkdownEditor.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,11 @@ const MarkdownEditor: FC<MarkdownEditorProps> = (props) => {
6161
className: "markdown-preview"
6262
}}
6363
maxHeight={props.maxHeight ?? 400}
64-
height={props.height ?? 200}
64+
height={props.height ?? 230}
6565
textareaProps={{
6666
placeholder: props.label
6767
}}
68+
preview="edit"
6869
/>
6970
</div>
7071
);

hwproj.front/src/components/Common/PublicationAndDeadlineDates.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import React, {useState, useEffect} from 'react';
22
import Utils from "../../services/Utils";
33
import {Tooltip, Checkbox, TextField, Grid, FormControlLabel} from '@mui/material/'
44

5-
65
interface IDateFieldsProps {
76
publicationDate: Date | undefined;
87
hasDeadline: boolean;
@@ -58,7 +57,7 @@ const PublicationAndDeadlineDates: React.FC<IDateFieldsProps> = (props) => {
5857
props.autoCalculatedDeadline && state.deadlineDate === props.autoCalculatedDeadline
5958

6059
const isDeadlineSoonerThanPublication = (publicationDate: Date, deadlineDate: Date | undefined) =>
61-
deadlineDate !== undefined && deadlineDate < publicationDate;
60+
deadlineDate != null && deadlineDate < publicationDate;
6261

6362
const deadlineSoonerThatHomework = isDeadlineSoonerThanPublication(state.publicationDate, state.deadlineDate)
6463

hwproj.front/src/components/Common/TaskPublicationAndDeadlineDates.tsx

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ interface IDateFieldsState {
2626
const TaskPublicationAndDeadlineDates: React.FC<IDateFieldsProps> = (props) => {
2727
const {homework} = props
2828
const homeworkPublicationDate = new Date(homework.publicationDate!)
29-
const homeworkDeadlineDate = homework.deadlineDate === undefined ? undefined : new Date(homework.deadlineDate)
29+
const homeworkDeadlineDate = homework.deadlineDate == null ? undefined : new Date(homework.deadlineDate)
3030

3131
const [state, setState] = useState<IDateFieldsState>({
3232
hasDeadline: props.hasDeadline,
@@ -36,10 +36,10 @@ const TaskPublicationAndDeadlineDates: React.FC<IDateFieldsProps> = (props) => {
3636
});
3737

3838
const [showDates, setShowDates] = useState<boolean>(
39-
props.deadlineDate !== undefined
40-
|| props.hasDeadline !== undefined
41-
|| props.isDeadlineStrict !== undefined
42-
|| props.publicationDate !== undefined)
39+
props.deadlineDate != null
40+
|| props.hasDeadline != null
41+
|| props.isDeadlineStrict != null
42+
|| props.publicationDate != null)
4343

4444
const {publicationDate, isDeadlineStrict, deadlineDate, hasDeadline} = state
4545

@@ -48,15 +48,16 @@ const TaskPublicationAndDeadlineDates: React.FC<IDateFieldsProps> = (props) => {
4848

4949
const isDeadlineSoonerThanPublication = (taskPublicationDate: Date | undefined, taskDeadlineDate: Date | undefined) =>
5050
{
51-
if ((taskDeadlineDate || homeworkDeadlineDate) === undefined) return false
51+
const deadlineDate = taskDeadlineDate || homeworkDeadlineDate
52+
if (deadlineDate == null) return false
5253

53-
return (taskDeadlineDate || homeworkDeadlineDate)! < (taskPublicationDate || homeworkPublicationDate)
54+
return deadlineDate < (taskPublicationDate || homeworkPublicationDate)
5455
}
5556

5657
const taskSoonerThanHomework = !!state.publicationDate && isTaskSoonerThanHomework(state.publicationDate)
5758
const deadlineSoonerThanPublication = (!!state.deadlineDate || !!homeworkDeadlineDate) && isDeadlineSoonerThanPublication(state.publicationDate, state.deadlineDate)
5859

59-
const showDeadlineEdit = hasDeadline === undefined ? homework.hasDeadline : hasDeadline
60+
const showDeadlineEdit = hasDeadline == null ? homework.hasDeadline : hasDeadline
6061

6162
useEffect(() => {
6263
const validationResult =
@@ -143,13 +144,13 @@ const TaskPublicationAndDeadlineDates: React.FC<IDateFieldsProps> = (props) => {
143144
...prevState,
144145
deadlineDate: undefined,
145146
isDeadlineStrict: undefined,
146-
hasDeadline: hasDeadline === undefined ? !homework.hasDeadline : undefined,
147+
hasDeadline: hasDeadline == null ? !homework.hasDeadline : undefined,
147148
}))
148149
}}
149150
/>}
150151
/>
151152
<FormHelperText style={{ marginTop: '-1px' }}>
152-
{hasDeadline !== undefined
153+
{hasDeadline != null
153154
? hasDeadline
154155
? 'Было без дедлайна'
155156
: 'Был c дедлайном'
@@ -174,7 +175,7 @@ const TaskPublicationAndDeadlineDates: React.FC<IDateFieldsProps> = (props) => {
174175
variant="standard"
175176
error={deadlineSoonerThanPublication}
176177
helperText={deadlineSoonerThanPublication ? `Дедлайн задачи раньше ее публикации: ${Utils.renderDateWithoutSeconds(state.publicationDate!)}` :
177-
deadlineDate !== undefined
178+
deadlineDate != null
178179
? props.homework.hasDeadline
179180
? `Было ${Utils.renderDateWithoutSeconds(props.homework.deadlineDate!)}`
180181
: `Было без дедлайна`
@@ -200,7 +201,7 @@ const TaskPublicationAndDeadlineDates: React.FC<IDateFieldsProps> = (props) => {
200201
<FormControlLabel
201202
label="Строгий"
202203
control={<Checkbox
203-
checked={isDeadlineStrict === undefined ? homework.isDeadlineStrict : isDeadlineStrict}
204+
checked={isDeadlineStrict == null ? homework.isDeadlineStrict : isDeadlineStrict}
204205
onChange={(_) => {
205206
setState(prevState => ({
206207
...prevState,
@@ -210,7 +211,7 @@ const TaskPublicationAndDeadlineDates: React.FC<IDateFieldsProps> = (props) => {
210211
/>}
211212
/>
212213
<FormHelperText style={{ marginTop: '-1px' }}>
213-
{isDeadlineStrict !== undefined
214+
{isDeadlineStrict != null
214215
? isDeadlineStrict
215216
? 'Был нестрогий'
216217
: 'Был строгий'

hwproj.front/src/components/Courses/CourseExperimental.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,13 @@ const CourseExperimental: FC<ICourseExperimentalProps> = (props) => {
149149
color,
150150
solutionsDescription
151151
} = StudentStatsUtils.calculateLastRatedSolutionInfo(solutions!, taskMaxRating)
152-
return lastSolution === undefined
152+
return lastSolution == null
153153
? <TimelineDot variant={"outlined"}/>
154154
: <Tooltip arrow disableInteractive enterDelay={1000}
155155
title={<span style={{whiteSpace: 'pre-line'}}>{solutionsDescription}</span>}>
156156
<Chip style={{backgroundColor: color, marginTop: '11.5px'}}
157157
size={"small"}
158-
label={lastRatedSolution === undefined ? "?" : lastRatedSolution.rating}/>
158+
label={lastRatedSolution == null ? "?" : lastRatedSolution.rating}/>
159159
</Tooltip>
160160
}
161161
return <TimelineDot variant={"outlined"}/>

hwproj.front/src/components/Homeworks/EditHomework.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ const EditHomework: FC = () => {
7070

7171
const course = await ApiSingleton.coursesApi.apiCoursesByCourseIdGet(homework.courseId!)
7272

73-
const deadline = homework.deadlineDate === undefined
73+
const deadline = homework.deadlineDate == null
7474
? undefined
7575
: new Date(homework.deadlineDate)
7676

@@ -90,7 +90,7 @@ const EditHomework: FC = () => {
9090
hasErrors: false,
9191
tags: homework.tags!,
9292
changedTaskPublicationDates: homework.tasks!
93-
.filter(t => t.publicationDate !== undefined)
93+
.filter(t => t.publicationDate != null)
9494
.map(t => new Date(t.publicationDate!))
9595
}))
9696
}

hwproj.front/src/components/Tasks/EditTask.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ const EditTask: FC = () => {
6969
const task = taskForEditing.task!
7070
const course = await ApiSingleton.coursesApi.apiCoursesByCourseIdGet(homework.courseId!)
7171

72-
const publication = task.publicationDate === undefined
72+
const publication = task.publicationDate == null
7373
? undefined
7474
: new Date(task.publicationDate)
7575

76-
const deadline = task.deadlineDate === undefined
76+
const deadline = task.deadlineDate == null
7777
? undefined
7878
: new Date(task.deadlineDate)
7979

hwproj.front/src/components/Tasks/TaskDeadlines.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ const TaskDeadlines: FC<ITaskDeadlinesProps> = ({taskDeadlines, onGiveUpClick})
8989
<Stack direction={"row"} spacing={10} alignItems={"baseline"} justifyContent={"space-between"}
9090
style={{height: 27}}>
9191
{Utils.renderReadableDate(deadline!.deadlineDate!)}
92-
{hoveredElement === i && solutionState === undefined && (
92+
{hoveredElement === i && solutionState == null && (
9393
<Typography variant={"caption"}>
9494
<LinkText
9595
style={{textDecoration: "none", cursor: "pointer"}}

hwproj.front/src/services/Utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default class Utils {
99
}
1010

1111
static toISOString(date: Date | undefined) {
12-
if (date === undefined) return undefined
12+
if (date == null) return undefined
1313

1414
const pad = (num: number) => (num < 10 ? '0' : '') + num
1515

0 commit comments

Comments
 (0)