diff --git a/biome.json b/biome.json index a563c114..2852132f 100644 --- a/biome.json +++ b/biome.json @@ -125,6 +125,7 @@ "noGlobalDirnameFilename": "error", "noProcessGlobal": "warn", "noTsIgnore": "warn", + "useReadonlyClassProperties": "error", "useConsistentObjectDefinition": { "level": "warn", "options": { diff --git a/packages/api/build.ts b/packages/api/build.ts index 0e1b37c8..57ef52cd 100644 --- a/packages/api/build.ts +++ b/packages/api/build.ts @@ -31,7 +31,7 @@ await build({ "@bull-board/ui", // Excluded because Standard Schema imports those, but the code is never executed "@valibot/to-json-schema", - "effect" + "effect", ], }); diff --git a/packages/api/plugin-loader.ts b/packages/api/plugin-loader.ts index 64e773f4..ef66626e 100644 --- a/packages/api/plugin-loader.ts +++ b/packages/api/plugin-loader.ts @@ -53,7 +53,7 @@ export class PluginLoader { * @returns {Promise} - The parsed manifest content. * @throws Will throw an error if the manifest file cannot be parsed. */ - private async parseManifestFile( + private static async parseManifestFile( manifestPath: string, manifestFile: string, ): Promise { @@ -118,7 +118,7 @@ export class PluginLoader { } const manifestPath = `${dir}/${plugin}/${manifestFile}`; - const manifest = await this.parseManifestFile( + const manifest = await PluginLoader.parseManifestFile( manifestPath, manifestFile, ); @@ -140,7 +140,7 @@ export class PluginLoader { * @returns {Promise>} - The loaded Plugin instance. * @throws Will throw an error if the entrypoint's default export is not a Plugin. */ - public async loadPlugin( + public static async loadPlugin( dir: string, entrypoint: string, ): Promise> { @@ -197,7 +197,7 @@ export class PluginLoader { return null; } - const pluginInstance = await this.loadPlugin( + const pluginInstance = await PluginLoader.loadPlugin( dir, `${plugin}/index`, ); diff --git a/packages/client/versia/base.ts b/packages/client/versia/base.ts index 91df1081..82b7e442 100644 --- a/packages/client/versia/base.ts +++ b/packages/client/versia/base.ts @@ -87,8 +87,8 @@ export class ResponseError< export class BaseClient { public constructor( protected baseUrl: URL, - private accessToken?: string, - private options: { + private readonly accessToken?: string, + private readonly options: { globalCatch?: (error: ResponseError) => void; throwOnError?: boolean; } = {}, @@ -103,6 +103,7 @@ export class BaseClient { } /** Overridable by testing */ + // biome-ignore lint/nursery/useReadonlyClassProperties: Overridable by testing private fetch = (...args: Parameters) => fetch(...args); private async request( diff --git a/packages/kit/build.ts b/packages/kit/build.ts index 21298bee..df40150d 100644 --- a/packages/kit/build.ts +++ b/packages/kit/build.ts @@ -18,7 +18,7 @@ await build({ "acorn", // Excluded because Standard Schema imports those, but the code is never executed "@valibot/to-json-schema", - "effect" + "effect", ], }); diff --git a/packages/kit/db/instance.ts b/packages/kit/db/instance.ts index 55008ad5..c064a5b0 100644 --- a/packages/kit/db/instance.ts +++ b/packages/kit/db/instance.ts @@ -180,19 +180,19 @@ export class Instance extends BaseInterface { // Go to endpoint, then follow the links to the actual metadata try { - const { json, ok, status } = await fetch(wellKnownUrl, { + const result = await fetch(wellKnownUrl, { // @ts-expect-error Bun extension proxy: config.http.proxy_address, }); - if (!ok) { + if (!result.ok) { federationResolversLogger.error`Failed to fetch ActivityPub metadata for instance ${chalk.bold( origin, - )} - HTTP ${status}`; + )} - HTTP ${result.status}`; return null; } - const wellKnown = (await json()) as { + const wellKnown = (await result.json()) as { links: { rel: string; href: string }[]; }; @@ -216,23 +216,19 @@ export class Instance extends BaseInterface { return null; } - const { - json: json2, - ok: ok2, - status: status2, - } = await fetch(metadataUrl.href, { + const result2 = await fetch(metadataUrl.href, { // @ts-expect-error Bun extension proxy: config.http.proxy_address, }); - if (!ok2) { + if (!result2.ok) { federationResolversLogger.error`Failed to fetch ActivityPub metadata for instance ${chalk.bold( origin, - )} - HTTP ${status2}`; + )} - HTTP ${result2.status}`; return null; } - const metadata = (await json2()) as { + const metadata = (await result2.json()) as { metadata: { nodeName?: string; title?: string; diff --git a/packages/kit/db/timeline.ts b/packages/kit/db/timeline.ts index 9b1908ef..6b1e825e 100644 --- a/packages/kit/db/timeline.ts +++ b/packages/kit/db/timeline.ts @@ -12,7 +12,7 @@ enum TimelineType { } export class Timeline { - public constructor(private type: TimelineType) {} + public constructor(private readonly type: TimelineType) {} public static getNoteTimeline( sql: SQL | undefined, diff --git a/packages/kit/inbox-processor.ts b/packages/kit/inbox-processor.ts index 39d6983a..f7c4a631 100644 --- a/packages/kit/inbox-processor.ts +++ b/packages/kit/inbox-processor.ts @@ -55,14 +55,14 @@ export class InboxProcessor { * @param requestIp Request IP address. Grabs it from the Hono context if not provided. */ public constructor( - private request: Request, - private body: JSONObject, - private sender: { + private readonly request: Request, + private readonly body: JSONObject, + private readonly sender: { instance: Instance; key: CryptoKey; } | null, - private authorizationHeader?: string, - private requestIp: SocketAddress | null = null, + private readonly authorizationHeader?: string, + private readonly requestIp: SocketAddress | null = null, ) {} /** @@ -208,7 +208,7 @@ export class InboxProcessor { throw new ApiError(400, "Unknown entity type"); }); } catch (e) { - return this.handleError(e as Error); + return InboxProcessor.handleError(e as Error); } } @@ -589,7 +589,7 @@ export class InboxProcessor { * @returns {void} * @throws {ApiError} - The error response. */ - private handleError(e: Error): void { + private static handleError(e: Error): void { if (isValidationError(e)) { throw new ApiError(400, "Failed to process request", e.message); } diff --git a/packages/kit/plugin.ts b/packages/kit/plugin.ts index 22e7e780..43eee5be 100644 --- a/packages/kit/plugin.ts +++ b/packages/kit/plugin.ts @@ -12,14 +12,15 @@ export type HonoPluginEnv = HonoEnv & { }; export class Plugin { - private handlers: Partial = {}; + private readonly handlers: Partial = {}; + // biome-ignore lint/nursery/useReadonlyClassProperties: biome is wrong lol private store: z.infer | null = null; - private routes: { + private readonly routes: { path: string; fn: (app: Hono>) => void; }[] = []; - public constructor(private configSchema: ConfigSchema) {} + public constructor(private readonly configSchema: ConfigSchema) {} public get middleware(): MiddlewareHandler> { // Middleware that adds the plugin's configuration to the request object diff --git a/packages/kit/search-manager.ts b/packages/kit/search-manager.ts index 1f0ee0d4..d6567ea5 100644 --- a/packages/kit/search-manager.ts +++ b/packages/kit/search-manager.ts @@ -26,8 +26,9 @@ export enum SonicIndexType { * Class for managing Sonic search operations */ export class SonicSearchManager { - private searchChannel: SonicChannelSearch; - private ingestChannel: SonicChannelIngest; + private readonly searchChannel: SonicChannelSearch; + private readonly ingestChannel: SonicChannelIngest; + // biome-ignore lint/nursery/useReadonlyClassProperties: biome is wrong lol private connected = false; /** diff --git a/packages/kit/timelines/streaming.ts b/packages/kit/timelines/streaming.ts index c70f3885..4f184f37 100644 --- a/packages/kit/timelines/streaming.ts +++ b/packages/kit/timelines/streaming.ts @@ -74,7 +74,10 @@ export class StreamingTimeline { return `timeline:${this.timeline}`; } - private messageHandler = (channel: string, message: string): void => { + private readonly messageHandler = ( + channel: string, + message: string, + ): void => { if (channel === this.channelName) { try { const parsed = JSON.parse(message); diff --git a/packages/logging/index.ts b/packages/logging/index.ts index 56079dec..0ed43128 100644 --- a/packages/logging/index.ts +++ b/packages/logging/index.ts @@ -44,35 +44,31 @@ const getSinks = (): Record<"file" | "console" | "sentry", Sink> => { } if (config.logging.sentry) { - sinks.sentry = getSentrySink( - Sentry.init({ - dsn: config.logging.sentry.dsn.origin, - debug: config.logging.sentry.debug, - sampleRate: config.logging.sentry.sample_rate, - maxBreadcrumbs: config.logging.sentry.max_breadcrumbs, - tracesSampleRate: config.logging.sentry.traces_sample_rate, - environment: config.logging.sentry.environment, - tracePropagationTargets: - config.logging.sentry.trace_propagation_targets, - release: env.GIT_COMMIT - ? `${pkg.version}-${env.GIT_COMMIT}` - : pkg.version, - integrations: [Sentry.extraErrorDataIntegration()], - }), - ); - sinks.sentry = withFilter( - sinks.sentry, + getSentrySink( + Sentry.init({ + dsn: config.logging.sentry.dsn.origin, + debug: config.logging.sentry.debug, + sampleRate: config.logging.sentry.sample_rate, + maxBreadcrumbs: config.logging.sentry.max_breadcrumbs, + tracesSampleRate: config.logging.sentry.traces_sample_rate, + environment: config.logging.sentry.environment, + tracePropagationTargets: + config.logging.sentry.trace_propagation_targets, + release: env.GIT_COMMIT + ? `${pkg.version}-${env.GIT_COMMIT}` + : pkg.version, + integrations: [Sentry.extraErrorDataIntegration()], + }), + ), getLevelFilter(config.logging.sentry.log_level), ); } - sinks.console = getConsoleSink({ - formatter: consoleFormatter, - }); - sinks.console = withFilter( - sinks.console, + getConsoleSink({ + formatter: consoleFormatter, + }), getLevelFilter(config.logging.log_level), ); diff --git a/packages/sdk/inbox-processor.ts b/packages/sdk/inbox-processor.ts index 40bc24b9..1fee5da1 100644 --- a/packages/sdk/inbox-processor.ts +++ b/packages/sdk/inbox-processor.ts @@ -17,9 +17,9 @@ type MaybePromise = T | Promise; * .sort(); */ export class EntitySorter { - private handlers: EntitySorterHandlers = new Map(); + private readonly handlers: EntitySorterHandlers = new Map(); - public constructor(private jsonData: JSONObject) {} + public constructor(private readonly jsonData: JSONObject) {} public on( entity: T,