chore: improve linting (#7244)

This commit is contained in:
Noel
2022-01-11 12:30:08 +01:00
committed by GitHub
parent ff3a8b8323
commit 16938da355
57 changed files with 527 additions and 440 deletions

View File

@@ -5,21 +5,6 @@ import type { ApplicationCommandOptionBase } from './mixins/ApplicationCommandOp
import type { ToAPIApplicationCommandOptions } from './SlashCommandBuilder';
import type { SlashCommandSubcommandBuilder, SlashCommandSubcommandGroupBuilder } from './SlashCommandSubcommands';
export function validateRequiredParameters(
name: string,
description: string,
options: ToAPIApplicationCommandOptions[],
) {
// Assert name matches all conditions
validateName(name);
// Assert description conditions
validateDescription(description);
// Assert options conditions
validateMaxOptionsLength(options);
}
const namePredicate = z
.string()
.min(1)
@@ -36,6 +21,27 @@ export function validateDescription(description: unknown): asserts description i
descriptionPredicate.parse(description);
}
const maxArrayLengthPredicate = z.unknown().array().max(25);
export function validateMaxOptionsLength(options: unknown): asserts options is ToAPIApplicationCommandOptions[] {
maxArrayLengthPredicate.parse(options);
}
export function validateRequiredParameters(
name: string,
description: string,
options: ToAPIApplicationCommandOptions[],
) {
// Assert name matches all conditions
validateName(name);
// Assert description conditions
validateDescription(description);
// Assert options conditions
validateMaxOptionsLength(options);
}
const booleanPredicate = z.boolean();
export function validateDefaultPermission(value: unknown): asserts value is boolean {
@@ -46,12 +52,6 @@ export function validateRequired(required: unknown): asserts required is boolean
booleanPredicate.parse(required);
}
const maxArrayLengthPredicate = z.unknown().array().max(25);
export function validateMaxOptionsLength(options: unknown): asserts options is ToAPIApplicationCommandOptions[] {
maxArrayLengthPredicate.parse(options);
}
export function validateMaxChoicesLength(choices: APIApplicationCommandOptionChoice[]) {
maxArrayLengthPredicate.parse(choices);
}

View File

@@ -133,5 +133,5 @@ export interface SlashCommandOptionsOnlyBuilder
Pick<SlashCommandBuilder, 'toJSON'> {}
export interface ToAPIApplicationCommandOptions {
toJSON(): APIApplicationCommandOption;
toJSON: () => APIApplicationCommandOption;
}

View File

@@ -48,8 +48,10 @@ export class SlashCommandSubcommandGroupBuilder implements ToAPIApplicationComma
validateMaxOptionsLength(options);
// Get the final result
// eslint-disable-next-line @typescript-eslint/no-use-before-define
const result = typeof input === 'function' ? input(new SlashCommandSubcommandBuilder()) : input;
// eslint-disable-next-line @typescript-eslint/no-use-before-define
assertReturnOfBuilder(result, SlashCommandSubcommandBuilder);
// Push it