Add ESLint (#941)
* Add eslint, switch to lint-staged for precommit * Fix all ESLint errors * Update GH workflow to check prettier and eslint
This commit is contained in:
@@ -18,5 +18,4 @@
|
||||
|
||||
import { ChannelPermissionOverwrite } from "@fosscord/util";
|
||||
|
||||
export interface ChannelPermissionOverwriteSchema
|
||||
extends ChannelPermissionOverwrite {}
|
||||
export type ChannelPermissionOverwriteSchema = ChannelPermissionOverwrite;
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
|
||||
import { ActivitySchema } from "@fosscord/util";
|
||||
|
||||
// TODO: Need a way to allow camalCase and pascal_case without just duplicating the schema
|
||||
|
||||
export const IdentifySchema = {
|
||||
token: String,
|
||||
$intents: BigInt, // discord uses a Integer for bitfields we use bigints tho. | instanceOf will automatically convert the Number to a BigInt
|
||||
@@ -98,7 +100,7 @@ export interface IdentifySchema {
|
||||
referring_domain_current?: string;
|
||||
release_channel?: "stable" | "dev" | "ptb" | "canary";
|
||||
client_build_number?: number;
|
||||
client_event_source?: any;
|
||||
client_event_source?: string;
|
||||
client_version?: string;
|
||||
system_locale?: string;
|
||||
};
|
||||
@@ -111,23 +113,23 @@ export interface IdentifySchema {
|
||||
guild_subscriptions?: boolean;
|
||||
capabilities?: number;
|
||||
client_state?: {
|
||||
guild_hashes?: any;
|
||||
guild_hashes?: unknown;
|
||||
highest_last_message_id?: string | number;
|
||||
read_state_version?: number;
|
||||
user_guild_settings_version?: number;
|
||||
user_settings_version?: number;
|
||||
useruser_guild_settings_version?: number;
|
||||
private_channels_version?: number;
|
||||
guild_versions?: any;
|
||||
guild_versions?: unknown;
|
||||
api_code_version?: number;
|
||||
};
|
||||
clientState?: {
|
||||
guildHashes?: any;
|
||||
guildHashes?: unknown;
|
||||
highestLastMessageId?: string | number;
|
||||
readStateVersion?: number;
|
||||
userGuildSettingsVersion?: number;
|
||||
useruserGuildSettingsVersion?: number;
|
||||
guildVersions?: any;
|
||||
guildVersions?: unknown;
|
||||
apiCodeVersion?: number;
|
||||
};
|
||||
v?: number;
|
||||
|
||||
@@ -22,8 +22,8 @@ export interface LazyRequestSchema {
|
||||
activities?: boolean;
|
||||
threads?: boolean;
|
||||
typing?: true;
|
||||
members?: any[];
|
||||
thread_member_lists?: any[];
|
||||
members?: unknown[];
|
||||
thread_member_lists?: unknown[];
|
||||
}
|
||||
|
||||
export const LazyRequestSchema = {
|
||||
@@ -32,6 +32,6 @@ export const LazyRequestSchema = {
|
||||
$channels: Object,
|
||||
$typing: Boolean,
|
||||
$threads: Boolean,
|
||||
$members: [] as any[],
|
||||
$thread_member_lists: [] as any[],
|
||||
$members: [] as unknown[],
|
||||
$thread_member_lists: [] as unknown[],
|
||||
};
|
||||
|
||||
@@ -18,6 +18,11 @@
|
||||
|
||||
import { Embed } from "@fosscord/util";
|
||||
|
||||
type Attachment = {
|
||||
id: string;
|
||||
filename: string;
|
||||
};
|
||||
|
||||
export interface MessageCreateSchema {
|
||||
type?: number;
|
||||
content?: string;
|
||||
@@ -41,11 +46,11 @@ export interface MessageCreateSchema {
|
||||
fail_if_not_exists?: boolean;
|
||||
};
|
||||
payload_json?: string;
|
||||
file?: any;
|
||||
file?: { filename: string };
|
||||
/**
|
||||
TODO: we should create an interface for attachments
|
||||
TODO: OpenWAAO<-->attachment-style metadata conversion
|
||||
**/
|
||||
attachments?: any[];
|
||||
attachments?: Attachment[];
|
||||
sticker_ids?: string[];
|
||||
}
|
||||
|
||||
@@ -18,4 +18,4 @@
|
||||
|
||||
import { UserSettings } from "@fosscord/util";
|
||||
|
||||
export interface UserSettingsSchema extends Partial<UserSettings> {}
|
||||
export type UserSettingsSchema = Partial<UserSettings>;
|
||||
|
||||
@@ -45,7 +45,7 @@ export const ajv = new Ajv({
|
||||
|
||||
addFormats(ajv);
|
||||
|
||||
export function validateSchema<G>(schema: string, data: G): G {
|
||||
export function validateSchema<G extends object>(schema: string, data: G): G {
|
||||
const valid = ajv.validate(schema, normalizeBody(data));
|
||||
if (!valid) throw ajv.errors;
|
||||
return data;
|
||||
@@ -55,13 +55,13 @@ export function validateSchema<G>(schema: string, data: G): G {
|
||||
// this removes null values as ajv doesn't treat them as undefined
|
||||
// normalizeBody allows to handle circular structures without issues
|
||||
// taken from https://github.com/serverless/serverless/blob/master/lib/classes/ConfigSchemaHandler/index.js#L30 (MIT license)
|
||||
export const normalizeBody = (body: any = {}) => {
|
||||
export const normalizeBody = (body: object = {}) => {
|
||||
const normalizedObjectsSet = new WeakSet();
|
||||
const normalizeObject = (object: any) => {
|
||||
const normalizeObject = (object: object) => {
|
||||
if (normalizedObjectsSet.has(object)) return;
|
||||
normalizedObjectsSet.add(object);
|
||||
if (Array.isArray(object)) {
|
||||
for (const [index, value] of object.entries()) {
|
||||
for (const [, value] of object.entries()) {
|
||||
if (typeof value === "object") normalizeObject(value);
|
||||
}
|
||||
} else {
|
||||
@@ -75,6 +75,8 @@ export const normalizeBody = (body: any = {}) => {
|
||||
key === "discovery_splash"
|
||||
)
|
||||
continue;
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
//@ts-ignore
|
||||
delete object[key];
|
||||
} else if (typeof value === "object") {
|
||||
normalizeObject(value);
|
||||
|
||||
Reference in New Issue
Block a user