ronantakizawa/codereview-bench huggingface dataset:
Repository: discordjs/discord.js
File: packages/formatters/src/formatters.ts (TypeScript)

Code before:
	emojiId,
	animated,
	name,
}: Required<FormatEmojiOptions<EmojiId, Name>>): `<:${Name}:${EmojiId}>` | `<a:${Name}:${EmojiId}>`;

export function formatEmoji<EmojiId extends Snowflake, Name extends string>(
	emojiIdOrOptions: EmojiId | FormatEmojiOptions<EmojiId, Name>,
	animated?: boolean,
	name?: Name,
): `<:${string}:${EmojiId}>` | `<a:${string}:${EmojiId}>` {
	const options =
		typeof emojiIdOrOptions === 'object'
			? emojiIdOrOptions
			: {
					emojiId: emojiIdOrOptions,
					name: name ?? '_',
					animated: animated ?? false,
				};

	const { emojiId, animated: isAnimated, name: emojiName } = options;

	return `<${isAnimated ? 'a' : ''}:${emojiName ?? '_'}:${emojiId}>`;
}

/**
 * The options for formatting an emoji
 */
interface FormatEmojiOptions<EmojiId extends Snowflake, Name extends string> {
	/**
	 * Whether the emoji is animated
	 */
	animated?: boolean;
	/**
	 * The emoji id to format
	 */
	emojiId: EmojiId;
	/**
	 * The name of the emoji
	 */
	name?: Name;
}

/**
 * Formats a channel link for a direct message channel.
 *
 * @typeParam ChannelId - This is inferred by the supplied channel id
 * @param channelId - The channel's id
 */
export function channelLink<ChannelId extends Snowflake>(
	channelId: ChannelId,
): `https://discord.com/channels/@me/${ChannelId}`;

Review comment (suggestion):
```suggestion
 * The options for formatting an emoji.
```

Code after:
): `<:${EmojiName}:${EmojiId}>`;

/**
 * Formats an emoji id and name into a fully qualified emoji identifier.
 *
 * @typeParam EmojiId - This is inferred by the supplied emoji id
 * @typeParam EmojiName - This is inferred by the supplied emoji name
 * @param options - The options for formatting an emoji
 */
export function formatEmoji<EmojiId extends Snowflake, EmojiName extends string>(
	options: FormatEmojiOptions<EmojiId, EmojiName>,
): `<:${EmojiName}:${EmojiId}>` | `<a:${EmojiName}:${EmojiId}>`;

export function formatEmoji<EmojiId extends Snowflake, EmojiName extends string>(
	emojiIdOrOptions: EmojiId | FormatEmojiOptions<EmojiId, EmojiName>,
	animated?: boolean,
): `<:${string}:${EmojiId}>` | `<a:${string}:${EmojiId}>` {
	const options =
		typeof emojiIdOrOptions === 'string'
			? {
					id: emojiIdOrOptions,
					animated: animated ?? false,
				}
			: emojiIdOrOptions;

	const { id, animated: isAnimated, name: emojiName } = options;

	return `<${isAnimated ? 'a' : ''}:${emojiName ?? '_'}:${id}>`;
}

/**
 * The options for formatting an emoji.
 *
 * @typeParam EmojiId - This is inferred by the supplied emoji id
 * @typeParam EmojiName - This is inferred by the supplied emoji name
 */
export interface FormatEmojiOptions<EmojiId extends Snowflake, EmojiName extends string> {
	/**
	 * Whether the emoji is animated
	 */
	animated?: boolean;
	/**
	 * The emoji id to format
	 */
	id: EmojiId;
	/**
	 * The name of the emoji
	 */
	name?: EmojiName;
}
Repository: discordjs/discord.js
File: packages/scripts/src/generateIndex.ts (TypeScript)

Code before:
export function tryResolveSummaryText(item: ApiDeclaredItem): string | null {
	if (!item?.tsdocComment) {
		return null;
	}

	const { summarySection } = item.tsdocComment;

	let retVal = '';

	// Recursively visit the nodes in the summary section.
	const visitTSDocNode = (node: DocNode) => {
		switch (node.kind) {
			case DocNodeKind.CodeSpan:
				retVal += (node as DocCodeSpan).code;
				break;
			case DocNodeKind.PlainText:
				retVal += (node as DocPlainText).text;
				break;
			case DocNodeKind.LinkTag: {
				const { codeDestination, urlDestination, linkText } = node as DocLinkTag;
				if (codeDestination) {
					const declarationReference = item.getAssociatedModel()?.resolveDeclarationReference(codeDestination, item);
					if (declarationReference?.resolvedApiItem) {
						const foundItem = declarationReference?.resolvedApiItem;
						retVal += linkText ?? foundItem?.displayName;
						break;
					}

					const typeName = codeDestination.memberReferences.map((ref) => ref.memberIdentifier!.identifier).join('.');
					retVal += typeName;
					break;
				}

				retVal += linkText ?? urlDestination;
				break;
			}

			case DocNodeKind.Section:
			case DocNodeKind.Paragraph: {
				for (const child of (node as DocParagraph).nodes) {
					visitTSDocNode(child);
				}

				break;
			}

			default: // We'll ignore all other nodes.
				break;
		}
	};


Review comment (suggestion):
Might be personal preference, but I‘d prefer `if {..} else {..}` over `if {.. break;} …` to make it easier to see what are the two alternatives 

Code after:
export function tryResolveSummaryText(item: ApiDeclaredItem): string | null {
	if (!item?.tsdocComment) {
		return null;
	}

	const { summarySection } = item.tsdocComment;

	let retVal = '';

	// Recursively visit the nodes in the summary section.
	const visitTSDocNode = (node: DocNode) => {
		switch (node.kind) {
			case DocNodeKind.CodeSpan:
				retVal += (node as DocCodeSpan).code;
				break;
			case DocNodeKind.PlainText:
				retVal += (node as DocPlainText).text;
				break;
			case DocNodeKind.LinkTag: {
				const { codeDestination, urlDestination, linkText } = node as DocLinkTag;
				if (codeDestination) {
					const declarationReference = item.getAssociatedModel()?.resolveDeclarationReference(codeDestination, item);
					if (declarationReference?.resolvedApiItem) {
						const foundItem = declarationReference.resolvedApiItem;
						retVal += linkText ?? foundItem.displayName;
					} else {
						const typeName = codeDestination.memberReferences.map((ref) => ref.memberIdentifier?.identifier).join('.');
						retVal += typeName;
					}
				} else {
					retVal += linkText ?? urlDestination;
				}

				break;
			}

			case DocNodeKind.Section:
			case DocNodeKind.Paragraph: {
				for (const child of (node as DocParagraph).nodes) {
					visitTSDocNode(child);
				}

				break;
			}

			default: // We'll ignore all other nodes.
				break;
		}
	};

	for (const node of summarySection.nodes) {
Repository: discordjs/discord.js
File: packages/rest/src/lib/utils/types.ts (TypeScript)

Code before:
	 */
	scope: 'global' | 'shared' | 'user';
	/**
	 * The time, in milliseconds, that will need to pass before the sublimit lock for the route resets, and requests that fall under a sublimit
	 * can be retried
	 *
	 * This is only present on certain sublimits, and `0` otherwise
	 */
	sublimitTimeout: number;
	/**
	 * The time, in milliseconds, until the route's request-lock is reset
	 */
	timeToReset: number;
	/**
	 * The full URL for this request
	 */
	url: string;
}

/**
 * A function that determines whether the rate limit hit should throw an Error
 */
export type RateLimitQueueFilter = (rateLimitData: RateLimitData) => Awaitable<boolean>;

/**
 * A function that determines the ratelimit offset for a given request.
 */
export type GetRateLimitOffsetFunction = (route: string) => number;

export interface APIRequest {
	/**
	 * The data that was used to form the body of this request
	 */
	data: HandlerRequestData;
	/**
	 * The HTTP method used in this request
	 */
	method: string;
	/**
	 * Additional HTTP options for this request
	 */
	options: RequestInit;
	/**
	 * The full path used to make the request
	 */
	path: RouteLike;
	/**
	 * The number of times this request has been attempted
	 */
	retries: number;
	/**

Review comment (suggestion):
```suggestion
 * A function that determines the rate limit offset for a given request.
```

Code after:
	 */
	scope: 'global' | 'shared' | 'user';
	/**
	 * The time, in milliseconds, that will need to pass before the sublimit lock for the route resets, and requests that fall under a sublimit
	 * can be retried
	 *
	 * This is only present on certain sublimits, and `0` otherwise
	 */
	sublimitTimeout: number;
	/**
	 * The time, in milliseconds, until the route's request-lock is reset
	 */
	timeToReset: number;
	/**
	 * The full URL for this request
	 */
	url: string;
}

/**
 * A function that determines whether the rate limit hit should throw an Error
 */
export type RateLimitQueueFilter = (rateLimitData: RateLimitData) => Awaitable<boolean>;

/**
 * A function that determines the rate limit offset for a given request.
 */
export type GetRateLimitOffsetFunction = (route: string) => number;

export interface APIRequest {
	/**
	 * The data that was used to form the body of this request
	 */
	data: HandlerRequestData;
	/**
	 * The HTTP method used in this request
	 */
	method: string;
	/**
	 * Additional HTTP options for this request
	 */
	options: RequestInit;
	/**
	 * The full path used to make the request
	 */
	path: RouteLike;
	/**
	 * The number of times this request has been attempted
	 */
	retries: number;
	/**
Repository: discordjs/discord.js
File: packages/discord.js/src/structures/Embed.js (JavaScript)

Code before:

  /**
   * Returns the API-compatible JSON for this embed.
   * @returns {APIEmbed}
   */
  toJSON() {
    return { ...this.data };
  }

  /**
   * Whether the given embeds are equal.
   * @param {Embed|APIEmbed} other The embed to compare against
   * @returns {boolean}
   */
  equals(other) {
    if (other instanceof Embed) {
      return isEqual(this.data, other.data);
    }

    return (
      this.color === (other.color ?? null) &&
      this.description === (other.description ?? null) &&
      this.title === (other.title ?? null) &&
      this.url === (other.url ?? null) &&
      (this.timestamp ? new Date(this.timestamp).getTime() : null) ===
        (other.timestamp ? new Date(other.timestamp).getTime() : null) &&
      this.image?.url === other.image?.url &&
      this.thumbnail?.url === other.thumbnail?.url &&
      this.video?.url === other.video?.url &&
      isEqual(this.fields, other.fields?.map(field => ({ ...field, inline: field.inline ?? false })) ?? []) &&
      isEqual(this.provider, other.provider ?? null) &&
      isEqual(
        { icon_url: this.author?.iconURL, name: this.author?.name, url: this.author?.url },
        { icon_url: other.author?.icon_url, name: other.author?.name, url: other.author?.url },
      ) &&
      isEqual(
        { icon_url: this.footer?.iconURL, text: this.footer?.text },
        { icon_url: other.footer?.icon_url, text: other.footer?.text },
      )
    );
  }
}

module.exports = Embed;


Review comment (suggestion):
```suggestion
      this.timestamp === (other.timestamp ?? null) &&
```


Code after:

  /**
   * Returns the API-compatible JSON for this embed.
   * @returns {APIEmbed}
   */
  toJSON() {
    return { ...this.data };
  }

  /**
   * Whether the given embeds are equal.
   * @param {Embed|APIEmbed} other The embed to compare against
   * @returns {boolean}
   */
  equals(other) {
    if (other instanceof Embed) {
      return isEqual(this.data, other.data);
    }

    return (
      this.author?.iconURL === other.author?.icon_url &&
      this.author?.name === other.author?.name &&
      this.author?.url === other.author?.url &&
      this.color === (other.color ?? null) &&
      this.description === (other.description ?? null) &&
      this.footer?.iconURL === other.footer?.icon_url &&
      this.footer?.text === other.footer?.text &&
      this.image?.url === other.image?.url &&
      this.thumbnail?.url === other.thumbnail?.url &&
      (this.timestamp && Date.parse(this.timestamp)) === (other.timestamp ? Date.parse(other.timestamp) : null) &&
      this.title === (other.title ?? null) &&
      this.url === (other.url ?? null) &&
      this.video?.url === other.video?.url &&
      isEqual(this.fields, other.fields?.map(field => ({ ...field, inline: field.inline ?? false })) ?? []) &&
      isEqual(this.provider, other.provider ?? null)
    );
  }
}

module.exports = Embed;
Repository: discordjs/discord.js
File: packages/discord.js/src/structures/CommandInteraction.js (JavaScript)

Code before:
     * @type {Snowflake}
     */
    this.commandId = data.data.id;

    /**
     * The invoked application command's name
     * @type {string}
     */
    this.commandName = data.data.name;

    /**
     * The invoked application command's type
     * @type {ApplicationCommandType}
     */
    this.commandType = data.data.type;

    /**
     * The id of the guild the invoked application command is registered to
     * @type {?Snowflake}
     */
    this.commandGuildId = data.data.guild_id ?? null;

    /**
     * Mapping of installation contexts that the interaction was authorized for to related user or guild IDs
     * @type {APIAuthorizingIntegrationOwnersMap}
     */
    this.authorizingIntegrationOwners = data.authorizingIntegrationOwners;

    /**
     * Context where the interaction was triggered from
     * @type {?InteractionContextType}
     */
    this.context = data.context ?? null;

    /**
     * Whether the reply to this interaction has been deferred
     * @type {boolean}
     */
    this.deferred = false;

    /**
     * Whether this interaction has already been replied to
     * @type {boolean}
     */
    this.replied = false;

    /**
     * Whether the reply to this interaction is ephemeral
     * @type {?boolean}
     */
    this.ephemeral = null;

Review comment (security):
```suggestion
    /**
     * Mapping of installation contexts that the interaction was authorized for the related user or guild ids
     * @type {APIAuthorizingIntegrationOwnersMap}
     */
```

Code after:
     * @type {Snowflake}
     */
    this.commandId = data.data.id;

    /**
     * The invoked application command's name
     * @type {string}
     */
    this.commandName = data.data.name;

    /**
     * The invoked application command's type
     * @type {ApplicationCommandType}
     */
    this.commandType = data.data.type;

    /**
     * The id of the guild the invoked application command is registered to
     * @type {?Snowflake}
     */
    this.commandGuildId = data.data.guild_id ?? null;

    /* eslint-disable max-len */
    /**
     * Mapping of installation contexts that the interaction was authorized for the related user or guild ids
     * @type {APIAuthorizingIntegrationOwnersMap}
     * @see {@link https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-authorizing-integration-owners-object}
     */
    this.authorizingIntegrationOwners = data.authorizing_integration_owners;
    /* eslint-enable max-len */

    /**
     * Context where the interaction was triggered from
     * @type {?InteractionContextType}
     */
    this.context = data.context ?? null;

    /**
     * Whether the reply to this interaction has been deferred
     * @type {boolean}
     */
    this.deferred = false;

    /**
     * Whether this interaction has already been replied to
     * @type {boolean}
     */
    this.replied = false;

    /**
     * Whether the reply to this interaction is ephemeral
Repository: discordjs/discord.js
File: packages/discord.js/src/util/Transformers.js (JavaScript)

Code before:
    type: autoModerationAction.type,
    metadata: {
      durationSeconds: autoModerationAction.metadata.duration_seconds ?? null,
      channelId: autoModerationAction.metadata.channel_id ?? null,
      customMessage: autoModerationAction.metadata.custom_message ?? null,
    },
  };
}

/**
 * Transforms an API integration types config object to a camel-cased variant.
 * @param {APIApplicationIntegrationTypeConfiguration} integrationTypesConfiguration The data to transform
 * @returns {IntegrationTypesConfiguration}
 * @ignore
 */
function _transformAPIIntegrationTypesConfiguration(integrationTypesConfiguration) {
  console.log(integrationTypesConfiguration);
  return integrationTypesConfiguration
    ? {
        oAuth2InstallParams:
          {
            scopes: integrationTypesConfiguration.oauth2_install_params?.scopes ?? null,
            permissions: integrationTypesConfiguration.oauth2_install_params
              ? new PermissionsBitField(integrationTypesConfiguration.oauth2_install_params.permissions).freeze()
              : null,
          } ?? null,
      }
    : null;
}

module.exports = { toSnakeCase, _transformAPIAutoModerationAction, _transformAPIIntegrationTypesConfiguration };


Review comment (suggestion):
This `?? null` is useless, you always define an object here
```suggestion
          },
```

Code after:
    metadata: {
      durationSeconds: autoModerationAction.metadata.duration_seconds ?? null,
      channelId: autoModerationAction.metadata.channel_id ?? null,
      customMessage: autoModerationAction.metadata.custom_message ?? null,
    },
  };
}

/**
 * Transforms an API message interaction metadata object to a camel-cased variant.
 * @param {Client} client The client
 * @param {APIMessageInteractionMetadata} messageInteractionMetadata The metadata to transform
 * @returns {MessageInteractionMetadata}
 * @ignore
 */
function _transformAPIMessageInteractionMetadata(client, messageInteractionMetadata) {
  return {
    id: messageInteractionMetadata.id,
    type: messageInteractionMetadata.type,
    user: client.users._add(messageInteractionMetadata.user),
    authorizingIntegrationOwners: messageInteractionMetadata.authorizing_integration_owners,
    originalResponseMessageId: messageInteractionMetadata.original_response_message_id ?? null,
    interactedMessageId: messageInteractionMetadata.interacted_message_id ?? null,
    triggeringInteractionMetadata: messageInteractionMetadata.triggering_interaction_metadata
      ? _transformAPIMessageInteractionMetadata(messageInteractionMetadata.triggering_interaction_metadata)
      : null,
  };
}

module.exports = { toSnakeCase, _transformAPIAutoModerationAction, _transformAPIMessageInteractionMetadata };
Repository: discordjs/discord.js
File: packages/discord.js/src/util/Transformers.js (JavaScript)

Code before:
    type: autoModerationAction.type,
    metadata: {
      durationSeconds: autoModerationAction.metadata.duration_seconds ?? null,
      channelId: autoModerationAction.metadata.channel_id ?? null,
      customMessage: autoModerationAction.metadata.custom_message ?? null,
    },
  };
}

/**
 * Transforms an API message interaction metadata object to a camel-cased variant.
 * @param {Client} client The client
 * @param {APIMessageInteractionMetadata} messageInteractionMetadata The metadata to transform
 * @returns {MessageInteractionMetadata}
 * @ignore
 */
function _transformAPIMessageInteractionMetadata(client, messageInteractionMetadata) {
  return {
    id: messageInteractionMetadata.id,
    type: messageInteractionMetadata.type,
    user: client.users._add(messageInteractionMetadata.user),
    authorizingIntegrationOwners: messageInteractionMetadata.authorizing_integration_owners,
    originalResponseMessageId: messageInteractionMetadata.original_response_message_id ?? null,
    interactedMessageId: messageInteractionMetadata.interacted_message_id ?? null,
    triggeringInteractionMetadata: messageInteractionMetadata.triggering_interaction_metadata
      ? _transformAPIAutoModerationAction(messageInteractionMetadata.triggering_interaction_metadata)
      : null,
  };
}

module.exports = { toSnakeCase, _transformAPIAutoModerationAction, _transformAPIMessageInteractionMetadata };


Review comment (suggestion):
```suggestion
      ? _transformAPIMessageInteractionMetadata(messageInteractionMetadata.triggering_interaction_metadata)
```

Code after:
    type: autoModerationAction.type,
    metadata: {
      durationSeconds: autoModerationAction.metadata.duration_seconds ?? null,
      channelId: autoModerationAction.metadata.channel_id ?? null,
      customMessage: autoModerationAction.metadata.custom_message ?? null,
    },
  };
}

/**
 * Transforms an API message interaction metadata object to a camel-cased variant.
 * @param {Client} client The client
 * @param {APIMessageInteractionMetadata} messageInteractionMetadata The metadata to transform
 * @returns {MessageInteractionMetadata}
 * @ignore
 */
function _transformAPIMessageInteractionMetadata(client, messageInteractionMetadata) {
  return {
    id: messageInteractionMetadata.id,
    type: messageInteractionMetadata.type,
    user: client.users._add(messageInteractionMetadata.user),
    authorizingIntegrationOwners: messageInteractionMetadata.authorizing_integration_owners,
    originalResponseMessageId: messageInteractionMetadata.original_response_message_id ?? null,
    interactedMessageId: messageInteractionMetadata.interacted_message_id ?? null,
    triggeringInteractionMetadata: messageInteractionMetadata.triggering_interaction_metadata
      ? _transformAPIMessageInteractionMetadata(messageInteractionMetadata.triggering_interaction_metadata)
      : null,
  };
}

module.exports = { toSnakeCase, _transformAPIAutoModerationAction, _transformAPIMessageInteractionMetadata };
Repository: discordjs/discord.js
File: packages/discord.js/src/structures/CommandInteraction.js (JavaScript)

Code before:
     * @type {Snowflake}
     */
    this.commandId = data.data.id;

    /**
     * The invoked application command's name
     * @type {string}
     */
    this.commandName = data.data.name;

    /**
     * The invoked application command's type
     * @type {ApplicationCommandType}
     */
    this.commandType = data.data.type;

    /**
     * The id of the guild the invoked application command is registered to
     * @type {?Snowflake}
     */
    this.commandGuildId = data.data.guild_id ?? null;

    /**
     * Mapping of installation contexts that the interaction was authorized for the related user or guild ids
     * @type {APIAuthorizingIntegrationOwnersMap}
     */
    this.authorizingIntegrationOwners = data.authorizing_integration_owners;

    /**
     * Context where the interaction was triggered from
     * @type {?InteractionContextType}
     */
    this.context = data.context ?? null;

    /**
     * Whether the reply to this interaction has been deferred
     * @type {boolean}
     */
    this.deferred = false;

    /**
     * Whether this interaction has already been replied to
     * @type {boolean}
     */
    this.replied = false;

    /**
     * Whether the reply to this interaction is ephemeral
     * @type {?boolean}
     */
    this.ephemeral = null;

Review comment (security):
Should be added to util/APITypes.js

Also, I think this property should link to the docs, i.e. `@see {@link https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-authorizing-integration-owners-object}`

Code after:
     * @type {Snowflake}
     */
    this.commandId = data.data.id;

    /**
     * The invoked application command's name
     * @type {string}
     */
    this.commandName = data.data.name;

    /**
     * The invoked application command's type
     * @type {ApplicationCommandType}
     */
    this.commandType = data.data.type;

    /**
     * The id of the guild the invoked application command is registered to
     * @type {?Snowflake}
     */
    this.commandGuildId = data.data.guild_id ?? null;

    /* eslint-disable max-len */
    /**
     * Mapping of installation contexts that the interaction was authorized for the related user or guild ids
     * @type {APIAuthorizingIntegrationOwnersMap}
     * @see {@link https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-authorizing-integration-owners-object}
     */
    this.authorizingIntegrationOwners = data.authorizing_integration_owners;
    /* eslint-enable max-len */

    /**
     * Context where the interaction was triggered from
     * @type {?InteractionContextType}
     */
    this.context = data.context ?? null;

    /**
     * Whether the reply to this interaction has been deferred
     * @type {boolean}
     */
    this.deferred = false;

    /**
     * Whether this interaction has already been replied to
     * @type {boolean}
     */
    this.replied = false;

    /**
     * Whether the reply to this interaction is ephemeral