style: satisfy lint for quote depth

This commit is contained in:
Peter Steinberger
2026-01-01 10:48:34 +01:00
parent 68ec1d67bf
commit 9b7dab7643
3 changed files with 30 additions and 18 deletions
+6 -2
View File
@@ -245,9 +245,13 @@ function resolveTimeoutFromOptions(options: { timeout?: string | number }): numb
function resolveQuoteDepth(...values: Array<string | number | undefined | null>): number | undefined { function resolveQuoteDepth(...values: Array<string | number | undefined | null>): number | undefined {
for (const value of values) { for (const value of values) {
if (value === undefined || value === null || value === '') continue; if (value === undefined || value === null || value === '') {
continue;
}
const parsed = typeof value === 'number' ? value : Number.parseInt(value, 10); const parsed = typeof value === 'number' ? value : Number.parseInt(value, 10);
if (Number.isFinite(parsed) && parsed >= 0) return Math.floor(parsed); if (Number.isFinite(parsed) && parsed >= 0) {
return Math.floor(parsed);
}
} }
return undefined; return undefined;
} }
+12 -4
View File
@@ -42,8 +42,12 @@ const QUERY_IDS: Record<OperationName, string> = {
const TARGET_QUERY_ID_OPERATIONS = Object.keys(FALLBACK_QUERY_IDS) as Array<OperationName>; const TARGET_QUERY_ID_OPERATIONS = Object.keys(FALLBACK_QUERY_IDS) as Array<OperationName>;
function normalizeQuoteDepth(value?: number): number { function normalizeQuoteDepth(value?: number): number {
if (value === undefined || value === null) return 1; if (value === undefined || value === null) {
if (!Number.isFinite(value)) return 1; return 1;
}
if (!Number.isFinite(value)) {
return 1;
}
return Math.max(0, Math.floor(value)); return Math.max(0, Math.floor(value));
} }
@@ -729,8 +733,12 @@ export class TwitterClient {
} }
private unwrapTweetResult(result: GraphqlTweetResult | undefined): GraphqlTweetResult | undefined { private unwrapTweetResult(result: GraphqlTweetResult | undefined): GraphqlTweetResult | undefined {
if (!result) return undefined; if (!result) {
if (result.tweet) return result.tweet; return undefined;
}
if (result.tweet) {
return result.tweet;
}
return result; return result;
} }
+12 -12
View File
@@ -992,9 +992,9 @@ describe('TwitterClient', () => {
root.quoted_status_result = { result: quoted }; root.quoted_status_result = { result: quoted };
const client = new TwitterClient({ cookies: validCookies }); const client = new TwitterClient({ cookies: validCookies });
const mapped = (client as unknown as { mapTweetResult: (result: unknown) => TweetData | undefined }).mapTweetResult( const mapped = (
root, client as unknown as { mapTweetResult: (result: unknown) => TweetData | undefined }
); ).mapTweetResult(root);
expect(mapped?.quotedTweet?.id).toBe('2'); expect(mapped?.quotedTweet?.id).toBe('2');
expect(mapped?.quotedTweet?.quotedTweet).toBeUndefined(); expect(mapped?.quotedTweet?.quotedTweet).toBeUndefined();
@@ -1006,9 +1006,9 @@ describe('TwitterClient', () => {
root.quoted_status_result = { result: quoted }; root.quoted_status_result = { result: quoted };
const client = new TwitterClient({ cookies: validCookies, quoteDepth: 0 }); const client = new TwitterClient({ cookies: validCookies, quoteDepth: 0 });
const mapped = (client as unknown as { mapTweetResult: (result: unknown) => TweetData | undefined }).mapTweetResult( const mapped = (
root, client as unknown as { mapTweetResult: (result: unknown) => TweetData | undefined }
); ).mapTweetResult(root);
expect(mapped?.quotedTweet).toBeUndefined(); expect(mapped?.quotedTweet).toBeUndefined();
}); });
@@ -1021,9 +1021,9 @@ describe('TwitterClient', () => {
root.quoted_status_result = { result: quoted1 }; root.quoted_status_result = { result: quoted1 };
const client = new TwitterClient({ cookies: validCookies, quoteDepth: 2 }); const client = new TwitterClient({ cookies: validCookies, quoteDepth: 2 });
const mapped = (client as unknown as { mapTweetResult: (result: unknown) => TweetData | undefined }).mapTweetResult( const mapped = (
root, client as unknown as { mapTweetResult: (result: unknown) => TweetData | undefined }
); ).mapTweetResult(root);
expect(mapped?.quotedTweet?.id).toBe('2'); expect(mapped?.quotedTweet?.id).toBe('2');
expect(mapped?.quotedTweet?.quotedTweet?.id).toBe('3'); expect(mapped?.quotedTweet?.quotedTweet?.id).toBe('3');
@@ -1041,9 +1041,9 @@ describe('TwitterClient', () => {
}; };
const client = new TwitterClient({ cookies: validCookies }); const client = new TwitterClient({ cookies: validCookies });
const mapped = (client as unknown as { mapTweetResult: (result: unknown) => TweetData | undefined }).mapTweetResult( const mapped = (
root, client as unknown as { mapTweetResult: (result: unknown) => TweetData | undefined }
); ).mapTweetResult(root);
expect(mapped?.quotedTweet?.id).toBe('2'); expect(mapped?.quotedTweet?.id).toBe('2');
}); });