Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Aug 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,6 @@
"@typescript-eslint/no-inferrable-types": ["off"],
// Temporarily disable. 33 problems.
"@typescript-eslint/no-empty-function": ["off"],
// Temporarily disable. 17 problems.
"@typescript-eslint/no-this-alias": ["off"],
// Temporarily disable. 3 problems.
"@typescript-eslint/no-empty-interface": ["off"],
// Temporarily disable. 34 problems.
Expand Down
3 changes: 3 additions & 0 deletions core/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be sweet if this rule were smart enough to only trigger if the alias was used inside a function. ah well.

let block = this;
let prevBlock;
do {
Expand Down Expand Up @@ -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;
Expand All @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions core/block_svg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
Expand Down
6 changes: 2 additions & 4 deletions core/blockly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
23 changes: 11 additions & 12 deletions core/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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();
Expand All @@ -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);
}
}
}
Expand Down Expand Up @@ -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.
Expand Down
5 changes: 2 additions & 3 deletions core/flyout_base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};
}
Expand Down
8 changes: 4 additions & 4 deletions core/rendered_connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -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();
Expand Down
6 changes: 2 additions & 4 deletions core/scrollbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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_);
}

/**
Expand Down
1 change: 1 addition & 0 deletions core/toolbox/category.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()!;
Expand Down
7 changes: 3 additions & 4 deletions core/variable_map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
28 changes: 12 additions & 16 deletions core/workspace_comment_svg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down