Skip to content

Commit 0417f7e

Browse files
committed
refactor: . Unwrap else block
1 parent db4931d commit 0417f7e

File tree

1 file changed

+26
-27
lines changed

1 file changed

+26
-27
lines changed

src/Obsidian/FileParser.ts

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -122,37 +122,36 @@ export class FileParser {
122122
const parentListItem: ListItem | null = this.line2ListItem.get(listItem.parent) ?? null;
123123
this.line2ListItem.set(lineNumber, new ListItem(this.fileLines[lineNumber], parentListItem));
124124
return sectionIndex;
125-
} else {
126-
let task;
127-
try {
128-
task = Task.fromLine({
129-
line,
130-
taskLocation: taskLocation,
131-
fallbackDate: this.dateFromFileName.value,
132-
});
125+
}
126+
let task;
127+
try {
128+
task = Task.fromLine({
129+
line,
130+
taskLocation: taskLocation,
131+
fallbackDate: this.dateFromFileName.value,
132+
});
133+
134+
if (task !== null) {
135+
// listItem.parent could be negative if the parent is not found (in other words, it is a root task).
136+
// That is not a problem, as we never put a negative number in line2ListItem map, so parent will be null.
137+
const parentListItem: ListItem | null = this.line2ListItem.get(listItem.parent) ?? null;
138+
if (parentListItem !== null) {
139+
task = new Task({
140+
...task,
141+
parent: parentListItem,
142+
});
143+
}
144+
145+
this.line2ListItem.set(lineNumber, task);
133146

134147
if (task !== null) {
135-
// listItem.parent could be negative if the parent is not found (in other words, it is a root task).
136-
// That is not a problem, as we never put a negative number in line2ListItem map, so parent will be null.
137-
const parentListItem: ListItem | null = this.line2ListItem.get(listItem.parent) ?? null;
138-
if (parentListItem !== null) {
139-
task = new Task({
140-
...task,
141-
parent: parentListItem,
142-
});
143-
}
144-
145-
this.line2ListItem.set(lineNumber, task);
146-
147-
if (task !== null) {
148-
sectionIndex++;
149-
this.tasks.push(task);
150-
}
148+
sectionIndex++;
149+
this.tasks.push(task);
151150
}
152-
} catch (e) {
153-
this.errorReporter(e, this.filePath, listItem, line);
154-
return sectionIndex;
155151
}
152+
} catch (e) {
153+
this.errorReporter(e, this.filePath, listItem, line);
154+
return sectionIndex;
156155
}
157156
return sectionIndex;
158157
}

0 commit comments

Comments
 (0)