Skip to content

Commit

Permalink
Add tsc to lint script and fix almost all warnings (#193)
Browse files Browse the repository at this point in the history
* Add `tsc` to `lint` script and fix almost all warnings

* remove useless comment i copied from stackoverflow
  • Loading branch information
mat-1 authored Mar 14, 2022
1 parent b4e475d commit 3f94ebd
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 25 deletions.
10 changes: 10 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,15 @@ module.exports = {
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/ban-types': 'off',
// https://stackoverflow.com/a/64067915
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': [
'warn',
{
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_',
},
],
},
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"preview:host": "svelte-kit preview --host",
"check": "svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-check --tsconfig ./tsconfig.json --watch",
"lint": "prettier --ignore-path .gitignore --check --plugin-search-dir=. . && eslint --ignore-path .gitignore .",
"lint": "prettier --ignore-path .gitignore --check --plugin-search-dir=. . && eslint --ignore-path .gitignore . && tsc --noEmit",
"format": "prettier --ignore-path .gitignore --write --plugin-search-dir=. . && eslint --ignore-path .gitignore --fix .",
"register-commands": "node --experimental-specifier-resolution=node --loader ts-node/esm src/lib/discord/scripts/registerCommands.ts"
},
Expand Down
1 change: 0 additions & 1 deletion src/lib/database/entries.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { Collection } from 'mongodb'
import { createUuid, getDatabase, ReplaceIdWithUuid, replaceUuidWithId } from '.'
import { isAdmin } from '../perms'

export type Visibility = 'visible' | 'unlisted' | 'hidden'

Expand Down
3 changes: 1 addition & 2 deletions src/lib/database/sessions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { createUuid, getDatabase, ReplaceIdWithUuid, replaceIdWithUuid, replaceUuidWithId } from '.'
import type { Binary, Collection } from 'mongodb'
import type { Binary } from 'mongodb'
import { generateToken } from '../auth'
import { fetchUser } from './users'

Expand Down
5 changes: 4 additions & 1 deletion src/lib/discord/api/interactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@ import type { APIInteractionDataResolvedGuildMember, APIUser } from 'discord-api
export const APPLICATIONS_BASE_API_URL =
`https://discord.com/api/v9/applications/${process.env.DISCORD_CLIENT_ID}` as const

const DISCORD_PUBLIC_KEY = process.env.DISCORD_PUBLIC_KEY
if (DISCORD_PUBLIC_KEY) throw new Error('DISCORD_PUBLIC_KEY environment variable not set')

export function verifyInteraction(
headers: Headers,
rawBody: string | Uint8Array | ArrayBuffer
): boolean {
const signature = headers.get('x-signature-ed25519')
const timestamp = headers.get('x-signature-timestamp')
if (!signature || !timestamp) return false
return verifyKey(rawBody ?? '', signature, timestamp, process.env.DISCORD_PUBLIC_KEY)
return verifyKey(rawBody ?? '', signature, timestamp, DISCORD_PUBLIC_KEY!)
}

export async function handleInteraction(data: APIInteraction): Promise<APIInteractionResponse> {
Expand Down
2 changes: 0 additions & 2 deletions src/lib/inputs/RevertButton.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<script lang="ts">
import { goto } from '$app/navigation'
export let id: string
async function revert() {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/perms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function canSeeEntry(user: User, entry: Entry): boolean {
return entry.visibility !== 'hidden'
}

export function canEditEntry(user: User, entry: Entry): boolean {
export function canEditEntry(user: User, _entry: Entry): boolean {
return user.admin
}

Expand Down
3 changes: 0 additions & 3 deletions src/lib/revert.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import type { Entry } from './database/entries'
import {
fetchEntryHistory,
fetchEntryHistoryItemsAfter,
fetchEntryHistoryItemBefore,
HistoryItem,
} from './database/history'
import * as diff from 'fast-myers-diff'
import { createUuid } from './database'

/**
* How the entry would look if this edit was reverted
Expand Down
12 changes: 8 additions & 4 deletions src/routes/__error.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<script context="module">
export function load({ error, status }) {
<script lang="ts" context="module">
import type { ErrorLoad } from '@sveltejs/kit'
export const load: ErrorLoad = async ({ error, status }) => {
return {
props: {
status,
message: error.message,
message: error?.message,
},
}
}
Expand All @@ -21,7 +23,9 @@
<div class="error-container-container">
<div class="error-container">
<h1>{status}</h1>
<h2>{message}</h2>
{#if message}
<h2>{message}</h2>
{/if}
<a href="/">Go back</a>
</div>
</div>
Expand Down
6 changes: 4 additions & 2 deletions src/routes/__layout.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<script context="module">
export async function load({ session }) {
<script lang="ts" context="module">
import type { Load } from '@sveltejs/kit'
export const load: Load = async ({ session }) => {
return {
props: {
user: session.user,
Expand Down
14 changes: 7 additions & 7 deletions src/routes/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { createSession } from '../lib/database/sessions'
import type { RequestHandler } from '@sveltejs/kit'
import { createUuid } from '../lib/database/index'

const clientId = process.env.DISCORD_CLIENT_ID
if (!clientId) throw new Error('DISCORD_CLIENT_ID environment variable not set')
const DISCORD_CLIENT_ID = process.env.DISCORD_CLIENT_ID
if (!DISCORD_CLIENT_ID) throw new Error('DISCORD_CLIENT_ID environment variable not set')

const clientSecret = process.env.DISCORD_CLIENT_SECRET
if (!clientSecret) throw new Error('DISCORD_CLIENT_SECRET environment variable not set')
const DISCORD_CLIENT_SECRET = process.env.DISCORD_CLIENT_SECRET
if (!DISCORD_CLIENT_SECRET) throw new Error('DISCORD_CLIENT_SECRET environment variable not set')

export const get: RequestHandler = async req => {
const discordOauthCode = req.url.searchParams.get('code')
Expand All @@ -22,7 +22,7 @@ export const get: RequestHandler = async req => {
// redirect to discord login
status: 302,
headers: {
location: `https://discord.com/oauth2/authorize?client_id=${clientId}&redirect_uri=${redirectUri}&response_type=code&scope=identify`,
location: `https://discord.com/oauth2/authorize?client_id=${DISCORD_CLIENT_ID}&redirect_uri=${redirectUri}&response_type=code&scope=identify`,
},
}
}
Expand All @@ -34,8 +34,8 @@ export const get: RequestHandler = async req => {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: new URLSearchParams({
client_id: clientId,
client_secret: clientSecret,
client_id: DISCORD_CLIENT_ID,
client_secret: DISCORD_CLIENT_SECRET,
grant_type: 'authorization_code',
code: discordOauthCode,
redirect_uri: redirectUri,
Expand Down
2 changes: 1 addition & 1 deletion src/routes/logout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { RequestHandler } from '@sveltejs/kit'
const clientSecret = process.env['DISCORD_CLIENT_SECRET']
if (!clientSecret) throw new Error('DISCORD_CLIENT_SECRET environment variable not set')

export const get: RequestHandler = async req => {
export const get: RequestHandler = async _req => {
return {
status: 302,
headers: {
Expand Down

0 comments on commit 3f94ebd

Please sign in to comment.