Skip to content

Commit eaff1ae

Browse files
chore: remove unneeded non-null assertions
Now `setCurNode` can take null we don't need them.
1 parent 42e8cd7 commit eaff1ae

File tree

6 files changed

+14
-27
lines changed

6 files changed

+14
-27
lines changed

src/actions/disconnect.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,7 @@ export class DisconnectAction {
145145
rootBlock.bringToFront();
146146

147147
if (wasVisitingConnection) {
148-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
149-
const connectionNode = ASTNode.createConnectionNode(superiorConnection)!;
148+
const connectionNode = ASTNode.createConnectionNode(superiorConnection);
150149
workspace.getCursor()?.setCurNode(connectionNode);
151150
}
152151
}

src/actions/enter.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,7 @@ export class EnterAction {
145145
}
146146

147147
this.navigation.focusWorkspace(workspace);
148-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
149-
workspace.getCursor()?.setCurNode(ASTNode.createBlockNode(newBlock)!);
148+
workspace.getCursor()?.setCurNode(ASTNode.createBlockNode(newBlock));
150149
}
151150

152151
/**

src/actions/ws_movement.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,10 @@ export class WorkspaceMovement {
115115
const newY = yDirection * WS_MOVE_DISTANCE + wsCoord.y;
116116

117117
cursor.setCurNode(
118-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
119118
ASTNode.createWorkspaceNode(
120119
workspace,
121120
new BlocklyUtils.Coordinate(newX, newY),
122-
)!,
121+
),
123122
);
124123
return true;
125124
}

src/flyout_cursor.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,13 @@ export class FlyoutCursor extends Blockly.Cursor {
8383
return null;
8484
}
8585

86-
override setCurNode(node: Blockly.ASTNode) {
86+
override setCurNode(node: Blockly.ASTNode | null) {
8787
super.setCurNode(node);
8888

89-
const location = node.getLocation();
89+
const location = node?.getLocation();
9090
let bounds: Blockly.utils.Rect | undefined;
9191
if (
92+
location &&
9293
'getBoundingRectangle' in location &&
9394
typeof location.getBoundingRectangle === 'function'
9495
) {

src/line_cursor.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -744,8 +744,7 @@ export class LineCursor extends Marker {
744744
block = block.getParent();
745745
}
746746
if (block) {
747-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
748-
this.setCurNode(Blockly.ASTNode.createBlockNode(block)!, true);
747+
this.setCurNode(Blockly.ASTNode.createBlockNode(block), true);
749748
}
750749
}
751750
}

src/navigation.ts

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,7 @@ export class Navigation {
320320
const curNode = cursor.getCurNode();
321321
const block = curNode ? curNode.getSourceBlock() : null;
322322
if (block && block.id === mutatedBlockId) {
323-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
324-
cursor.setCurNode(Blockly.ASTNode.createBlockNode(block)!);
323+
cursor.setCurNode(Blockly.ASTNode.createBlockNode(block));
325324
}
326325
}
327326
}
@@ -348,11 +347,7 @@ export class Navigation {
348347

349348
if (sourceBlock.id === deletedBlockId || ids.includes(sourceBlock.id)) {
350349
cursor.setCurNode(
351-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
352-
Blockly.ASTNode.createWorkspaceNode(
353-
workspace,
354-
WS_COORDINATE_ON_DELETE,
355-
)!,
350+
Blockly.ASTNode.createWorkspaceNode(workspace, WS_COORDINATE_ON_DELETE),
356351
);
357352
}
358353
}
@@ -374,8 +369,7 @@ export class Navigation {
374369
const curNodeBlock = block.isShadow() ? block : block.getParent();
375370
if (curNodeBlock) {
376371
this.getFlyoutCursor(mainWorkspace)?.setCurNode(
377-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
378-
Blockly.ASTNode.createStackNode(curNodeBlock)!,
372+
Blockly.ASTNode.createStackNode(curNodeBlock),
379373
);
380374
}
381375
this.focusFlyout(mainWorkspace);
@@ -603,17 +597,15 @@ export class Navigation {
603597
if (!defaultFlyoutItem) return;
604598
const defaultFlyoutItemElement = defaultFlyoutItem.getElement();
605599
if (defaultFlyoutItemElement instanceof Blockly.FlyoutButton) {
606-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
607600
const astNode = Blockly.ASTNode.createButtonNode(
608601
defaultFlyoutItemElement as Blockly.FlyoutButton,
609-
)!;
602+
);
610603
flyoutCursor.setCurNode(astNode);
611604
return true;
612605
} else if (defaultFlyoutItemElement instanceof Blockly.BlockSvg) {
613-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
614606
const astNode = Blockly.ASTNode.createStackNode(
615607
defaultFlyoutItemElement as Blockly.BlockSvg,
616-
)!;
608+
);
617609
flyoutCursor.setCurNode(astNode);
618610
return true;
619611
}
@@ -652,17 +644,15 @@ export class Navigation {
652644
);
653645
if (topBlocks.length > 0) {
654646
cursor.setCurNode(
655-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
656647
Blockly.ASTNode.createTopNode(
657648
topBlocks[prefer === 'first' ? 0 : topBlocks.length - 1],
658-
)!,
649+
),
659650
);
660651
} else {
661-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
662652
const wsNode = Blockly.ASTNode.createWorkspaceNode(
663653
workspace,
664654
wsCoordinates,
665-
)!;
655+
);
666656
cursor.setCurNode(wsNode);
667657
}
668658
return true;

0 commit comments

Comments
 (0)