chore: Fix or individually disable no-this-alias lint rule violations. (#6371)

This commit is contained in:
Aaron Dodson
2022-08-22 14:13:26 -07:00
committed by GitHub
parent 9454b7070c
commit 43f54b1b06
11 changed files with 45 additions and 54 deletions

View File

@@ -570,6 +570,7 @@ export class Block implements IASTNodeLocation, IDeletable {
* @return The block (if any) that surrounds the current block.
*/
getSurroundParent(): this|null {
/* eslint-disable-next-line @typescript-eslint/no-this-alias */
let block = this;
let prevBlock;
do {
@@ -625,6 +626,7 @@ export class Block implements IASTNodeLocation, IDeletable {
*/
getRootBlock(): this {
let rootBlock: this;
/* eslint-disable-next-line @typescript-eslint/no-this-alias */
let block: this|null = this;
do {
rootBlock = block;
@@ -641,6 +643,7 @@ export class Block implements IASTNodeLocation, IDeletable {
* @internal
*/
getTopStackBlock(): this {
/* eslint-disable-next-line @typescript-eslint/no-this-alias */
let block = this;
let previous;
do {

View File

@@ -1242,6 +1242,7 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg,
* @internal
*/
bringToFront() {
/* eslint-disable-next-line @typescript-eslint/no-this-alias */
let block = this;
do {
const root = block.getSvgRoot();
@@ -1550,19 +1551,18 @@ export class BlockSvg extends Block implements IASTNodeLocationSvg,
* @internal
*/
scheduleSnapAndBump() {
const block = this;
// Ensure that any snap and bump are part of this move's event group.
const group = eventUtils.getGroup();
setTimeout(function() {
setTimeout(() => {
eventUtils.setGroup(group);
block.snapToGrid();
this.snapToGrid();
eventUtils.setGroup(false);
}, config.bumpDelay / 2);
setTimeout(function() {
setTimeout(() => {
eventUtils.setGroup(group);
block.bumpNeighbours();
this.bumpNeighbours();
eventUtils.setGroup(false);
}, config.bumpDelay);
}

View File

@@ -566,13 +566,11 @@ WorkspaceCommentSvg.prototype.showContextMenu =
if (this.workspace.options.readOnly) {
return;
}
// Save the current workspace comment in a variable for use in closures.
const comment = this;
const menuOptions = [];
if (this.isDeletable() && this.isMovable()) {
menuOptions.push(ContextMenu.commentDuplicateOption(comment));
menuOptions.push(ContextMenu.commentDeleteOption(comment));
menuOptions.push(ContextMenu.commentDuplicateOption(this));
menuOptions.push(ContextMenu.commentDeleteOption(this));
}
ContextMenu.show(e, menuOptions, this.RTL);

View File

@@ -91,8 +91,7 @@ export class Connection implements IASTNodeLocationWithBlock {
*/
protected connect_(childConnection: Connection) {
const INPUT = ConnectionType.INPUT_VALUE;
const parentConnection = this;
const parentBlock = parentConnection.getSourceBlock();
const parentBlock = this.getSourceBlock();
const childBlock = childConnection.getSourceBlock();
// Make sure the childConnection is available.
@@ -102,16 +101,16 @@ export class Connection implements IASTNodeLocationWithBlock {
// Make sure the parentConnection is available.
let orphan;
if (parentConnection.isConnected()) {
const shadowState = parentConnection.stashShadowState_();
const target = parentConnection.targetBlock();
if (this.isConnected()) {
const shadowState = this.stashShadowState_();
const target = this.targetBlock();
if (target!.isShadow()) {
target!.dispose(false);
} else {
parentConnection.disconnect();
this.disconnect();
orphan = target;
}
parentConnection.applyShadowState_(shadowState);
this.applyShadowState_(shadowState);
}
// Connect the new connection to the parent.
@@ -120,7 +119,7 @@ export class Connection implements IASTNodeLocationWithBlock {
event =
new (eventUtils.get(eventUtils.BLOCK_MOVE))!(childBlock) as BlockMove;
}
connectReciprocally(parentConnection, childConnection);
connectReciprocally(this, childConnection);
childBlock.setParent(parentBlock);
if (event) {
event.recordNew();
@@ -129,15 +128,14 @@ export class Connection implements IASTNodeLocationWithBlock {
// Deal with the orphan if it exists.
if (orphan) {
const orphanConnection = parentConnection.type === INPUT ?
orphan.outputConnection :
orphan.previousConnection;
const orphanConnection = this.type === INPUT ? orphan.outputConnection :
orphan.previousConnection;
const connection = Connection.getConnectionForOrphanedConnection(
childBlock, (orphanConnection));
if (connection) {
orphanConnection.connect(connection);
} else {
orphanConnection.onFailedConnect(parentConnection);
orphanConnection.onFailedConnect(this);
}
}
}
@@ -256,6 +254,7 @@ export class Connection implements IASTNodeLocationWithBlock {
// Superior block.
parentBlock = this.sourceBlock_;
childBlock = otherConnection.getSourceBlock();
/* eslint-disable-next-line @typescript-eslint/no-this-alias */
parentConnection = this;
} else {
// Inferior block.

View File

@@ -897,12 +897,11 @@ export abstract class Flyout extends DeleteArea implements IFlyout {
* @return Function to call when block is clicked.
*/
private blockMouseDown_(block: BlockSvg): Function {
const flyout = this;
return (e: MouseEvent) => {
const gesture = flyout.targetWorkspace.getGesture(e);
const gesture = this.targetWorkspace.getGesture(e);
if (gesture) {
gesture.setStartBlock(block);
gesture.handleFlyoutStart(e, flyout);
gesture.handleFlyoutStart(e, this);
}
};
}

View File

@@ -153,6 +153,7 @@ export class RenderedConnection extends Connection {
return;
}
// Swap the connections and move the 'static' connection instead.
/* eslint-disable-next-line @typescript-eslint/no-this-alias */
staticConnection = this;
reverse = true;
}
@@ -495,8 +496,7 @@ export class RenderedConnection extends Connection {
const renderedChildConnection = childConnection as RenderedConnection;
const parentConnection = this;
const parentBlock = parentConnection.getSourceBlock();
const parentBlock = this.getSourceBlock();
const childBlock = renderedChildConnection.getSourceBlock();
const parentRendered = parentBlock.rendered;
const childRendered = childBlock.rendered;
@@ -508,8 +508,8 @@ export class RenderedConnection extends Connection {
childBlock.updateDisabled();
}
if (parentRendered && childRendered) {
if (parentConnection.type === ConnectionType.NEXT_STATEMENT ||
parentConnection.type === ConnectionType.PREVIOUS_STATEMENT) {
if (this.type === ConnectionType.NEXT_STATEMENT ||
this.type === ConnectionType.PREVIOUS_STATEMENT) {
// Child block may need to square off its corners if it is in a stack.
// Rendering a child will render its parent.
childBlock.render();

View File

@@ -164,12 +164,10 @@ export class Scrollbar {
this.lengthAttribute_ = 'height';
this.positionAttribute_ = 'y';
}
const scrollbar = this;
this.onMouseDownBarWrapper_ = browserEvents.conditionalBind(
this.svgBackground_!, 'mousedown', scrollbar,
scrollbar.onMouseDownBar_);
this.svgBackground_!, 'mousedown', this, this.onMouseDownBar_);
this.onMouseDownHandleWrapper_ = browserEvents.conditionalBind(
this.svgHandle_!, 'mousedown', scrollbar, scrollbar.onMouseDownHandle_);
this.svgHandle_!, 'mousedown', this, this.onMouseDownHandle_);
}
/**

View File

@@ -481,6 +481,7 @@ export class ToolboxCategory extends ToolboxItem implements
* @return True only if every ancestor is expanded
*/
protected allAncestorsExpanded_(): boolean {
/* eslint-disable-next-line @typescript-eslint/no-this-alias */
let category: IToolboxItem = this;
while (category.getParent()) {
category = category.getParent()!;

View File

@@ -227,20 +227,19 @@ export class VariableMap {
}
}
const map = this;
if (uses.length > 1) {
// Confirm before deleting multiple blocks.
const confirmText = Msg['DELETE_VARIABLE_CONFIRMATION']
.replace('%1', String(uses.length))
.replace('%2', variableName);
dialog.confirm(confirmText, function(ok) {
dialog.confirm(confirmText, (ok) => {
if (ok && variable) {
map.deleteVariableInternal(variable, uses);
this.deleteVariableInternal(variable, uses);
}
});
} else {
// No confirmation necessary for a single block.
map.deleteVariableInternal(variable, uses);
this.deleteVariableInternal(variable, uses);
}
} else {
console.warn('Can\'t delete non-existent variable: ' + id);

View File

@@ -978,20 +978,18 @@ export class WorkspaceCommentSvg extends WorkspaceComment implements
* @internal
*/
setFocus() {
const comment = this;
this.focused_ = true;
// Defer CSS changes.
setTimeout(function() {
if (comment.disposed_) {
setTimeout(() => {
if (this.disposed_) {
return;
}
comment.textarea_!.focus();
comment.addFocus();
this.textarea_!.focus();
this.addFocus();
dom.addClass(
comment.svgRectTarget_ as SVGRectElement,
'blocklyCommentTargetFocused');
this.svgRectTarget_ as SVGRectElement, 'blocklyCommentTargetFocused');
dom.addClass(
comment.svgHandleTarget_ as SVGRectElement,
this.svgHandleTarget_ as SVGRectElement,
'blocklyCommentHandleTargetFocused');
}, 0);
}
@@ -1001,21 +999,19 @@ export class WorkspaceCommentSvg extends WorkspaceComment implements
* @internal
*/
blurFocus() {
const comment = this;
this.focused_ = false;
// Defer CSS changes.
setTimeout(function() {
if (comment.disposed_) {
setTimeout(() => {
if (this.disposed_) {
return;
}
comment.textarea_!.blur();
comment.removeFocus();
this.textarea_!.blur();
this.removeFocus();
dom.removeClass(
comment.svgRectTarget_ as SVGRectElement,
'blocklyCommentTargetFocused');
this.svgRectTarget_ as SVGRectElement, 'blocklyCommentTargetFocused');
dom.removeClass(
comment.svgHandleTarget_ as SVGRectElement,
this.svgHandleTarget_ as SVGRectElement,
'blocklyCommentHandleTargetFocused');
}, 0);
}