Skip to content

Commit

Permalink
Merge pull request #557 from josefaidt/fix-ci-enforce-type-imports
Browse files Browse the repository at this point in the history
enforce consistent imports, types, etc.
  • Loading branch information
AnilMaktala authored Feb 26, 2024
2 parents 24d5435 + 9fdea29 commit fd451a2
Show file tree
Hide file tree
Showing 66 changed files with 983 additions and 148 deletions.
2 changes: 1 addition & 1 deletion apps/discord-bot-frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"express": "^4.18.1",
"fast-glob": "^3.2.11",
"prisma": "^4.5.0",
"svelte": "4.2.1",
"uuid": "^8.3.2",
"zod": "^3.19.1"
},
Expand Down Expand Up @@ -64,6 +63,7 @@
"d3-sankey": "^0.12.3",
"esbuild": "^0.19.2",
"jsdom": "^20.0.0",
"svelte": "4.2.1",
"svelte-check": "^3.5.0",
"tasuku": "^2.0.1",
"tslib": "^2.6.2",
Expand Down
2 changes: 1 addition & 1 deletion apps/discord-bot-frontend/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defineConfig, devices } from '@playwright/test'
import { loadEnvVars } from './vite.config'
import { z } from 'zod'
import { loadEnvVars } from './vite.config'

loadEnvVars()

Expand Down
2 changes: 1 addition & 1 deletion apps/discord-bot-frontend/scripts/seed.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { DiscordUser, DiscordRole, Prisma } from '@prisma/client'
import { faker } from '@faker-js/faker'
import task from 'tasuku'
import { prisma, init } from '$lib/db'
import { ACCESS_LEVELS } from '$lib/constants'
import type { DiscordUser, DiscordRole, Prisma } from '@prisma/client'

function createFakeUsers(): Prisma.DiscordUserCreateInput[] {
return Array.from({ length: 10 }).map(() => ({
Expand Down
2 changes: 1 addition & 1 deletion apps/discord-bot-frontend/src/app.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-empty-interface */
/// <reference types="@sveltejs/kit" />
import * as Auth from '@auth/core/types'
import type { APIGuild } from 'discord.js'
import type * as Auth from '@auth/core/types'

interface User extends Auth.User {
id: string
Expand Down
4 changes: 2 additions & 2 deletions apps/discord-bot-frontend/src/lib/auth/config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { AppSession } from '../../app'
import type { SvelteKitAuthConfig } from '@auth/sveltekit'
import GitHub from '@auth/core/providers/github'
import Discord from '@auth/core/providers/discord'
import { get } from 'svelte/store'
import { PrismaAdapter } from '@next-auth/prisma-adapter'
import { getUserAccess } from '$lib/discord/get-user-access'
import { prisma } from '$lib/db'
import { guild } from '$lib/store'
import type { AppSession } from '../../app'
import type { SvelteKitAuthConfig } from '@auth/sveltekit'

export const config: SvelteKitAuthConfig = {
adapter: PrismaAdapter(prisma),
Expand Down
2 changes: 1 addition & 1 deletion apps/discord-bot-frontend/src/lib/discord/api.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { REST } from '@discordjs/rest'
import type {
RESTOptions,
InternalRequest,
RequestMethod,
} from '@discordjs/rest'
import { REST } from '@discordjs/rest'

// we'll want to eventually expand this interface with more options specific to our DX
// eslint-disable-next-line @typescript-eslint/no-empty-interface
Expand Down
4 changes: 2 additions & 2 deletions apps/discord-bot-frontend/src/lib/discord/client.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Question } from '@prisma/client'
import {
Client,
GatewayIntentBits,
Expand All @@ -10,17 +11,16 @@ import {
type ThreadChannel,
type Guild,
} from 'discord.js'
import { prisma } from '$lib/db'
import {
commands,
createCommandFeatures,
syncRegisteredCommandsForGuild,
} from './commands'
import { PREFIXES } from './commands/thread'
import { isHelpChannel, isThreadWithinHelpChannel } from './support'
import { prisma } from '$lib/db'
import { integrations } from '$lib/features/index'
import { FEATURE_TYPES } from '$lib/constants'
import type { Question } from '@prisma/client'

export const client = new Client({
intents: [
Expand Down
4 changes: 2 additions & 2 deletions apps/discord-bot-frontend/src/lib/discord/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import {
type MessagePayload,
type InteractionEditReplyOptions,
} from 'discord.js'
import { prisma } from '$lib/db'
import { FEATURE_TYPES } from '$lib/constants'
import * as admin from './commands/admin'
import * as contribute from './commands/contribute'
import * as github from './commands/github'
Expand All @@ -26,6 +24,8 @@ import * as selectAnswer from './commands/select-answer'
import * as thread from './commands/thread'
import * as q from './commands/q'
import { api } from './api'
import { FEATURE_TYPES } from '$lib/constants'
import { prisma } from '$lib/db'

type AuthoredCommand = {
handler: (
Expand Down
18 changes: 9 additions & 9 deletions apps/discord-bot-frontend/src/lib/discord/commands/admin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import type {
Message,
ChatInputCommandInteraction,
InteractionReplyOptions,
ThreadChannel,
} from 'discord.js'
import type { Question } from '@prisma/client'
import { SlashCommandBuilder } from '@discordjs/builders'
import { faker } from '@faker-js/faker'
import { EmbedBuilder, PermissionFlagsBits } from 'discord.js'
import { isThreadWithinHelpChannel } from '../support'
import { repositoriesWithDiscussions as repositories } from './_repositories'
import { getUserAccess } from '$lib/discord/get-user-access'
import { prisma } from '$lib/db'
import {
Expand All @@ -9,15 +18,6 @@ import {
markAnswered,
lockDiscussion,
} from '$lib/github/queries'
import { repositoriesWithDiscussions as repositories } from './_repositories'
import { isThreadWithinHelpChannel } from '../support'
import type {
Message,
ChatInputCommandInteraction,
InteractionReplyOptions,
ThreadChannel,
} from 'discord.js'
import type { Question } from '@prisma/client'

const userIdToUsername = new Map<string, User>()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { SlashCommandBuilder } from '@discordjs/builders'
import { repositories } from './_repositories'
import type {
ChatInputCommandInteraction,
InteractionReplyOptions,
} from 'discord.js'
import { SlashCommandBuilder } from '@discordjs/builders'
import { repositories } from './_repositories'

export const config = new SlashCommandBuilder()
.setName('contribute')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ChatInputCommandInteraction } from 'discord.js'
import { SlashCommandBuilder } from '@discordjs/builders'
import { repositories } from './_repositories'
import type { ChatInputCommandInteraction } from 'discord.js'

export const config = new SlashCommandBuilder()
.setName('github')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { SlashCommandBuilder } from '@discordjs/builders'
import type {
ChatInputCommandInteraction,
InteractionReplyOptions,
} from 'discord.js'
import { SlashCommandBuilder } from '@discordjs/builders'

export const config = new SlashCommandBuilder()
.setName('login')
Expand Down
14 changes: 7 additions & 7 deletions apps/discord-bot-frontend/src/lib/discord/commands/q.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { EmbedBuilder, ButtonStyle } from 'discord.js'
import {
SlashCommandBuilder,
ActionRowBuilder,
ButtonBuilder,
} from '@discordjs/builders'
import { prisma } from '$lib/db'
import type {
ButtonInteraction,
ChatInputCommandInteraction,
InteractionReplyOptions,
TextBasedChannel,
} from 'discord.js'
import type { Question } from '@prisma/client'
import { EmbedBuilder, ButtonStyle } from 'discord.js'
import {
SlashCommandBuilder,
ActionRowBuilder,
ButtonBuilder,
} from '@discordjs/builders'
import { prisma } from '$lib/db'

function epoch(date: Date): number {
return Math.floor(date.getTime() / 1000)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { ContextMenuCommandBuilder } from '@discordjs/builders'
import { ApplicationCommandType, EmbedBuilder } from 'discord.js'
import { prisma } from '$lib/db'
import { isAdminOrStaff } from '../is-admin-or-staff'
import type {
GuildMember,
MessageContextMenuCommandInteraction,
} from 'discord.js'
import { ContextMenuCommandBuilder } from '@discordjs/builders'
import { ApplicationCommandType, EmbedBuilder } from 'discord.js'
import { isAdminOrStaff } from '../is-admin-or-staff'
import { parseTitle, parseTitlePrefix, fitsPrefix, truncateSuffix, PREFIXES } from './thread'
import { prisma } from '$lib/db'

export const config = new ContextMenuCommandBuilder()
.setName('select-answer')
Expand Down
10 changes: 5 additions & 5 deletions apps/discord-bot-frontend/src/lib/discord/commands/thread.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { SlashCommandBuilder } from '@discordjs/builders'
import { EmbedBuilder, MessageType } from 'discord.js'
import { prisma } from '$lib/db'
import { isThreadWithinHelpChannel } from '../support'
import { isAdminOrStaff } from '../is-admin-or-staff'
import type {
ChatInputCommandInteraction,
GuildMember,
ThreadChannel,
InteractionReplyOptions,
} from 'discord.js'
import { SlashCommandBuilder } from '@discordjs/builders'
import { EmbedBuilder, MessageType } from 'discord.js'
import { isThreadWithinHelpChannel } from '../support'
import { isAdminOrStaff } from '../is-admin-or-staff'
import { prisma } from '$lib/db'

export const PREFIXES = {
solved: '✅ - ',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { APIGuild } from 'discord.js'
import { Routes } from 'discord.js'
import { api } from './api'
import type { APIGuild } from 'discord.js'

/**
* Fetches the bot's guilds
Expand Down
4 changes: 2 additions & 2 deletions apps/discord-bot-frontend/src/lib/discord/get-user-access.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { APIGuild, APIGuildMember } from 'discord-api-types/v10'
import { Routes } from 'discord-api-types/v10'
import { api } from './api'
import { ACCESS_LEVELS } from '$lib/constants'
import { prisma } from '$lib/db'
import { api } from './api'
import type { APIGuild, APIGuildMember } from 'discord-api-types/v10'

export async function getUserAccess(
guildMemberId: string,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { GuildMember } from 'discord.js'
import { ACCESS_LEVELS } from '$lib/constants'
import { prisma } from '$lib/db'
import type { GuildMember } from 'discord.js'

export async function isAdminOrStaff(user: GuildMember) {
const data = await prisma.configuration.findUnique({
Expand Down
2 changes: 1 addition & 1 deletion apps/discord-bot-frontend/src/lib/discord/roles/addRole.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { api } from '$lib/discord/api'
import { Routes } from 'discord-api-types/v10'
import { api } from '$lib/discord/api'

/** applies a role to a given user */
export async function addRole(roleId: string, guildId: string, userId: string) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { api } from '$lib/discord/api'
import { Routes } from 'discord-api-types/v10'
import { api } from '$lib/discord/api'

/** removes a role from a given user */
export async function removeRole(
Expand Down
2 changes: 1 addition & 1 deletion apps/discord-bot-frontend/src/lib/features/is-enabled.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { FEATURE_CODES } from '$lib/constants'
import { prisma } from '$lib/db'
import { FEATURE_CODES } from '$lib/constants'

export const isEnabled = async (
code: keyof typeof FEATURE_CODES,
Expand Down
4 changes: 2 additions & 2 deletions apps/discord-bot-frontend/src/lib/notifications.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { writable } from 'svelte/store'
import { v4 as uuid } from 'uuid'
import type { Readable } from 'svelte/store'
import type { ToastNotificationProps } from 'carbon-components-svelte/types/Notification/ToastNotification.svelte'
import { writable } from 'svelte/store'
import { v4 as uuid } from 'uuid'

type Notification = ToastNotificationProps & {
id: string
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Handle } from '@sveltejs/kit'
import { SvelteKitAuth } from '@auth/sveltekit'
import { config } from '$lib/auth/config'
import type { Handle } from '@sveltejs/kit'

/**
* @todo use session callback to extend session?
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import cookie from 'cookie'
import type { Handle, RequestEvent } from '@sveltejs/kit'
import * as cookie from 'cookie'
import { Routes } from 'discord.js'
import { GUILD_COOKIE } from '$lib/constants'
import { api } from '$lib/discord/api'
import { getBotGuilds } from '$lib/discord/get-bot-guilds'
import type { Handle, RequestEvent } from '@sveltejs/kit'

/**
* Parse cookies from the event and returns the value of the guild cookie
Expand Down
2 changes: 1 addition & 1 deletion apps/discord-bot-frontend/src/lib/store.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Writable } from 'svelte/store'
import { derived, writable } from 'svelte/store'
import { page } from '$app/stores'
import type { Writable } from 'svelte/store'

export { store as notifications } from './notifications'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { redirect } from '@sveltejs/kit'
import type { LayoutServerLoad } from './$types'
import { redirect } from '@sveltejs/kit'

export const load: LayoutServerLoad = async ({ locals }) => {
if (locals.session?.user?.isAdmin || locals.session?.user?.isGuildOwner) {
Expand Down
6 changes: 3 additions & 3 deletions apps/discord-bot-frontend/src/routes/admin/+page.server.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { PageServerLoad } from './$types'
import { error } from '@sveltejs/kit'
import {
type Configuration,
Expand All @@ -11,16 +12,15 @@ import {
type RESTGetAPIGuildRolesResult,
type RESTGetAPIApplicationCommandResult,
} from 'discord-api-types/v10'
import { api } from '../api/_discord'
import { tabs } from './tabs'
import { env } from '$env/dynamic/private'
import {
commands as bank,
type Command as CommandType,
} from '$lib/discord/commands'
import { prisma } from '$lib/db'
import { FEATURE_TYPES } from '$lib/constants'
import type { PageServerLoad } from './$types'
import { api } from '../api/_discord'
import { tabs } from './tabs'

type AdminPageReturn = {
commands: Array<
Expand Down
2 changes: 1 addition & 1 deletion apps/discord-bot-frontend/src/routes/admin/breadcrumbs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { page } from '$app/stores'
import { derived } from 'svelte/store'
import { page } from '$app/stores'

export const createIntegrationHrefFromCode = (code: string) => {
return `/admin/integrations/${code.toLowerCase()}`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { prisma } from '$lib/db'
import { FEATURE_TYPES } from '$lib/constants'
import type { PageServerLoad } from './$types'
import { createIntegrationHrefFromCode } from '../breadcrumbs'
import { prisma } from '$lib/db'
import { FEATURE_TYPES } from '$lib/constants'

export const load: PageServerLoad = async ({ locals }) => {
const integrations = await prisma.configurationFeature.findMany({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { prisma } from '$lib/db'
import type { PageServerLoad } from './$types'
import { prisma } from '$lib/db'

export const load: PageServerLoad = async ({ locals, params }) => {
const { code } = params
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { RequestHandler } from '@sveltejs/kit'
import { json } from '@sveltejs/kit'
import { prisma } from '$lib/db'
import { ACCESS_LEVELS } from '$lib/constants'
import type { RequestHandler } from '@sveltejs/kit'

export const POST: RequestHandler = async ({ request }) => {
const { id, name, adminRoles, staffRoles, contributorRoles } =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { FEATURE_CODES } from '$lib/constants'
import { type RequestHandler } from '@sveltejs/kit'
import { prisma } from '$lib/db'
import { FEATURE_CODES } from '$lib/constants'

type Payload = {
/**
Expand Down
Loading

0 comments on commit fd451a2

Please sign in to comment.