Skip to content

Commit

Permalink
refactor: replace short hand type conversions with function calls (#45)
Browse files Browse the repository at this point in the history
* refactor: replace short hand type conversions with function calls

Prefer using explicit casts by calling `Number`, `Boolean`, or `String` over using operators like `+`, `!!` or `"" +`. This is considered best practice as it improves readability.

* style: format code with Prettier

This commit fixes the style issues introduced in daa490e according to the output
from Prettier.

Details: #45

---------

Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
  • Loading branch information
deepsource-autofix[bot] authored Feb 27, 2024
1 parent 94f065d commit a9ee439
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
9 changes: 6 additions & 3 deletions src/commands/slash/Information/credits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,17 @@ export default class Credits extends BaseCommand {
{ context: { userId: credit } },
)) as User[];

const member = shardValues.find((m) => !!m) ?? (await interaction.client.users.fetch(credit));
const member =
shardValues.find((m) => Boolean(m)) ?? (await interaction.client.users.fetch(credit));

members.push(member);
}

const linksDivider = `${emojis.blueLine.repeat(9)} **LINKS** ${emojis.blueLine.repeat(9)}`;
const creditsDivider = `${emojis.blueLine.repeat(9)} **TEAM** ${emojis.blueLine.repeat(9)}`;

const creditsEmbed = simpleEmbed(stripIndents`
const creditsEmbed = simpleEmbed(
stripIndents`
## ${emojis.wand} The Team
InterChat is a project driven by a passionate team dedicated to enhancing the Discord experience. We welcome new members to join our team; if you're interested, please join our [support server](${LINKS.SUPPORT_INVITE}).
Expand All @@ -57,7 +59,8 @@ export default class Credits extends BaseCommand {
${linksDivider}
[Guide](${LINKS.DOCS}) • [Invite](https://discord.com/application-directory/769921109209907241) • [Support Server](${LINKS.SUPPORT_INVITE}) • [Vote](https://top.gg/bot/769921109209907241/vote) • [Privacy](${LINKS.DOCS}/legal/privacy) • [Terms](${LINKS.DOCS}/legal/terms)
`.replaceAll('_', '\\_'));
`.replaceAll('_', '\\_'),
);

const linkButtons = new ActionRowBuilder<ButtonBuilder>().addComponents(
new ButtonBuilder()
Expand Down
4 changes: 2 additions & 2 deletions src/core/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default abstract class SuperClient<R extends boolean = boolean> extends C

private readonly scheduler = new Scheduler();

readonly description = 'The only cross-server chatting bot you\'ll ever need.';
readonly description = "The only cross-server chatting bot you'll ever need.";
readonly version = process.env.npm_package_version ?? 'Unknown';
readonly commands = commandsMap;
readonly interactions = interactionsMap;
Expand Down Expand Up @@ -117,7 +117,7 @@ export default abstract class SuperClient<R extends boolean = boolean> extends C

// eslint-disable-next-line @typescript-eslint/no-explicit-any
static resolveEval = <T>(value: T[]) =>
value?.find((res) => !!res) as RemoveMethods<T> | undefined;
value?.find((res) => Boolean(res)) as RemoveMethods<T> | undefined;

/**
* Fetches a guild by its ID from the cache.
Expand Down
8 changes: 4 additions & 4 deletions src/utils/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export const hasVoted = async (userId: Snowflake): Promise<boolean> => {
})
).json();

return !!res.voted;
return Boolean(res.voted);
};

export const userVotedToday = async (userId: Snowflake): Promise<boolean> => {
Expand Down Expand Up @@ -156,8 +156,8 @@ export const disableAllComponents = (
const jsonRow = row.toJSON();
jsonRow.components.forEach((component) => {
!disableLinks &&
component.type === ComponentType.Button &&
component.style === ButtonStyle.Link
component.type === ComponentType.Button &&
component.style === ButtonStyle.Link
? (component.disabled = false) // leave link buttons enabled
: (component.disabled = true);
});
Expand Down Expand Up @@ -351,7 +351,7 @@ export const parseEmoji = (emoji: string) => {
if (!match) return null;

const [, animated, name, id] = match;
return { animated: !!animated, name, id };
return { animated: Boolean(animated), name, id };
};

export const getEmojiId = (emoji: string | undefined) => {
Expand Down

0 comments on commit a9ee439

Please sign in to comment.