eslint: ban self usage
We've migrated most code to use arrow funcs which gives access to
|this|, but we still have some legacy logic in hterm. Clean that
up and ban it in the linter to prevent regressions.
This process also allowed some dead funcs to be detected!
Change-Id: Idd9d40e99b6f50463dcbacf9198d49bcf1262c0f
Reviewed-on: https://chromium-review.googlesource.com/c/apps/libapps/+/2144947
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Joel Hockey <joelhockey@chromium.org>
diff --git a/hterm/js/hterm_terminal.js b/hterm/js/hterm_terminal.js
index f42de62..8bb9bbe 100644
--- a/hterm/js/hterm_terminal.js
+++ b/hterm/js/hterm_terminal.js
@@ -781,18 +781,17 @@
environment = {};
}
- var self = this;
this.command = new commandClass(
{
commandName: commandName,
args: args,
io: this.io.push(),
environment: environment,
- onExit: function(code) {
- self.io.pop();
- self.uninstallKeyboard();
- self.div_.dispatchEvent(new CustomEvent('terminal-closing'));
- if (self.prefs_.get('close-on-exit')) {
+ onExit: (code) => {
+ this.io.pop();
+ this.uninstallKeyboard();
+ this.div_.dispatchEvent(new CustomEvent('terminal-closing'));
+ if (this.prefs_.get('close-on-exit')) {
window.close();
}
},
@@ -2640,11 +2639,10 @@
return;
}
- var self = this;
- this.timeouts_.redraw = setTimeout(function() {
- delete self.timeouts_.redraw;
- self.scrollPort_.redraw_();
- }, 0);
+ this.timeouts_.redraw = setTimeout(() => {
+ delete this.timeouts_.redraw;
+ this.scrollPort_.redraw_();
+ });
};
/**
@@ -2661,11 +2659,10 @@
return;
}
- var self = this;
- this.timeouts_.scrollDown = setTimeout(function() {
- delete self.timeouts_.scrollDown;
- self.scrollPort_.scrollRowToBottom(self.getRowCount());
- }, 10);
+ this.timeouts_.scrollDown = setTimeout(() => {
+ delete this.timeouts_.scrollDown;
+ this.scrollPort_.scrollRowToBottom(this.getRowCount());
+ }, 10);
};
/**
@@ -2788,10 +2785,7 @@
hterm.Terminal.prototype.ringBell = function() {
this.cursorNode_.style.backgroundColor = 'rgb(var(--hterm-foreground-color))';
- var self = this;
- setTimeout(function() {
- self.restyleCursor_();
- }, 200);
+ setTimeout(() => this.restyleCursor_(), 200);
// bellSquelchTimeout_ affects both audio and notification bells.
if (this.bellSquelchTimeout_) {
@@ -2811,7 +2805,7 @@
var n = hterm.notify();
this.bellNotificationList_.push(n);
// TODO: Should we try to raise the window here?
- n.onclick = function() { self.closeBellNotifications_(); };
+ n.onclick = () => this.closeBellNotifications_();
}
};
@@ -3152,11 +3146,10 @@
cursorLineText, cursorRowIndex, cursorColumnIndex);
}
- var self = this;
- this.timeouts_.syncCursor = setTimeout(function() {
- self.syncCursorPosition_();
- delete self.timeouts_.syncCursor;
- }, 0);
+ this.timeouts_.syncCursor = setTimeout(() => {
+ this.syncCursorPosition_();
+ delete this.timeouts_.syncCursor;
+ });
};
/**