enable no-unused-vars eslint rule for BE

pull/30/head
Dario Piotrowicz 2023-01-06 10:06:16 +01:00
rodzic fb13b0f309
commit 870dd60c3b
31 zmienionych plików z 32 dodań i 69 usunięć

Wyświetl plik

@ -15,6 +15,7 @@ module.exports = {
'prefer-const': 'error',
'no-var': 'error',
'@typescript-eslint/no-unsafe-return': 'error',
'@typescript-eslint/no-unused-vars': 'error',
/*
Note: the following rules have been set to off so that linting
can pass with the current code, but we need to gradually
@ -35,7 +36,6 @@ module.exports = {
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-inferrable-types': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/ban-types': 'off',

Wyświetl plik

@ -48,12 +48,6 @@ export type PluginArgs = {
domain: string
}
type CloudflareAccessPagesPluginFunction<
Env = unknown,
Params extends string = any,
Data extends Record<string, unknown> = Record<string, unknown>
> = PagesPluginFunction<Env, Params, Data, PluginArgs>
// Adapted slightly from https://github.com/cloudflare/workers-access-external-auth-example
const base64URLDecode = (s: string) => {
s = s.replace(/-/g, '+').replace(/_/g, '/').replace(/\s/g, '')
@ -85,6 +79,7 @@ export function getPayload(jwt: string): JWTPayload {
export const generateValidator =
({ domain, aud, jwt }: { domain: string; aud: string; jwt: string }) =>
async (
// eslint-disable-next-line @typescript-eslint/no-unused-vars
request: Request
): Promise<{
payload: object

Wyświetl plik

@ -1,6 +1,5 @@
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-announce
import type { Object } from '../objects'
import type { Actor } from '../actors'
import type { Activity } from '.'

Wyświetl plik

@ -2,7 +2,6 @@ import * as actors from 'wildebeest/backend/src/activitypub/actors'
import { addObjectInOutbox } from 'wildebeest/backend/src/activitypub/actors/outbox'
import { actorURL } from 'wildebeest/backend/src/activitypub/actors'
import * as objects from 'wildebeest/backend/src/activitypub/objects'
import type { Actor } from 'wildebeest/backend/src/activitypub/actors'
import * as accept from 'wildebeest/backend/src/activitypub/activities/accept'
import { addObjectInInbox } from 'wildebeest/backend/src/activitypub/actors/inbox'
import {

Wyświetl plik

@ -1,6 +1,5 @@
// https://www.w3.org/TR/activitystreams-vocabulary/#dfn-like
import type { Object } from '../objects'
import type { Actor } from '../actors'
import type { Activity } from '.'

Wyświetl plik

@ -1,5 +1,5 @@
import type { Actor } from 'wildebeest/backend/src/activitypub/actors'
import type { OrderedCollection, OrderedCollectionPage } from 'wildebeest/backend/src/activitypub/core'
import type { OrderedCollection } from 'wildebeest/backend/src/activitypub/core'
const headers = {
accept: 'application/activity+json',

Wyświetl plik

@ -1,4 +1,3 @@
import { MastodonAccount } from 'wildebeest/backend/src/types/account'
import { defaultImages } from 'wildebeest/config/accounts'
import { generateUserKey } from 'wildebeest/backend/src/utils/key-ops'
import type { Object } from '../objects'

Wyświetl plik

@ -43,6 +43,7 @@ export async function get(actor: Actor): Promise<OrderedCollection<Activity>> {
return collection
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async function loadItems<T>(collection: OrderedCollection<T>, max: number): Promise<Array<T>> {
// FIXME: implement max and multi page support

Wyświetl plik

@ -1,4 +1,3 @@
import type { Actor } from 'wildebeest/backend/src/activitypub/actors'
import type { UUID } from 'wildebeest/backend/src/types'
// https://www.w3.org/TR/activitystreams-vocabulary/#object-types
@ -128,6 +127,7 @@ export async function cacheObject(
}
export async function updateObject(db: D1Database, properties: any, id: URL): Promise<boolean> {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const res: any = await db
.prepare('UPDATE objects SET properties = ? WHERE id = ?')
.bind(JSON.stringify(properties), id.toString())

Wyświetl plik

@ -25,8 +25,6 @@ export async function addFollowing(db: D1Database, actor: Actor, target: Actor,
// Accept the pending following request
export async function acceptFollowing(db: D1Database, actor: Actor, target: Actor) {
const id = crypto.randomUUID()
const query = `
UPDATE actor_following SET state=? WHERE actor_id=? AND target_actor_id=? AND state=?
`

Wyświetl plik

@ -1,5 +1,4 @@
import type { Object } from 'wildebeest/backend/src/activitypub/objects'
import type { JWK } from 'wildebeest/backend/src/webpush/jwk'
import * as actors from 'wildebeest/backend/src/activitypub/actors'
import { urlToHandle } from 'wildebeest/backend/src/utils/handle'
import { loadExternalMastodonAccount } from 'wildebeest/backend/src/mastodon/account'
@ -9,7 +8,6 @@ import type { WebPushInfos, WebPushMessage } from 'wildebeest/backend/src/webpus
import { WebPushResult } from 'wildebeest/backend/src/webpush/webpushinfos'
import type { Actor } from 'wildebeest/backend/src/activitypub/actors'
import type { NotificationType, Notification } from 'wildebeest/backend/src/types/notification'
import type { Subscription } from 'wildebeest/backend/src/mastodon/subscription'
import { getSubscriptionForAllClients } from 'wildebeest/backend/src/mastodon/subscription'
import { getVAPIDKeys } from 'wildebeest/backend/src/mastodon/subscription'
import * as config from 'wildebeest/backend/src/config'

Wyświetl plik

@ -2,11 +2,9 @@ import type { Handle } from '../utils/parse'
import type { MediaAttachment } from 'wildebeest/backend/src/types/media'
import type { UUID } from 'wildebeest/backend/src/types'
import { getObjectByMastodonId, getObjectById } from 'wildebeest/backend/src/activitypub/objects'
import type { Object } from 'wildebeest/backend/src/activitypub/objects'
import type { Note } from 'wildebeest/backend/src/activitypub/objects/note'
import { loadExternalMastodonAccount } from 'wildebeest/backend/src/mastodon/account'
import * as actors from 'wildebeest/backend/src/activitypub/actors'
import * as objects from 'wildebeest/backend/src/activitypub/objects'
import * as media from 'wildebeest/backend/src/media/'
import type { MastodonStatus } from 'wildebeest/backend/src/types'
import { parseHandle } from '../utils/parse'

Wyświetl plik

@ -2,7 +2,6 @@ import type { MastodonStatus } from 'wildebeest/backend/src/types/status'
import { getFollowingId } from 'wildebeest/backend/src/mastodon/follow'
import type { Actor } from 'wildebeest/backend/src/activitypub/actors/'
import { toMastodonStatusFromRow } from './status'
import { emailSymbol } from 'wildebeest/backend/src/activitypub/actors/'
export async function pregenerateTimelines(domain: string, db: D1Database, cache: KVNamespace, actor: Actor) {
const timeline = await getHomeTimeline(domain, db, actor)

Wyświetl plik

@ -1,5 +1,3 @@
import type { MediaAttachment } from 'wildebeest/backend/src/types/media'
export type Config = {
accountId: string
apiToken: string

Wyświetl plik

@ -1,5 +1,4 @@
import type { MediaAttachment } from 'wildebeest/backend/src/types/media'
import type { Document } from 'wildebeest/backend/src/activitypub/objects'
import { IMAGE } from 'wildebeest/backend/src/activitypub/objects/image'
import type { Object } from 'wildebeest/backend/src/activitypub/objects'

Wyświetl plik

@ -1,9 +1,7 @@
import * as access from 'wildebeest/backend/src/access'
import * as actors from 'wildebeest/backend/src/activitypub/actors'
import type { Env } from 'wildebeest/backend/src/types/env'
import type { Identity, ContextData } from 'wildebeest/backend/src/types/context'
import * as errors from 'wildebeest/backend/src/errors'
import { loadLocalMastodonAccount } from 'wildebeest/backend/src/mastodon/account'
async function loadContextData(db: D1Database, clientId: string, email: string, ctx: any): Promise<boolean> {
const query = `

Wyświetl plik

@ -1,4 +1,3 @@
import type { MastodonAccount } from 'wildebeest/backend/src/types/account'
import type { Person } from 'wildebeest/backend/src/activitypub/actors'
export type Identity = {

Wyświetl plik

@ -1,5 +1,3 @@
import { MastodonAccount } from '../types/account'
import * as config from 'wildebeest/backend/src/config'
import * as actors from '../activitypub/actors'
import type { Actor } from '../activitypub/actors'

Wyświetl plik

@ -1,12 +1,12 @@
import { makeDB, assertCache, isUrlValid } from './utils'
import { addFollowing, acceptFollowing } from 'wildebeest/backend/src/mastodon/follow'
import { makeDB, isUrlValid } from './utils'
import { addFollowing } from 'wildebeest/backend/src/mastodon/follow'
import { createPerson } from 'wildebeest/backend/src/activitypub/actors'
import { configure, generateVAPIDKeys } from 'wildebeest/backend/src/config'
import * as activityHandler from 'wildebeest/backend/src/activitypub/activities/handle'
import { createPublicNote } from 'wildebeest/backend/src/activitypub/objects/note'
import { addObjectInOutbox } from 'wildebeest/backend/src/activitypub/actors/outbox'
import { strict as assert } from 'node:assert/strict'
import { cacheObject, createObject } from 'wildebeest/backend/src/activitypub/objects/'
import { cacheObject } from 'wildebeest/backend/src/activitypub/objects/'
import * as ap_users from 'wildebeest/functions/ap/users/[id]'
import * as ap_outbox from 'wildebeest/functions/ap/users/[id]/outbox'
@ -87,7 +87,7 @@ describe('ActivityPub', () => {
test('Object must be an object', async () => {
const db = await makeDB()
const actor = await createPerson(domain, db, userKEK, 'sven@cloudflare.com')
await createPerson(domain, db, userKEK, 'sven@cloudflare.com')
const activity = {
'@context': 'https://www.w3.org/ns/activitystreams',
@ -105,7 +105,7 @@ describe('ActivityPub', () => {
describe('Create', () => {
test('Object must be an object', async () => {
const db = await makeDB()
const actor = await createPerson(domain, db, userKEK, 'sven@cloudflare.com')
await createPerson(domain, db, userKEK, 'sven@cloudflare.com')
const activity = {
'@context': 'https://www.w3.org/ns/activitystreams',
@ -278,7 +278,7 @@ describe('ActivityPub', () => {
const db = await makeDB()
await configure(db, { title: 'title', description: 'a', email: 'email' })
await generateVAPIDKeys(db)
const actor = await createPerson(domain, db, userKEK, 'sven@cloudflare.com')
await createPerson(domain, db, userKEK, 'sven@cloudflare.com')
const activity: any = {
type: 'Announce',

Wyświetl plik

@ -6,7 +6,7 @@ import * as ap_followers from 'wildebeest/functions/ap/users/[id]/followers'
import * as ap_following from 'wildebeest/functions/ap/users/[id]/following'
import { addFollowing, acceptFollowing } from 'wildebeest/backend/src/mastodon/follow'
import { strict as assert } from 'node:assert/strict'
import { makeDB, assertCache, isUrlValid } from '../utils'
import { makeDB } from '../utils'
import { createPerson } from 'wildebeest/backend/src/activitypub/actors'
const userKEK = 'test_kek10'

Wyświetl plik

@ -1,4 +1,4 @@
import { makeDB, assertCache, isUrlValid } from '../utils'
import { makeDB } from '../utils'
import { generateVAPIDKeys, configure } from 'wildebeest/backend/src/config'
import * as objects from 'wildebeest/backend/src/activitypub/objects'
import { createPublicNote } from 'wildebeest/backend/src/activitypub/objects/note'

Wyświetl plik

@ -2,19 +2,13 @@ import { strict as assert } from 'node:assert/strict'
import * as v1_instance from 'wildebeest/functions/api/v1/instance'
import * as apps from 'wildebeest/functions/api/v1/apps'
import * as custom_emojis from 'wildebeest/functions/api/v1/custom_emojis'
import * as notifications from 'wildebeest/functions/api/v1/notifications'
import { defaultImages } from 'wildebeest/config/accounts'
import { isUrlValid, makeDB, assertCORS, assertJSON, assertCache, streamToArrayBuffer, createTestClient } from './utils'
import { loadLocalMastodonAccount } from 'wildebeest/backend/src/mastodon/account'
import { getSigningKey } from 'wildebeest/backend/src/mastodon/account'
import { Actor, createPerson, getPersonById } from 'wildebeest/backend/src/activitypub/actors'
import { createClient, getClientById } from '../src/mastodon/client'
import { makeDB, assertCORS, assertJSON, assertCache, createTestClient } from './utils'
import { createPerson } from 'wildebeest/backend/src/activitypub/actors'
import { createSubscription } from '../src/mastodon/subscription'
import * as subscription from 'wildebeest/functions/api/v1/push/subscription'
import { configure, generateVAPIDKeys } from 'wildebeest/backend/src/config'
const userKEK = 'test_kek'
const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms))
const domain = 'cloudflare.com'
describe('Mastodon APIs', () => {
@ -75,6 +69,7 @@ describe('Mastodon APIs', () => {
assertCORS(res)
assertJSON(res)
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { name, website, redirect_uri, client_id, client_secret, vapid_key, ...rest } = await res.json<
Record<string, string>
>()

Wyświetl plik

@ -11,7 +11,7 @@ import * as accounts_follow from 'wildebeest/functions/api/v1/accounts/[id]/foll
import * as accounts_unfollow from 'wildebeest/functions/api/v1/accounts/[id]/unfollow'
import * as accounts_statuses from 'wildebeest/functions/api/v1/accounts/[id]/statuses'
import * as accounts_get from 'wildebeest/functions/api/v1/accounts/[id]'
import { isUrlValid, makeDB, assertCORS, assertJSON, assertCache, streamToArrayBuffer } from '../utils'
import { isUrlValid, makeDB, assertCORS, assertJSON } from '../utils'
import * as accounts_verify_creds from 'wildebeest/functions/api/v1/accounts/verify_credentials'
import * as accounts_update_creds from 'wildebeest/functions/api/v1/accounts/update_credentials'
import { createPerson, getPersonById } from 'wildebeest/backend/src/activitypub/actors'
@ -362,7 +362,7 @@ describe('Mastodon APIs', () => {
test('get pinned statuses', async () => {
const db = await makeDB()
const actor = await createPerson(domain, db, userKEK, 'sven@cloudflare.com')
await createPerson(domain, db, userKEK, 'sven@cloudflare.com')
const req = new Request('https://' + domain + '?pinned=true')
const res = await accounts_statuses.handleRequest(req, db, 'sven@' + domain, userKEK)
@ -510,7 +510,7 @@ describe('Mastodon APIs', () => {
await generateVAPIDKeys(db)
const actor = await createPerson(domain, db, userKEK, 'sven@cloudflare.com')
const localNote = await createPublicNote(domain, db, 'my localnote status', actor)
await createPublicNote(domain, db, 'my localnote status', actor)
globalThis.fetch = async (input: RequestInfo) => {
if (input.toString() === 'https://social.com/.well-known/webfinger?resource=acct%3Asomeone%40social.com') {
@ -586,7 +586,7 @@ describe('Mastodon APIs', () => {
})
test('get local actor followers', async () => {
globalThis.fetch = async (input: any, opts: any) => {
globalThis.fetch = async (input: any) => {
if (input.toString() === 'https://' + domain + '/ap/users/sven2') {
return new Response(
JSON.stringify({
@ -615,7 +615,7 @@ describe('Mastodon APIs', () => {
})
test('get local actor following', async () => {
globalThis.fetch = async (input: any, opts: any) => {
globalThis.fetch = async (input: any) => {
if (input.toString() === 'https://' + domain + '/ap/users/sven2') {
return new Response(
JSON.stringify({
@ -752,7 +752,7 @@ describe('Mastodon APIs', () => {
beforeEach(() => {
receivedActivity = null
globalThis.fetch = async (input: any, opts: any) => {
globalThis.fetch = async (input: any) => {
if (
input.toString() ===
'https://' + domain + '/.well-known/webfinger?resource=acct%3Aactor%40' + domain + ''

Wyświetl plik

@ -12,7 +12,7 @@ const domain = 'cloudflare.com'
describe('Mastodon APIs', () => {
describe('media', () => {
test('upload image creates object', async () => {
globalThis.fetch = async (input: RequestInfo, data: any) => {
globalThis.fetch = async (input: RequestInfo) => {
if (input === 'https://api.cloudflare.com/client/v4/accounts/testaccountid/images/v1') {
return new Response(
JSON.stringify({

Wyświetl plik

@ -3,7 +3,7 @@ import { createPublicNote } from 'wildebeest/backend/src/activitypub/objects/not
import { createNotification, insertFollowNotification } from 'wildebeest/backend/src/mastodon/notification'
import { createPerson } from 'wildebeest/backend/src/activitypub/actors'
import * as notifications from 'wildebeest/functions/api/v1/notifications'
import { makeDB, assertJSON, assertCORS, createTestClient } from '../utils'
import { makeDB, assertJSON, createTestClient } from '../utils'
import { strict as assert } from 'node:assert/strict'
import { sendLikeNotification } from 'wildebeest/backend/src/mastodon/notification'
import { createSubscription } from 'wildebeest/backend/src/mastodon/subscription'

Wyświetl plik

@ -2,15 +2,7 @@ import { getSigningKey } from 'wildebeest/backend/src/mastodon/account'
import * as oauth_authorize from 'wildebeest/functions/oauth/authorize'
import * as first_login from 'wildebeest/functions/first-login'
import * as oauth_token from 'wildebeest/functions/oauth/token'
import {
isUrlValid,
makeDB,
assertCORS,
assertJSON,
assertCache,
streamToArrayBuffer,
createTestClient,
} from '../utils'
import { isUrlValid, makeDB, assertCORS, assertJSON, createTestClient } from '../utils'
import { TEST_JWT, ACCESS_CERTS } from '../test-data'
import { strict as assert } from 'node:assert/strict'

Wyświetl plik

@ -1,7 +1,7 @@
import * as search from 'wildebeest/functions/api/v2/search'
import { createPerson } from 'wildebeest/backend/src/activitypub/actors'
import { defaultImages } from 'wildebeest/config/accounts'
import { isUrlValid, makeDB, assertCORS, assertJSON, assertCache } from '../utils'
import { makeDB, assertCORS, assertJSON } from '../utils'
import { strict as assert } from 'node:assert/strict'
const userKEK = 'test_kek11'

Wyświetl plik

@ -12,7 +12,7 @@ import * as statuses_context from 'wildebeest/functions/api/v1/statuses/[id]/con
import { createPerson } from 'wildebeest/backend/src/activitypub/actors'
import { insertLike } from 'wildebeest/backend/src/mastodon/like'
import { insertReblog } from 'wildebeest/backend/src/mastodon/reblog'
import { isUrlValid, makeDB, assertCORS, assertJSON, assertCache, streamToArrayBuffer } from '../utils'
import { isUrlValid, makeDB, assertJSON, streamToArrayBuffer } from '../utils'
import * as note from 'wildebeest/backend/src/activitypub/objects/note'
const userKEK = 'test_kek4'
@ -100,7 +100,6 @@ describe('Mastodon APIs', () => {
const res = await statuses.handleRequest(req, db, connectedActor, userKEK)
assert.equal(res.status, 200)
const data = await res.json<any>()
const row = await db.prepare(`SELECT count(*) as count FROM outbox_objects`).first()
assert.equal(row.count, 1)
})
@ -224,7 +223,7 @@ describe('Mastodon APIs', () => {
)
.run()
globalThis.fetch = async (input: any, data: any) => {
globalThis.fetch = async (input: any) => {
if (input === actor.id.toString()) {
return new Response(
JSON.stringify({
@ -452,7 +451,7 @@ describe('Mastodon APIs', () => {
)
.run()
globalThis.fetch = async (input: any, data: any) => {
globalThis.fetch = async (input: any) => {
if (input === actor.id.toString()) {
return new Response(
JSON.stringify({

Wyświetl plik

@ -5,7 +5,7 @@ import { addFollowing, acceptFollowing } from 'wildebeest/backend/src/mastodon/f
import { createPublicNote } from 'wildebeest/backend/src/activitypub/objects/note'
import { addObjectInOutbox } from 'wildebeest/backend/src/activitypub/actors/outbox'
import { createPerson } from 'wildebeest/backend/src/activitypub/actors'
import { makeDB, assertCORS, assertJSON, assertCache } from '../utils'
import { makeDB, assertCORS, assertJSON } from '../utils'
import * as timelines_home from 'wildebeest/functions/api/v1/timelines/home'
import * as timelines_public from 'wildebeest/functions/api/v1/timelines/public'
import * as timelines from 'wildebeest/backend/src/mastodon/timeline'

Wyświetl plik

@ -1,6 +1,6 @@
import { strict as assert } from 'node:assert/strict'
import * as trends_statuses from 'wildebeest/functions/api/v1/trends/statuses'
import { makeDB, assertJSON } from '../utils'
import { assertJSON } from '../utils'
describe('Mastodon APIs', () => {
describe('trends', () => {

Wyświetl plik

@ -7,7 +7,7 @@ import { generateUserKey, unwrapPrivateKey, importPublicKey } from 'wildebeest/b
import { signRequest } from 'wildebeest/backend/src/utils/http-signing'
import { generateDigestHeader } from 'wildebeest/backend/src/utils/http-signing-cavage'
import { parseRequest } from 'wildebeest/backend/src/utils/httpsigjs/parser'
import { fetchKey, verifySignature } from 'wildebeest/backend/src/utils/httpsigjs/verifier'
import { verifySignature } from 'wildebeest/backend/src/utils/httpsigjs/verifier'
describe('utils', () => {
test('user key lifecycle', async () => {