fix: 🚨 Fix Deepsource warnings

This commit is contained in:
Jesse Wierzbinski 2025-07-07 05:08:34 +02:00
parent 2fffbcbede
commit 870b6dbe85
No known key found for this signature in database
13 changed files with 58 additions and 59 deletions

View file

@ -125,6 +125,7 @@
"noGlobalDirnameFilename": "error",
"noProcessGlobal": "warn",
"noTsIgnore": "warn",
"useReadonlyClassProperties": "error",
"useConsistentObjectDefinition": {
"level": "warn",
"options": {

View file

@ -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",
],
});

View file

@ -53,7 +53,7 @@ export class PluginLoader {
* @returns {Promise<unknown>} - 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<unknown> {
@ -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<Plugin<ZodTypeAny>>} - 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<Plugin<ZodTypeAny>> {
@ -197,7 +197,7 @@ export class PluginLoader {
return null;
}
const pluginInstance = await this.loadPlugin(
const pluginInstance = await PluginLoader.loadPlugin(
dir,
`${plugin}/index`,
);

View file

@ -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<typeof fetch>) => fetch(...args);
private async request<ReturnType>(

View file

@ -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",
],
});

View file

@ -180,19 +180,19 @@ export class Instance extends BaseInterface<typeof Instances> {
// 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<typeof Instances> {
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;

View file

@ -12,7 +12,7 @@ enum TimelineType {
}
export class Timeline<Type extends Note | User | Notification> {
public constructor(private type: TimelineType) {}
public constructor(private readonly type: TimelineType) {}
public static getNoteTimeline(
sql: SQL<unknown> | undefined,

View file

@ -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);
}

View file

@ -12,14 +12,15 @@ export type HonoPluginEnv<ConfigType extends z.ZodTypeAny> = HonoEnv & {
};
export class Plugin<ConfigSchema extends z.ZodTypeAny> {
private handlers: Partial<ServerHooks> = {};
private readonly handlers: Partial<ServerHooks> = {};
// biome-ignore lint/nursery/useReadonlyClassProperties: biome is wrong lol
private store: z.infer<ConfigSchema> | null = null;
private routes: {
private readonly routes: {
path: string;
fn: (app: Hono<HonoPluginEnv<ConfigSchema>>) => void;
}[] = [];
public constructor(private configSchema: ConfigSchema) {}
public constructor(private readonly configSchema: ConfigSchema) {}
public get middleware(): MiddlewareHandler<HonoPluginEnv<ConfigSchema>> {
// Middleware that adds the plugin's configuration to the request object

View file

@ -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;
/**

View file

@ -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);

View file

@ -44,7 +44,8 @@ const getSinks = (): Record<"file" | "console" | "sentry", Sink> => {
}
if (config.logging.sentry) {
sinks.sentry = getSentrySink(
sinks.sentry = withFilter(
getSentrySink(
Sentry.init({
dsn: config.logging.sentry.dsn.origin,
debug: config.logging.sentry.debug,
@ -59,20 +60,15 @@ const getSinks = (): Record<"file" | "console" | "sentry", Sink> => {
: pkg.version,
integrations: [Sentry.extraErrorDataIntegration()],
}),
);
sinks.sentry = withFilter(
sinks.sentry,
),
getLevelFilter(config.logging.sentry.log_level),
);
}
sinks.console = getConsoleSink({
formatter: consoleFormatter,
});
sinks.console = withFilter(
sinks.console,
getConsoleSink({
formatter: consoleFormatter,
}),
getLevelFilter(config.logging.log_level),
);

View file

@ -17,9 +17,9 @@ type MaybePromise<T> = T | Promise<T>;
* .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<T extends typeof Entity>(
entity: T,