style: satisfy lint for quote depth
This commit is contained in:
+6
-2
@@ -245,9 +245,13 @@ function resolveTimeoutFromOptions(options: { timeout?: string | number }): numb
|
||||
|
||||
function resolveQuoteDepth(...values: Array<string | number | undefined | null>): number | undefined {
|
||||
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);
|
||||
if (Number.isFinite(parsed) && parsed >= 0) return Math.floor(parsed);
|
||||
if (Number.isFinite(parsed) && parsed >= 0) {
|
||||
return Math.floor(parsed);
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@@ -42,8 +42,12 @@ const QUERY_IDS: Record<OperationName, string> = {
|
||||
const TARGET_QUERY_ID_OPERATIONS = Object.keys(FALLBACK_QUERY_IDS) as Array<OperationName>;
|
||||
|
||||
function normalizeQuoteDepth(value?: number): number {
|
||||
if (value === undefined || value === null) return 1;
|
||||
if (!Number.isFinite(value)) return 1;
|
||||
if (value === undefined || value === null) {
|
||||
return 1;
|
||||
}
|
||||
if (!Number.isFinite(value)) {
|
||||
return 1;
|
||||
}
|
||||
return Math.max(0, Math.floor(value));
|
||||
}
|
||||
|
||||
@@ -729,8 +733,12 @@ export class TwitterClient {
|
||||
}
|
||||
|
||||
private unwrapTweetResult(result: GraphqlTweetResult | undefined): GraphqlTweetResult | undefined {
|
||||
if (!result) return undefined;
|
||||
if (result.tweet) return result.tweet;
|
||||
if (!result) {
|
||||
return undefined;
|
||||
}
|
||||
if (result.tweet) {
|
||||
return result.tweet;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -992,9 +992,9 @@ describe('TwitterClient', () => {
|
||||
root.quoted_status_result = { result: quoted };
|
||||
|
||||
const client = new TwitterClient({ cookies: validCookies });
|
||||
const mapped = (client as unknown as { mapTweetResult: (result: unknown) => TweetData | undefined }).mapTweetResult(
|
||||
root,
|
||||
);
|
||||
const mapped = (
|
||||
client as unknown as { mapTweetResult: (result: unknown) => TweetData | undefined }
|
||||
).mapTweetResult(root);
|
||||
|
||||
expect(mapped?.quotedTweet?.id).toBe('2');
|
||||
expect(mapped?.quotedTweet?.quotedTweet).toBeUndefined();
|
||||
@@ -1006,9 +1006,9 @@ describe('TwitterClient', () => {
|
||||
root.quoted_status_result = { result: quoted };
|
||||
|
||||
const client = new TwitterClient({ cookies: validCookies, quoteDepth: 0 });
|
||||
const mapped = (client as unknown as { mapTweetResult: (result: unknown) => TweetData | undefined }).mapTweetResult(
|
||||
root,
|
||||
);
|
||||
const mapped = (
|
||||
client as unknown as { mapTweetResult: (result: unknown) => TweetData | undefined }
|
||||
).mapTweetResult(root);
|
||||
|
||||
expect(mapped?.quotedTweet).toBeUndefined();
|
||||
});
|
||||
@@ -1021,9 +1021,9 @@ describe('TwitterClient', () => {
|
||||
root.quoted_status_result = { result: quoted1 };
|
||||
|
||||
const client = new TwitterClient({ cookies: validCookies, quoteDepth: 2 });
|
||||
const mapped = (client as unknown as { mapTweetResult: (result: unknown) => TweetData | undefined }).mapTweetResult(
|
||||
root,
|
||||
);
|
||||
const mapped = (
|
||||
client as unknown as { mapTweetResult: (result: unknown) => TweetData | undefined }
|
||||
).mapTweetResult(root);
|
||||
|
||||
expect(mapped?.quotedTweet?.id).toBe('2');
|
||||
expect(mapped?.quotedTweet?.quotedTweet?.id).toBe('3');
|
||||
@@ -1041,9 +1041,9 @@ describe('TwitterClient', () => {
|
||||
};
|
||||
|
||||
const client = new TwitterClient({ cookies: validCookies });
|
||||
const mapped = (client as unknown as { mapTweetResult: (result: unknown) => TweetData | undefined }).mapTweetResult(
|
||||
root,
|
||||
);
|
||||
const mapped = (
|
||||
client as unknown as { mapTweetResult: (result: unknown) => TweetData | undefined }
|
||||
).mapTweetResult(root);
|
||||
|
||||
expect(mapped?.quotedTweet?.id).toBe('2');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user