Skip to content

Commit

Permalink
refactor: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
samarmeena committed Dec 3, 2023
1 parent 77985ff commit 027542f
Show file tree
Hide file tree
Showing 26 changed files with 138 additions and 134 deletions.
44 changes: 10 additions & 34 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
],
"extends": [
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
"plugin:@typescript-eslint/strict-type-checked"
],
"rules": {
// simple-import-sort
Expand All @@ -26,39 +26,15 @@
"typescript-sort-keys/interface": "error",
"typescript-sort-keys/string-enum": "error",

// common
"no-return-await": "error",
"no-unreachable-loop": "error",
"no-promise-executor-return": "error",
"no-unsafe-optional-chaining": "error",
"no-useless-backreference": "error",
"require-atomic-updates": "error",
"require-await": "error",
"no-await-in-loop": "error",
"spaced-comment": "error",
"sort-imports": "off",
"sort-keys": "error",
"no-unused-vars": "off", // typescript-eslint suggestion: off
"curly": "error",
"camelcase": "error",

// TypeScript
"@typescript-eslint/consistent-type-imports": "error",
"@typescript-eslint/no-use-before-define": "error",
"@typescript-eslint/no-shadow": "error",
"@typescript-eslint/prefer-optional-chain": "error",
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/semi": "error",
"@typescript-eslint/no-loss-of-precision": "error",
// typescript-eslint
"@typescript-eslint/quotes": ["error", "double", { "avoidEscape": true }],
"@typescript-eslint/no-empty-function": "error",
"@typescript-eslint/no-empty-interface": "error",
"@typescript-eslint/no-inferrable-types": "error",
"@typescript-eslint/no-non-null-asserted-optional-chain": "error",
"@typescript-eslint/no-non-null-assertion": "error",
"@typescript-eslint/explicit-module-boundary-types": "error",
"@typescript-eslint/no-var-requires": "error",
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/ban-types": "error"
"@typescript-eslint/no-misused-promises": [
"error",
{
"checksVoidReturn": {
"arguments": false
}
}
]
}
}
12 changes: 6 additions & 6 deletions 1-starter/src/commands/choices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Discord, Slash, SlashChoice, SlashOption } from "discordx";
@Discord()
export class Example {
@Slash({ description: "choose" })
choose(
async choose(
@SlashChoice("Human", "Astronaut", "Dev")
@SlashOption({
description: "What are you?",
Expand All @@ -15,12 +15,12 @@ export class Example {
})
what: string,
interaction: CommandInteraction,
): void {
interaction.reply(what);
): Promise<void> {
await interaction.reply(what);
}

@Slash({ description: "choose1" })
choose1(
async choose1(
@SlashChoice({ name: "are you okay?", value: "okay" })
@SlashChoice({ name: "are you good?", value: "good" })
@SlashOption({
Expand All @@ -31,7 +31,7 @@ export class Example {
})
what: string,
interaction: CommandInteraction,
): void {
interaction.reply(what);
): Promise<void> {
await interaction.reply(what);
}
}
12 changes: 8 additions & 4 deletions 1-starter/src/commands/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@ export class Example {
name: "message context",
type: ApplicationCommandType.Message,
})
messageHandler(interaction: MessageContextMenuCommandInteraction): void {
interaction.reply("I am user context handler");
async messageHandler(
interaction: MessageContextMenuCommandInteraction,
): Promise<void> {
await interaction.reply("I am user context handler");
}

@ContextMenu({ name: "user context", type: ApplicationCommandType.User })
userHandler(interaction: UserContextMenuCommandInteraction): void {
interaction.reply("I am user context handler");
async userHandler(
interaction: UserContextMenuCommandInteraction,
): Promise<void> {
await interaction.reply("I am user context handler");
}
}
4 changes: 2 additions & 2 deletions 1-starter/src/commands/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class Example {
await interaction.deferReply();

// extract selected value by member
const roleValue = interaction.values?.[0];
const roleValue = interaction.values[0];

// if value not found
if (!roleValue) {
Expand Down Expand Up @@ -50,7 +50,7 @@ export class Example {
);

// send it
interaction.editReply({
await interaction.editReply({
components: [buttonRow],
content: "select your role!",
});
Expand Down
25 changes: 13 additions & 12 deletions 1-starter/src/commands/simple command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,38 @@ import {
@Discord()
export class Example {
@SimpleCommand({ aliases: ["hi"] })
hello(command: SimpleCommandMessage): void {
command.message.reply(`👋 ${command.message.member}`);
async hello(command: SimpleCommandMessage): Promise<void> {
await command.message.reply(`👋 ${command.message.member?.toString()}`);
}

@SimpleCommand({ argSplitter: "+" })
sum(
async sum(
@SimpleCommandOption({ name: "num1", type: SimpleCommandOptionType.Number })
num1: number | undefined,
@SimpleCommandOption({ name: "num2", type: SimpleCommandOptionType.Number })
num2: number | undefined,
command: SimpleCommandMessage,
): void {
): Promise<void> {
if (!num1 || !num2) {
command.sendUsageSyntax();
await command.sendUsageSyntax();
return;
}
command.message.reply(`total = ${num1 + num2}`);

await command.message.reply(`total = ${num1 + num2}`);
}

// make single handler for simple and slash command
likeIt(command: CommandInteraction | Message): void {
command.reply("I like it, Thanks");
async likeIt(command: CommandInteraction | Message): Promise<void> {
await command.reply("I like it, Thanks");
}

@SimpleCommand({ name: "like-it" })
simpleLikeIt(command: SimpleCommandMessage): void {
this.likeIt(command.message);
async simpleLikeIt(command: SimpleCommandMessage): Promise<void> {
await this.likeIt(command.message);
}

@Slash({ description: "like-ite", name: "like-it" })
slashLikeIt(command: CommandInteraction): void {
this.likeIt(command);
async slashLikeIt(command: CommandInteraction): Promise<void> {
await this.likeIt(command);
}
}
8 changes: 4 additions & 4 deletions 1-starter/src/commands/slash + button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ export class Example {
helloBtn,
);

interaction.editReply({
await interaction.editReply({
components: [row],
content: `${user}, Say hello to bot`,
content: `${user?.toString()}, Say hello to bot`,
});
}

@ButtonComponent({ id: "hello-btn" })
helloBtn(interaction: ButtonInteraction): void {
interaction.reply(`👋 ${interaction.member}`);
async helloBtn(interaction: ButtonInteraction): Promise<void> {
await interaction.reply(`👋 ${interaction.member?.toString()}`);
}
}
18 changes: 9 additions & 9 deletions 1-starter/src/commands/slash group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Discord, Slash, SlashGroup, SlashOption } from "discordx";
export class GroupExample {
@Slash({ description: "add" })
@SlashGroup("maths", "testing")
add(
async add(
@SlashOption({
description: "x value",
name: "x",
Expand All @@ -24,13 +24,13 @@ export class GroupExample {
})
y: number,
interaction: CommandInteraction,
): void {
interaction.reply(String(x + y));
): Promise<void> {
await interaction.reply(String(x + y));
}

@Slash({ description: "multiply" })
@SlashGroup("maths", "testing")
multiply(
async multiply(
@SlashOption({
description: "x value",
name: "x",
Expand All @@ -46,13 +46,13 @@ export class GroupExample {
})
y: number,
interaction: CommandInteraction,
): void {
interaction.reply(String(x * y));
): Promise<void> {
await interaction.reply(String(x * y));
}

@Slash({ description: "root" })
@SlashGroup("testing")
root(
async root(
@SlashOption({
description: "text",
name: "text",
Expand All @@ -61,7 +61,7 @@ export class GroupExample {
})
text: string,
interaction: CommandInteraction,
): void {
interaction.reply(text);
): Promise<void> {
await interaction.reply(text);
}
}
8 changes: 5 additions & 3 deletions 1-starter/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ bot.on("interactionCreate", (interaction: Interaction) => {
bot.executeInteraction(interaction);
});

bot.on("messageCreate", (message: Message) => {
bot.executeCommand(message);
bot.on("messageCreate", async (message: Message) => {
await bot.executeCommand(message);
});

async function run() {
Expand All @@ -69,4 +69,6 @@ async function run() {
await bot.login(process.env.BOT_TOKEN);
}

run();
run().catch((err) => {
throw err;
});
4 changes: 3 additions & 1 deletion 2-starter-with-api/src/api/guilds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export class API {

@Get()
guilds(context: Context): void {
context.body = `${bot.guilds.cache.map((g) => `${g.id}: ${g.name}\n`)}`;
context.body = `${bot.guilds.cache
.map((g) => `${g.id}: ${g.name}`)
.join("\n")}`;
}
}
12 changes: 6 additions & 6 deletions 2-starter-with-api/src/commands/choices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Discord, Slash, SlashChoice, SlashOption } from "discordx";
@Discord()
export class Example {
@Slash({ description: "choose" })
choose(
async choose(
@SlashChoice("Human", "Astronaut", "Dev")
@SlashOption({
description: "What are you?",
Expand All @@ -15,12 +15,12 @@ export class Example {
})
what: string,
interaction: CommandInteraction,
): void {
interaction.reply(what);
): Promise<void> {
await interaction.reply(what);
}

@Slash({ description: "choose1" })
choose1(
async choose1(
@SlashChoice({ name: "are you okay?", value: "okay" })
@SlashChoice({ name: "are you good?", value: "good" })
@SlashOption({
Expand All @@ -31,7 +31,7 @@ export class Example {
})
what: string,
interaction: CommandInteraction,
): void {
interaction.reply(what);
): Promise<void> {
await interaction.reply(what);
}
}
12 changes: 8 additions & 4 deletions 2-starter-with-api/src/commands/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@ export class Example {
name: "message context",
type: ApplicationCommandType.Message,
})
messageHandler(interaction: MessageContextMenuCommandInteraction): void {
interaction.reply("I am user context handler");
async messageHandler(
interaction: MessageContextMenuCommandInteraction,
): Promise<void> {
await interaction.reply("I am user context handler");
}

@ContextMenu({ name: "user context", type: ApplicationCommandType.User })
userHandler(interaction: UserContextMenuCommandInteraction): void {
interaction.reply("I am user context handler");
async userHandler(
interaction: UserContextMenuCommandInteraction,
): Promise<void> {
await interaction.reply("I am user context handler");
}
}
4 changes: 2 additions & 2 deletions 2-starter-with-api/src/commands/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class Example {
await interaction.deferReply();

// extract selected value by member
const roleValue = interaction.values?.[0];
const roleValue = interaction.values[0];

// if value not found
if (!roleValue) {
Expand Down Expand Up @@ -50,7 +50,7 @@ export class Example {
);

// send it
interaction.editReply({
await interaction.editReply({
components: [buttonRow],
content: "select your role!",
});
Expand Down
Loading

0 comments on commit 027542f

Please sign in to comment.