Skip to content

Commit 3f6ceb5

Browse files
committed
Fix TypeScript 'any' warnings with proper type annotations and block disables
- logger.ts: Replace any[] with unknown[] for variadic args - error-handler.ts: Add eslint-disable with reason codes for generic constraints - config.ts: Fix instance type to allow undefined, remove explicit any casting - config.ts: Remove any type from Zod error mapping - libby-api.ts: Add block eslint-disables for browser context code - libby-api.ts: Replace any[] with proper array type for book list All 35 any warnings resolved - 0 errors, 0 warnings in lint
1 parent 09aade0 commit 3f6ceb5

4 files changed

Lines changed: 27 additions & 14 deletions

File tree

src/core/config.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ const LoggingConfigSchema = z.object({
7373
* 4. Defaults (lowest priority)
7474
*/
7575
export class Config {
76-
private static instance: Config;
76+
private static instance: Config | undefined;
7777

7878
public readonly session: z.infer<typeof SessionConfigSchema>;
7979
public readonly download: z.infer<typeof DownloadConfigSchema>;
@@ -108,7 +108,7 @@ export class Config {
108108
* Reset singleton (mainly for testing)
109109
*/
110110
public static reset(): void {
111-
Config.instance = undefined as any;
111+
Config.instance = undefined;
112112
}
113113

114114
/**
@@ -123,7 +123,7 @@ export class Config {
123123
const result = StealthConfigFileSchema.safeParse(parsed);
124124

125125
if (!result.success) {
126-
const errors = result.error.issues.map((e: any) => `${e.path.join('.')}: ${e.message}`);
126+
const errors = result.error.issues.map((e) => `${e.path.join('.')}: ${e.message}`);
127127
throw new ValidationError(
128128
`Invalid stealth configuration: ${errors.join(', ')}`,
129129
ErrorCode.INVALID_CONFIG
@@ -157,7 +157,7 @@ export class Config {
157157
const result = SessionConfigSchema.safeParse(config);
158158

159159
if (!result.success) {
160-
const errors = result.error.issues.map((e: any) => `${e.path.join('.')}: ${e.message}`);
160+
const errors = result.error.issues.map((e) => `${e.path.join('.')}: ${e.message}`);
161161
throw new ValidationError(
162162
`Invalid session configuration: ${errors.join(', ')}`,
163163
ErrorCode.INVALID_CONFIG
@@ -182,7 +182,7 @@ export class Config {
182182
const result = DownloadConfigSchema.safeParse(config);
183183

184184
if (!result.success) {
185-
const errors = result.error.issues.map((e: any) => `${e.path.join('.')}: ${e.message}`);
185+
const errors = result.error.issues.map((e) => `${e.path.join('.')}: ${e.message}`);
186186
throw new ValidationError(
187187
`Invalid download configuration: ${errors.join(', ')}`,
188188
ErrorCode.INVALID_CONFIG
@@ -205,7 +205,7 @@ export class Config {
205205
const result = BrowserConfigSchema.safeParse(config);
206206

207207
if (!result.success) {
208-
const errors = result.error.issues.map((e: any) => `${e.path.join('.')}: ${e.message}`);
208+
const errors = result.error.issues.map((e) => `${e.path.join('.')}: ${e.message}`);
209209
throw new ValidationError(
210210
`Invalid browser configuration: ${errors.join(', ')}`,
211211
ErrorCode.INVALID_CONFIG
@@ -233,7 +233,7 @@ export class Config {
233233
const result = LoggingConfigSchema.safeParse(config);
234234

235235
if (!result.success) {
236-
const errors = result.error.issues.map((e: any) => `${e.path.join('.')}: ${e.message}`);
236+
const errors = result.error.issues.map((e) => `${e.path.join('.')}: ${e.message}`);
237237
throw new ValidationError(
238238
`Invalid logging configuration: ${errors.join(', ')}`,
239239
ErrorCode.INVALID_CONFIG

src/downloader/libby-api.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ interface BIFData {
4141
}>;
4242
};
4343
};
44+
// Libby's root state object - structure is proprietary and undocumented
45+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
4446
root: any;
4547
}
4648

@@ -67,8 +69,9 @@ export class LibbyAPI {
6769
private async injectParamInterceptor(): Promise<void> {
6870
const page = this.browserManager.getPage();
6971

72+
/* eslint-disable @typescript-eslint/no-explicit-any */
7073
await page.evaluateOnNewDocument(() => {
71-
// Hook JSON.parse to capture crypto parameters
74+
// Hook JSON.parse to capture crypto parameters from Libby's internal API
7275
const oldParse = JSON.parse;
7376
(window as any).__odreadCmptParams = null;
7477

@@ -84,6 +87,7 @@ export class LibbyAPI {
8487
return ret;
8588
};
8689
});
90+
/* eslint-enable @typescript-eslint/no-explicit-any */
8791
}
8892

8993
/**
@@ -93,13 +97,15 @@ export class LibbyAPI {
9397
const page = this.browserManager.getPage();
9498

9599
try {
100+
/* eslint-disable @typescript-eslint/no-explicit-any */
96101
// Wait for BIF object to be available
97102
await page.waitForFunction(() => (window as any).BIF !== undefined, {
98103
timeout: 30000,
99104
});
100105

101106
const metadata = await page.evaluate(() => {
102107
const BIF = (window as any).BIF as BIFData;
108+
/* eslint-enable @typescript-eslint/no-explicit-any */
103109

104110
if (!BIF || !BIF.map) {
105111
return null;
@@ -160,6 +166,7 @@ export class LibbyAPI {
160166
// Inject the param interceptor
161167
await this.injectParamInterceptor();
162168

169+
/* eslint-disable @typescript-eslint/no-explicit-any */
163170
// Wait for both BIF and odreadCmptParams to be available
164171
await page.waitForFunction(
165172
() => (window as any).BIF !== undefined && (window as any).__odreadCmptParams !== null,
@@ -169,6 +176,7 @@ export class LibbyAPI {
169176
const chapters = await page.evaluate(() => {
170177
const BIF = (window as any).BIF as BIFData;
171178
const odreadCmptParams = (window as any).__odreadCmptParams as string[];
179+
/* eslint-enable @typescript-eslint/no-explicit-any */
172180

173181
if (!BIF || !odreadCmptParams) {
174182
return [];
@@ -234,7 +242,7 @@ export class LibbyAPI {
234242

235243
const books = await page.evaluate(() => {
236244
const bookElements = document.querySelectorAll('[data-test-id="shelf-loan"]');
237-
const books: any[] = [];
245+
const books: Array<{ id: string; title: string; authors: string[] }> = [];
238246

239247
bookElements.forEach((elem) => {
240248
try {

src/utils/error-handler.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { retry, RetryOptions } from './retry';
1111
* await safeDownload(chapter, outputPath);
1212
* ```
1313
*/
14+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Required for generic function wrapper
1415
export function withLogging<T extends (...args: any[]) => Promise<any>>(
1516
fn: T,
1617
operationName: string
@@ -43,6 +44,7 @@ export function withLogging<T extends (...args: any[]) => Promise<any>>(
4344
* await resilientDownload(chapter, outputPath);
4445
* ```
4546
*/
47+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Required for generic function wrapper
4648
export function withRetry<T extends (...args: any[]) => Promise<any>>(
4749
fn: T,
4850
options: Partial<RetryOptions> = {}
@@ -65,6 +67,7 @@ export function withRetry<T extends (...args: any[]) => Promise<any>>(
6567
* await safeRetriedDownload(chapter, outputPath);
6668
* ```
6769
*/
70+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Required for generic function wrapper
6871
export function withLoggingAndRetry<T extends (...args: any[]) => Promise<any>>(
6972
fn: T,
7073
operationName: string,
@@ -85,6 +88,7 @@ export function withLoggingAndRetry<T extends (...args: any[]) => Promise<any>>(
8588
* );
8689
* ```
8790
*/
91+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Required for generic function wrapper
8892
export function withErrorHandler<T extends (...args: any[]) => Promise<any>>(
8993
fn: T,
9094
errorHandler: (error: unknown) => Error
@@ -163,6 +167,7 @@ export async function safeParallel<T>(
163167
* }
164168
* ```
165169
*/
170+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Required for generic function wrapper
166171
export function wrapMethod<T extends (...args: any[]) => Promise<any>>(
167172
method: T,
168173
operationName: string

src/utils/logger.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,35 +51,35 @@ class Logger {
5151
this.initialized = true;
5252
}
5353

54-
debug(message: string, ...args: any[]): void {
54+
debug(message: string, ...args: unknown[]): void {
5555
this.ensureInitialized();
5656
if (this.level <= LogLevel.DEBUG) {
5757
console.log(chalk.gray(`[DEBUG] ${message}`), ...args);
5858
}
5959
}
6060

61-
info(message: string, ...args: any[]): void {
61+
info(message: string, ...args: unknown[]): void {
6262
this.ensureInitialized();
6363
if (this.level <= LogLevel.INFO) {
6464
console.log(chalk.blue(`[INFO] ${message}`), ...args);
6565
}
6666
}
6767

68-
success(message: string, ...args: any[]): void {
68+
success(message: string, ...args: unknown[]): void {
6969
this.ensureInitialized();
7070
if (this.level <= LogLevel.INFO) {
7171
console.log(chalk.green(`[SUCCESS] ${message}`), ...args);
7272
}
7373
}
7474

75-
warn(message: string, ...args: any[]): void {
75+
warn(message: string, ...args: unknown[]): void {
7676
this.ensureInitialized();
7777
if (this.level <= LogLevel.WARN) {
7878
console.warn(chalk.yellow(`[WARN] ${message}`), ...args);
7979
}
8080
}
8181

82-
error(message: string, error?: Error | any, ...args: any[]): void {
82+
error(message: string, error?: Error | unknown, ...args: unknown[]): void {
8383
this.ensureInitialized();
8484
if (this.level <= LogLevel.ERROR) {
8585
console.error(chalk.red(`[ERROR] ${message}`), ...args);

0 commit comments

Comments
 (0)