From 8dc2e39527d7a2b4d3bb6fbc129a79ba0776b0c2 Mon Sep 17 00:00:00 2001 From: CDeltakai Date: Thu, 15 May 2025 20:26:12 +1000 Subject: [PATCH 1/4] fix: removing unnecessary eslint disable comments --- src/CreateDestroy.ts | 2 +- src/CreateDestroyStartStop.ts | 2 +- src/StartStop.ts | 2 +- src/utils.ts | 1 - 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/CreateDestroy.ts b/src/CreateDestroy.ts index 1a2aaeb..3d38dd1 100644 --- a/src/CreateDestroy.ts +++ b/src/CreateDestroy.ts @@ -118,7 +118,7 @@ function ready( } else if (descriptor.set != null) { kind = 'set'; } - const f: Function = descriptor[kind]; // eslint-disable-line @typescript-eslint/ban-types + const f: Function = descriptor[kind]; if (typeof f !== 'function') { throw new TypeError(`${key} is not a function`); } diff --git a/src/CreateDestroyStartStop.ts b/src/CreateDestroyStartStop.ts index 10b181a..8835ce5 100644 --- a/src/CreateDestroyStartStop.ts +++ b/src/CreateDestroyStartStop.ts @@ -238,7 +238,7 @@ function ready( } else if (descriptor.set != null) { kind = 'set'; } - const f: Function = descriptor[kind]; // eslint-disable-line @typescript-eslint/ban-types + const f: Function = descriptor[kind]; if (typeof f !== 'function') { throw new TypeError(`${key} is not a function`); } diff --git a/src/StartStop.ts b/src/StartStop.ts index fee74e5..f5e6836 100644 --- a/src/StartStop.ts +++ b/src/StartStop.ts @@ -159,7 +159,7 @@ function ready( } else if (descriptor.set != null) { kind = 'set'; } - const f: Function = descriptor[kind]; // eslint-disable-line @typescript-eslint/ban-types + const f: Function = descriptor[kind]; if (typeof f !== 'function') { throw new TypeError(`${key} is not a function`); } diff --git a/src/utils.ts b/src/utils.ts index ea3c082..26366ae 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -42,7 +42,6 @@ function promise(): PromiseDeconstructed { * This function rewrites the stack trace according to where the wrapped * function is called, giving a more useful stack trace */ -// eslint-disable-next-line @typescript-eslint/ban-types function resetStackTrace(error: Error, decorated?: Function): void { if (error.stack != null) { const stackTitle = error.stack.slice(0, error.stack.indexOf('\n') + 1); From 5c8bd8e9767e085bd71b549ba3696cd0a367e338 Mon Sep 17 00:00:00 2001 From: CDeltakai Date: Thu, 15 May 2025 20:30:44 +1000 Subject: [PATCH 2/4] fix: intentionally discarding returned values with void as we are only interested in its side effect. also silences the linter error assosciated with it --- tests/CreateDestroy.test.ts | 2 +- tests/CreateDestroyStartStop.test.ts | 4 ++-- tests/StartStop.test.ts | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/CreateDestroy.test.ts b/tests/CreateDestroy.test.ts index a8da27f..467252c 100644 --- a/tests/CreateDestroy.test.ts +++ b/tests/CreateDestroy.test.ts @@ -377,7 +377,7 @@ describe('CreateDestroy', () => { (async () => { const x = new X(); const destroy = x.destroy(); - x.a; + void x.a; await destroy; })(), ).resolves.toBeUndefined(); diff --git a/tests/CreateDestroyStartStop.test.ts b/tests/CreateDestroyStartStop.test.ts index b379629..2af5bec 100644 --- a/tests/CreateDestroyStartStop.test.ts +++ b/tests/CreateDestroyStartStop.test.ts @@ -596,7 +596,7 @@ describe('CreateDestroyStartStop', () => { await expect( (async () => { const start = x.start(); - x.a; + void x.a; await start; })(), ).rejects.toThrow(ErrorAsyncInitNotRunning); @@ -614,7 +614,7 @@ describe('CreateDestroyStartStop', () => { await expect( (async () => { const stop = x.stop(); - x.a; + void x.a; await stop; })(), ).resolves.toBeUndefined(); diff --git a/tests/StartStop.test.ts b/tests/StartStop.test.ts index 0d2634f..b038a25 100644 --- a/tests/StartStop.test.ts +++ b/tests/StartStop.test.ts @@ -311,7 +311,7 @@ describe('StartStop', () => { await expect( (async () => { const start = x.start(); - x.a; + void x.a; await start; })(), ).rejects.toThrow(ErrorAsyncInitNotRunning); @@ -329,7 +329,7 @@ describe('StartStop', () => { await expect( (async () => { const stop = x.stop(); - x.a; + void x.a; await stop; })(), ).resolves.toBeUndefined(); From 1ce716883875cc7bcc257853b6604094da3caf37 Mon Sep 17 00:00:00 2001 From: CDeltakai Date: Fri, 16 May 2025 12:54:45 +1000 Subject: [PATCH 3/4] Fix: Replaced the blanket Function type with AnyFn = (...args: unknown[]) => unknown. This silences no-unsafe-function-type linting rule and restores minimal type-safety (no implicit any) while leaving runtime behaviour untouched. --- src/CreateDestroy.ts | 3 ++- src/CreateDestroyStartStop.ts | 3 ++- src/StartStop.ts | 3 ++- src/utils.ts | 5 ++++- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/CreateDestroy.ts b/src/CreateDestroy.ts index 3d38dd1..8d2cd23 100644 --- a/src/CreateDestroy.ts +++ b/src/CreateDestroy.ts @@ -118,7 +118,8 @@ function ready( } else if (descriptor.set != null) { kind = 'set'; } - const f: Function = descriptor[kind]; + type AnyFn = (...args: Array) => unknown; + const f = descriptor[kind] as AnyFn; if (typeof f !== 'function') { throw new TypeError(`${key} is not a function`); } diff --git a/src/CreateDestroyStartStop.ts b/src/CreateDestroyStartStop.ts index 8835ce5..222c6bd 100644 --- a/src/CreateDestroyStartStop.ts +++ b/src/CreateDestroyStartStop.ts @@ -238,7 +238,8 @@ function ready( } else if (descriptor.set != null) { kind = 'set'; } - const f: Function = descriptor[kind]; + type AnyFn = (...args: Array) => unknown; + const f = descriptor[kind] as AnyFn; if (typeof f !== 'function') { throw new TypeError(`${key} is not a function`); } diff --git a/src/StartStop.ts b/src/StartStop.ts index f5e6836..0ab1c67 100644 --- a/src/StartStop.ts +++ b/src/StartStop.ts @@ -159,7 +159,8 @@ function ready( } else if (descriptor.set != null) { kind = 'set'; } - const f: Function = descriptor[kind]; + type AnyFn = (...args: Array) => unknown; + const f = descriptor[kind] as AnyFn; if (typeof f !== 'function') { throw new TypeError(`${key} is not a function`); } diff --git a/src/utils.ts b/src/utils.ts index 26366ae..42aa0e2 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -42,7 +42,10 @@ function promise(): PromiseDeconstructed { * This function rewrites the stack trace according to where the wrapped * function is called, giving a more useful stack trace */ -function resetStackTrace(error: Error, decorated?: Function): void { +function resetStackTrace( + error: Error, + decorated?: (...args: Array) => unknown, +): void { if (error.stack != null) { const stackTitle = error.stack.slice(0, error.stack.indexOf('\n') + 1); if (hasCaptureStackTrace) { From 8cafbe79a15f1630e1142d5de5ccad3adfc5cf5b Mon Sep 17 00:00:00 2001 From: CDeltakai Date: Fri, 16 May 2025 13:25:20 +1000 Subject: [PATCH 4/4] feat: added AnyFn type to types.ts to replace repeated usage --- src/CreateDestroy.ts | 3 +-- src/CreateDestroyStartStop.ts | 3 +-- src/types.ts | 4 +++- src/utils.ts | 7 ++----- 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/CreateDestroy.ts b/src/CreateDestroy.ts index 8d2cd23..75bbca5 100644 --- a/src/CreateDestroy.ts +++ b/src/CreateDestroy.ts @@ -1,4 +1,4 @@ -import type { Status, Class } from './types.js'; +import type { Status, Class, AnyFn } from './types.js'; import { Evented } from '@matrixai/events'; import { RWLockWriter } from '@matrixai/async-locks'; import { @@ -118,7 +118,6 @@ function ready( } else if (descriptor.set != null) { kind = 'set'; } - type AnyFn = (...args: Array) => unknown; const f = descriptor[kind] as AnyFn; if (typeof f !== 'function') { throw new TypeError(`${key} is not a function`); diff --git a/src/CreateDestroyStartStop.ts b/src/CreateDestroyStartStop.ts index 222c6bd..d9770c8 100644 --- a/src/CreateDestroyStartStop.ts +++ b/src/CreateDestroyStartStop.ts @@ -1,4 +1,4 @@ -import type { Status, Class } from './types.js'; +import type { Status, Class, AnyFn } from './types.js'; import { Evented } from '@matrixai/events'; import { RWLockWriter } from '@matrixai/async-locks'; import { @@ -238,7 +238,6 @@ function ready( } else if (descriptor.set != null) { kind = 'set'; } - type AnyFn = (...args: Array) => unknown; const f = descriptor[kind] as AnyFn; if (typeof f !== 'function') { throw new TypeError(`${key} is not a function`); diff --git a/src/types.ts b/src/types.ts index d78e524..e3666fc 100644 --- a/src/types.ts +++ b/src/types.ts @@ -11,4 +11,6 @@ type Status = 'destroying' | 'starting' | 'stopping' | null; type Class = new (...args: any[]) => T; -export type { PromiseDeconstructed, Status, Class }; +type AnyFn = (...args: Array) => unknown; + +export type { PromiseDeconstructed, Status, Class, AnyFn }; diff --git a/src/utils.ts b/src/utils.ts index 42aa0e2..9afd16b 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,4 +1,4 @@ -import type { PromiseDeconstructed } from './types.js'; +import type { AnyFn, PromiseDeconstructed } from './types.js'; /** * Symbols prevents name clashes with decorated classes @@ -42,10 +42,7 @@ function promise(): PromiseDeconstructed { * This function rewrites the stack trace according to where the wrapped * function is called, giving a more useful stack trace */ -function resetStackTrace( - error: Error, - decorated?: (...args: Array) => unknown, -): void { +function resetStackTrace(error: Error, decorated?: AnyFn): void { if (error.stack != null) { const stackTitle = error.stack.slice(0, error.stack.indexOf('\n') + 1); if (hasCaptureStackTrace) {