From 649e71992be35546677dea2eaeab6b775c5e25b3 Mon Sep 17 00:00:00 2001 From: parbez Date: Mon, 19 Feb 2024 13:25:58 +0530 Subject: [PATCH] chore: linter fixes --- .eslintrc.json | 2 +- src/lib/pagination/Pagination.ts | 8 ++------ src/lib/pagination/PaginationEmbed.ts | 23 ++++++----------------- src/lib/types/ButtonsOptions.ts | 4 +--- 4 files changed, 10 insertions(+), 27 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index b2e7220..c74fa32 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,6 +1,6 @@ { "root": true, - "extends": ["mahir/common", "mahir/node", "mahir/typescript", "mahir/prettier", "mahir/tsdoc"], + "extends": ["mahir/common", "mahir/node", "mahir/typescript", "mahir/tsdoc"], "ignorePatterns": ["**/dist/*"], "rules": { "no-param-reassign": "off", diff --git a/src/lib/pagination/Pagination.ts b/src/lib/pagination/Pagination.ts index ef4c894..1e96a8b 100644 --- a/src/lib/pagination/Pagination.ts +++ b/src/lib/pagination/Pagination.ts @@ -173,9 +173,7 @@ export class Pagination extends PaginationEmbed { return; } - if (interaction.customId === this.buttons.last?.data.custom_id) { - await this.goLast(interaction); - } + if (interaction.customId === this.buttons.last?.data.custom_id) await this.goLast(interaction); }); return this; } @@ -195,9 +193,7 @@ export class Pagination extends PaginationEmbed { * ``` */ public async render(): Promise | Message> { - if (this.interaction instanceof BaseInteraction && (this.interaction.replied || this.interaction.deferred)) { - return this.editReply(); - } + if (this.interaction instanceof BaseInteraction && (this.interaction.replied || this.interaction.deferred)) return this.editReply(); return this.reply(); } diff --git a/src/lib/pagination/PaginationEmbed.ts b/src/lib/pagination/PaginationEmbed.ts index 9565584..d4bf007 100644 --- a/src/lib/pagination/PaginationEmbed.ts +++ b/src/lib/pagination/PaginationEmbed.ts @@ -461,9 +461,8 @@ export abstract class PaginationEmbed extends EmbedBuilder { * ``` */ public setEmbeds(embeds: PEmbeds, template?: (embed: EmbedBuilder, i: number, array: PEmbeds) => JSONEncodable): this { - if (template) { + if (template) embeds = embeds.map((embed, index, array) => template(embed instanceof EmbedBuilder ? embed : EmbedBuilder.from(embed), index, array)); - } this.embeds = embeds; this.limit = 1; @@ -485,9 +484,7 @@ export abstract class PaginationEmbed extends EmbedBuilder { * ``` */ public addEmbeds(embeds: PEmbeds, template?: (embed: EmbedBuilder) => JSONEncodable): this { - if (template) { - embeds = embeds.map((embed) => template(EmbedBuilder.from(embed))); - } + if (template) embeds = embeds.map((embed) => template(EmbedBuilder.from(embed))); this.embeds.push(...embeds); return this; @@ -820,17 +817,13 @@ export abstract class PaginationEmbed extends EmbedBuilder { if (!this.data.footer) { this.customFooter = false; this.rawFooter = 'Pages: {pageNumber}/{totalPages}'; - } else if (this.customFooter && !this.rawFooter) { - this.rawFooter = this.data.footer.text; - } + } else if (this.customFooter && !this.rawFooter) this.rawFooter = this.data.footer.text; this.setFooter({ text: this.rawFooter.replaceAll('{pageNumber}', `${pageNumber}`).replaceAll('{totalPages}', `${this.totalPages}`), iconURL: this.data.footer?.icon_url }); - if (this.images.length) { - this.setImage(this.images[pageNumber - 1]); - } + if (this.images.length) this.setImage(this.images[pageNumber - 1]); // TODO: remove null from content in a next major version. Djs changed the typings in a minor version. this.payload.content = (Array.isArray(this.contents) ? this.contents[this.currentPage - 1] : this.contents) ?? undefined; @@ -841,9 +834,7 @@ export abstract class PaginationEmbed extends EmbedBuilder { ); } - if (this.fieldPaginate) { - super.setFields(this.rawFields.slice(pageNumber * this.limit - this.limit, pageNumber * this.limit)); - } + if (this.fieldPaginate) super.setFields(this.rawFields.slice(pageNumber * this.limit - this.limit, pageNumber * this.limit)); return this; } @@ -876,9 +867,7 @@ export abstract class PaginationEmbed extends EmbedBuilder { * ``` */ public ready(): Payload { - if (!this.fieldPaginate) { - this.setFields(this.rawFields); - } + if (!this.fieldPaginate) this.setFields(this.rawFields); this.totalEntry = this.embeds.length || Math.max(this.descriptions.length, this.images.length, this.fieldPaginate ? this.rawFields.length : 0); diff --git a/src/lib/types/ButtonsOptions.ts b/src/lib/types/ButtonsOptions.ts index c854cfa..8a7254e 100644 --- a/src/lib/types/ButtonsOptions.ts +++ b/src/lib/types/ButtonsOptions.ts @@ -1,6 +1,4 @@ -import { type APIButtonComponentWithCustomId, type ButtonStyle, type ComponentEmojiResolvable } from 'discord.js'; - -import type { ButtonBuilder } from 'discord.js'; +import type { APIButtonComponentWithCustomId, ButtonStyle, ComponentEmojiResolvable, ButtonBuilder } from 'discord.js'; /** * The style of the paginator buttons.