From cb6ee7a5a304c1d6a94af45636b33e87ee47ca14 Mon Sep 17 00:00:00 2001 From: Bryan Kendall Date: Wed, 8 Jul 2026 10:46:14 -0700 Subject: [PATCH 1/2] refactor: resolve @typescript-eslint/no-this-alias warnings Converts methods and callbacks in activator.js and responder.js to arrow functions to preserve lexical this scoping, resolving all occurrences of no-this-alias (const self = this) across the codebase. --- src/activator.js | 14 +++++--------- src/responder.js | 27 ++++++++++----------------- 2 files changed, 15 insertions(+), 26 deletions(-) diff --git a/src/activator.js b/src/activator.js index 737e2a00..8226d123 100644 --- a/src/activator.js +++ b/src/activator.js @@ -37,8 +37,6 @@ const Activator = function (spec, provider) { }; Activator.prototype.buildStack = function () { - const self = this; - const stack = this.spec.stack.slice(0); Object.entries(this.spec.before ?? {}).forEach(([name, wares]) => { stack.splice(...[stack.indexOf(name), 0].concat(wares)); @@ -49,19 +47,17 @@ Activator.prototype.buildStack = function () { }); return stack.map((ware) => { - return typeof ware === "function" ? ware : middleware[ware](self.spec); + return typeof ware === "function" ? ware : middleware[ware](this.spec); }); }; Activator.prototype.build = function () { - const self = this; - - return function (req, res, next) { - promiseback(self.awaitConfig, 2)(req, res).then((config) => { + return (req, res, next) => { + promiseback(this.awaitConfig, 2)(req, res).then((config) => { req.superstatic = config ?? {}; - const stack = self.stack.slice(0).reverse(); - const _run = function () { + const stack = this.stack.slice(0).reverse(); + const _run = () => { if (!stack.length) { return next(); } diff --git a/src/responder.js b/src/responder.js index 066fd7b2..e7dde84a 100644 --- a/src/responder.js +++ b/src/responder.js @@ -58,7 +58,6 @@ Responder.prototype.isNotModified = function (stats) { }; Responder.prototype.handle = function (item, next) { - const self = this; return this._handle(item) .then((responded) => { if (!responded && next) { @@ -67,7 +66,7 @@ Responder.prototype.handle = function (item, next) { return responded; }) .catch((err) => { - return self.handleError(err); + return this.handleError(err); }); }; @@ -104,10 +103,9 @@ Responder.prototype.handleError = function (err) { }; Responder.prototype.handleStack = function (stack) { - const self = this; if (stack.length) { return this._handle(stack.shift()).then((responded) => { - return responded ? true : self.handleStack(stack); + return responded ? true : this.handleStack(stack); }); } @@ -115,23 +113,20 @@ Responder.prototype.handleStack = function (stack) { }; Responder.prototype.handleFile = function (file) { - const self = this; return this.provider(this.req, file.file).then((result) => { if (!result) { return false; } - if (self.isNotModified(result)) { - return self.handleNotModified(result); + if (this.isNotModified(result)) { + return this.handleNotModified(result); } - return self.handleFileStream(file, result); + return this.handleFileStream(file, result); }); }; Responder.prototype.handleFileStream = function (file, result) { - const self = this; - this.streamedFile = file; this.res.statusCode = file.status ?? 200; if (this.res.statusCode === 200 && file.file === this.config.errorPage) { @@ -156,10 +151,10 @@ Responder.prototype.handleFileStream = function (file, result) { if (this.compressor) { this.compressor(this.req, this.res, () => { - result.stream.pipe(self.res); + result.stream.pipe(this.res); }); } else { - result.stream.pipe(self.res); + result.stream.pipe(this.res); } return awaitFinished(this.res).then(() => { @@ -186,24 +181,22 @@ Responder.prototype.handleRedirect = function (redirect) { }; Responder.prototype.handleMiddleware = function (middleware) { - const self = this; return new Promise((resolve) => { - middleware(self.req, self.res, () => { + middleware(this.req, this.res, () => { resolve(false); }); }); }; Responder.prototype.handleRewrite = function (item) { - const self = this; if (item.rewrite.destination) { - return self.handleFile({ file: item.rewrite.destination }); + return this.handleFile({ file: item.rewrite.destination }); } for (const key in this.rewriters) { if (item.rewrite[key]) { return this.rewriters[key](item.rewrite, this).then((result) => { - return self._handle(result); + return this._handle(result); }); } } From 6f16c9dfb551aaddb8528676cfb1ccb6faca4eac Mon Sep 17 00:00:00 2001 From: Bryan Kendall Date: Wed, 8 Jul 2026 10:47:42 -0700 Subject: [PATCH 2/2] config: promote @typescript-eslint/no-this-alias to error Removes the rule override from the eslint configuration to allow the rule to default to error, preventing future regressions. --- eslint.config.mjs | 1 - 1 file changed, 1 deletion(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index 7a027a53..3ea3754d 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -60,7 +60,6 @@ export default [ { files: ["**/*.js"], rules: { - "@typescript-eslint/no-this-alias": "warn", // TODO(bkendall): remove allow to error. "@typescript-eslint/no-unsafe-argument": "warn", // TODO(bkendall): remove allow to error. "@typescript-eslint/no-unsafe-assignment": "warn", // TODO(bkendall): remove allow to error. "@typescript-eslint/no-unsafe-call": "warn", // TODO(bkendall): remove allow to error.