chore: fix lint errors; tweak lint rules
This commit is contained in:
parent
9b3d6f5d68
commit
5f194bf1ef
115 changed files with 176 additions and 264 deletions
|
@ -95,19 +95,11 @@ export function tNullable<T extends t.Type<any, any>>(type: T) {
|
|||
return t.union([type, t.undefined, t.null], `Nullable<${type.name}>`);
|
||||
}
|
||||
|
||||
function typeHasProps(type: any): type is t.TypeC<any> {
|
||||
return type.props != null;
|
||||
}
|
||||
|
||||
function typeIsArray(type: any): type is t.ArrayC<any> {
|
||||
return type._tag === "ArrayType";
|
||||
}
|
||||
|
||||
export const tNormalizedNullOrUndefined = new t.Type<undefined, null | undefined>(
|
||||
"tNormalizedNullOrUndefined",
|
||||
(v): v is undefined => typeof v === "undefined",
|
||||
(v, c) => (v == null ? t.success(undefined) : t.failure(v, c, "Value must be null or undefined")),
|
||||
(s) => undefined,
|
||||
() => undefined,
|
||||
);
|
||||
|
||||
/**
|
||||
|
@ -166,16 +158,6 @@ export function tDeepPartial<T>(type: T): TDeepPartial<T> {
|
|||
}
|
||||
}
|
||||
|
||||
function tDeepPartialProp(prop: any) {
|
||||
if (typeHasProps(prop)) {
|
||||
return tDeepPartial(prop);
|
||||
} else if (typeIsArray(prop)) {
|
||||
return t.array(tDeepPartialProp(prop.type));
|
||||
} else {
|
||||
return prop;
|
||||
}
|
||||
}
|
||||
|
||||
export function getScalarDifference<T extends object>(
|
||||
base: T,
|
||||
object: T,
|
||||
|
@ -480,7 +462,9 @@ export const tAllowedMentions = t.type({
|
|||
});
|
||||
|
||||
export function dropPropertiesByName(obj, propName) {
|
||||
if (obj.hasOwnProperty(propName)) delete obj[propName];
|
||||
if (Object.hasOwn(obj, propName)) {
|
||||
delete obj[propName];
|
||||
}
|
||||
for (const value of Object.values(obj)) {
|
||||
if (typeof value === "object" && value !== null && !Array.isArray(value)) {
|
||||
dropPropertiesByName(value, propName);
|
||||
|
@ -584,8 +568,8 @@ export function get(obj, path, def?): any {
|
|||
.map((s) => s.trim())
|
||||
.filter((s) => s !== "");
|
||||
for (const part of pathParts) {
|
||||
// hasOwnProperty check here is necessary to prevent prototype traversal in tags
|
||||
if (!cursor.hasOwnProperty(part)) return def;
|
||||
// hasOwn check here is necessary to prevent prototype traversal in tags
|
||||
if (!Object.hasOwn(cursor, part)) return def;
|
||||
cursor = cursor[part];
|
||||
if (cursor === undefined) return def;
|
||||
if (cursor == null) return null;
|
||||
|
@ -691,10 +675,10 @@ export function isNotNull<T>(value: T): value is Exclude<T, null | undefined> {
|
|||
// discord.gg/<code>
|
||||
// discord.com/friend-invite/<code>
|
||||
const quickInviteDetection =
|
||||
/discord(?:app)?\.com\/(?:friend-)?invite\/([a-z0-9\-]+)|discord\.gg\/(?:\S+\/)?([a-z0-9\-]+)/gi;
|
||||
/discord(?:app)?\.com\/(?:friend-)?invite\/([a-z0-9-]+)|discord\.gg\/(?:\S+\/)?([a-z0-9-]+)/gi;
|
||||
|
||||
const isInviteHostRegex = /(?:^|\.)(?:discord.gg|discord.com|discordapp.com)$/i;
|
||||
const longInvitePathRegex = /^\/(?:friend-)?invite\/([a-z0-9\-]+)$/i;
|
||||
const longInvitePathRegex = /^\/(?:friend-)?invite\/([a-z0-9-]+)$/i;
|
||||
|
||||
export function getInviteCodesInString(str: string): string[] {
|
||||
const inviteCodes: string[] = [];
|
||||
|
@ -1187,12 +1171,12 @@ const keyMods = ["+", "-", "="];
|
|||
export function deepKeyIntersect(obj, keyReference) {
|
||||
const result = {};
|
||||
for (let [key, value] of Object.entries(obj)) {
|
||||
if (!keyReference.hasOwnProperty(key)) {
|
||||
if (!Object.hasOwn(keyReference, key)) {
|
||||
// Temporary solution so we don't erase keys with modifiers
|
||||
// Modifiers will be removed soon(tm) so we can remove this when that happens as well
|
||||
let found = false;
|
||||
for (const mod of keyMods) {
|
||||
if (keyReference.hasOwnProperty(mod + key)) {
|
||||
if (Object.hasOwn(keyReference, mod + key)) {
|
||||
key = mod + key;
|
||||
found = true;
|
||||
break;
|
||||
|
@ -1267,7 +1251,7 @@ export function getUser(client: Client, userResolvable: string): User | UnknownU
|
|||
*/
|
||||
export async function resolveUser(bot: Client, value: string): Promise<User | UnknownUser>;
|
||||
export async function resolveUser<T>(bot: Client, value: Not<T, string>): Promise<UnknownUser>;
|
||||
export async function resolveUser<T>(bot, value) {
|
||||
export async function resolveUser(bot, value) {
|
||||
if (typeof value !== "string") {
|
||||
return new UnknownUser();
|
||||
}
|
||||
|
@ -1386,22 +1370,22 @@ export function resolveRole(guild: Guild, roleResolvable: RoleResolvable) {
|
|||
|
||||
const inviteCache = new SimpleCache<Promise<Invite | null>>(10 * MINUTES, 200);
|
||||
|
||||
type ResolveInviteReturnType<T extends boolean> = Promise<Invite | null>;
|
||||
type ResolveInviteReturnType = Promise<Invite | null>;
|
||||
export async function resolveInvite<T extends boolean>(
|
||||
client: Client,
|
||||
code: string,
|
||||
withCounts?: T,
|
||||
): ResolveInviteReturnType<T> {
|
||||
): ResolveInviteReturnType {
|
||||
const key = `${code}:${withCounts ? 1 : 0}`;
|
||||
|
||||
if (inviteCache.has(key)) {
|
||||
return inviteCache.get(key) as ResolveInviteReturnType<T>;
|
||||
return inviteCache.get(key) as ResolveInviteReturnType;
|
||||
}
|
||||
|
||||
const promise = client.fetchInvite(code).catch(() => null);
|
||||
inviteCache.set(key, promise);
|
||||
|
||||
return promise as ResolveInviteReturnType<T>;
|
||||
return promise as ResolveInviteReturnType;
|
||||
}
|
||||
|
||||
const internalStickerCache: LimitedCollection<Snowflake, Sticker> = new LimitedCollection({ maxSize: 500 });
|
||||
|
@ -1605,7 +1589,7 @@ export function inviteHasCounts(invite: Invite): invite is Invite {
|
|||
}
|
||||
|
||||
export function asyncMap<T, R>(arr: T[], fn: (item: T) => Promise<R>): Promise<R[]> {
|
||||
return Promise.all(arr.map((item, index) => fn(item)));
|
||||
return Promise.all(arr.map((item) => fn(item)));
|
||||
}
|
||||
|
||||
export function unique<T>(arr: T[]): T[] {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue