diff --git a/.eslintrc.js b/.eslintrc.js index e8a1c2fa4..fcdb3c280 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -5,5 +5,7 @@ module.exports = { "plugin:@beequeue/node", "plugin:@beequeue/typescript", ], - rules: {}, + rules: { + "prettier/prettier": "off", + }, } diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index c70bef9b5..c4485a32f 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -34,6 +34,8 @@ jobs: - run: pnpm lint --format compact + - uses: dprint/check@v2.2 + typecheck: runs-on: ubuntu-latest diff --git a/.prettierrc b/.prettierrc deleted file mode 100644 index 3ee6ca58f..000000000 --- a/.prettierrc +++ /dev/null @@ -1,5 +0,0 @@ -{ - "printWidth": 90, - "semi": false, - "trailingComma": "all" -} diff --git a/Dockerfile b/Dockerfile index c28508ae9..3350c9e70 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM node:20-alpine as runtime_deps +FROM node:20-alpine AS runtime_deps RUN corepack enable @@ -13,8 +13,7 @@ ENV NODE_ENV=production # Install dependencies RUN pnpm install --frozen-lockfile - -FROM node:20-alpine as docs +FROM node:20-alpine AS docs RUN corepack enable @@ -31,7 +30,6 @@ RUN pnpm install --frozen-lockfile RUN pnpm --silent run docs - FROM node:20-alpine RUN corepack enable diff --git a/dprint.json b/dprint.json new file mode 100644 index 000000000..3daebfe1b --- /dev/null +++ b/dprint.json @@ -0,0 +1,20 @@ +{ + "$schema": "https://dprint.dev/schemas/v0.json", + "newLineKind": "lf", + "useTabs": false, + "indentWidth": 2, + "typescript": { + "semiColons": "asi", + "quoteProps": "asNeeded", + "arrowFunction.useParentheses": "force" + }, + "excludes": [ + "**/node_modules", + "**/pnpm-lock*" + ], + "plugins": [ + "https://plugins.dprint.dev/typescript-0.87.1.wasm", + "https://plugins.dprint.dev/json-0.17.4.wasm", + "https://plugins.dprint.dev/dockerfile-0.3.0.wasm" + ] +} diff --git a/jest.config.js b/jest.config.js deleted file mode 100644 index 6df073f00..000000000 --- a/jest.config.js +++ /dev/null @@ -1,22 +0,0 @@ -const { pathsToModuleNameMapper } = require("ts-jest/utils") -const { compilerOptions } = require("./tsconfig") - -module.exports = { - roots: ["/src"], - preset: "ts-jest", - moduleFileExtensions: ["js", "ts"], - moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, { - prefix: "/", - }), - coveragePathIgnorePatterns: ["sentry.ts", "utils.ts"], - collectCoverage: true, - coverageReporters: ["text", "text-summary"], - coverageThreshold: { - global: { - statements: 90, - branches: 75, - functions: 80, - lines: 90, - }, - }, -} diff --git a/package.json b/package.json index 072d79fce..ab8c7ae9e 100644 --- a/package.json +++ b/package.json @@ -5,13 +5,16 @@ "private": true, "license": "AGPL-3.0-only", "homepage": "https://arm.haglund.dev/docs", - "packageManager": "pnpm@8.7.4", + "packageManager": "pnpm@8.7.5", "engines": { "node": ">=20" }, "lint-staged": { "*.{js,ts,json}": [ - "prettier --write" + "dprint fmt" + ], + "Dockerfile": [ + "dprint fmt" ] }, "scripts": { @@ -62,7 +65,6 @@ "husky": "8.0.3", "lint-staged": "14.0.1", "onchange": "7.1.0", - "prettier": "3.0.3", "redoc-cli": "0.13.21", "tsconfig-paths": "4.2.0", "vitest": "0.34.4" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8ba619b73..2dbb5d8b5 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -111,9 +111,6 @@ devDependencies: onchange: specifier: 7.1.0 version: 7.1.0 - prettier: - specifier: 3.0.3 - version: 3.0.3 redoc-cli: specifier: 0.13.21 version: 0.13.21(@babel/core@7.22.17)(core-js@3.32.2)(react-is@18.2.0)(webpack@5.88.2) diff --git a/src/lib/sentry.ts b/src/lib/sentry.ts index 508dd5a5e..992f02c1a 100644 --- a/src/lib/sentry.ts +++ b/src/lib/sentry.ts @@ -15,9 +15,7 @@ Sentry.init({ export const sendErrorToSentry = (err: Error, request: FastifyRequest) => { Sentry.withScope((scope) => { - scope.addEventProcessor((event) => - Sentry.addRequestDataToEvent(event, request as never), - ) + scope.addEventProcessor((event) => Sentry.addRequestDataToEvent(event, request as never)) Sentry.captureException(err) }) diff --git a/src/manual-rules.ts b/src/manual-rules.ts index d3c6d4bf7..4bd407f54 100644 --- a/src/manual-rules.ts +++ b/src/manual-rules.ts @@ -30,9 +30,7 @@ export const updateBasedOnManualRules = async () => { .delete() .where(fromWhere) .transacting(trx) - .then(() => - knex("relations").update(fromWhere).where(toWhere).transacting(trx), - ), + .then(() => knex("relations").update(fromWhere).where(toWhere).transacting(trx)) ) .catch(console.error) }) diff --git a/src/routes/v1/ids/handler.test.ts b/src/routes/v1/ids/handler.test.ts index aa72811d8..e0cafb0a0 100644 --- a/src/routes/v1/ids/handler.test.ts +++ b/src/routes/v1/ids/handler.test.ts @@ -3,7 +3,7 @@ import { IncomingMessage, ServerResponse } from "http" import { FastifyInstance } from "fastify" import { RawServerDefault } from "fastify/types/utils" import { Logger } from "pino" -import { afterAll, afterEach, beforeAll, describe, test, expect } from "vitest" +import { afterAll, afterEach, beforeAll, describe, expect, test } from "vitest" import { buildApp } from "@/app" import { knex, Relation, Source } from "@/db" diff --git a/src/routes/v1/ids/handler.ts b/src/routes/v1/ids/handler.ts index e69e82696..a6074f2e0 100644 --- a/src/routes/v1/ids/handler.ts +++ b/src/routes/v1/ids/handler.ts @@ -3,11 +3,7 @@ import { FastifyPluginAsync, FastifyReply, FastifyRequest } from "fastify" import { Relation } from "@/db" import { bodyHandler, bodyInputSchema, BodyQuery } from "./schemas/json-body" -import { - handleQueryParams, - queryInputSchema, - QueryParamQuery, -} from "./schemas/query-params" +import { handleQueryParams, queryInputSchema, QueryParamQuery } from "./schemas/query-params" import { responseBodySchema } from "./schemas/response" type BodyInput = { Body: BodyQuery } diff --git a/src/routes/v1/ids/schemas/json-body.test.ts b/src/routes/v1/ids/schemas/json-body.test.ts index 1640a5114..476ffc5d7 100644 --- a/src/routes/v1/ids/schemas/json-body.test.ts +++ b/src/routes/v1/ids/schemas/json-body.test.ts @@ -30,8 +30,7 @@ const badCases = [ [{ anidb: 1337, test: 123 }, false], ] satisfies Cases -const mapToSingularArrayInput = (cases: Cases): Cases => - cases.map(([input, expected]) => [[input], expected]) +const mapToSingularArrayInput = (cases: Cases): Cases => cases.map(([input, expected]) => [[input], expected]) describe("schema", () => { const inputs = [ diff --git a/src/routes/v1/ids/schemas/json-body.ts b/src/routes/v1/ids/schemas/json-body.ts index 6613c37ae..05e691a5d 100644 --- a/src/routes/v1/ids/schemas/json-body.ts +++ b/src/routes/v1/ids/schemas/json-body.ts @@ -46,7 +46,7 @@ export const bodyHandler = async ( // Get relations relations = await knex .select(["anidb", "anilist", "myanimelist", "kitsu"]) - .where(function () { + .where(function() { // eslint-disable-next-line @typescript-eslint/no-floating-promises for (const item of input) this.orWhere(item) }) diff --git a/src/routes/v2/ids/handler.ts b/src/routes/v2/ids/handler.ts index 054b6b085..f05f64791 100644 --- a/src/routes/v2/ids/handler.ts +++ b/src/routes/v2/ids/handler.ts @@ -35,7 +35,7 @@ const bodyHandler = async ( // Get relations relations = await knex .select(buildSelectFromInclude(request)) - .where(function () { + .where(function() { // eslint-disable-next-line @typescript-eslint/no-floating-promises for (const item of input) this.orWhere(item) }) diff --git a/src/routes/v2/ids/schemas/json-body.test.ts b/src/routes/v2/ids/schemas/json-body.test.ts index 217bbfa5e..c675a442c 100644 --- a/src/routes/v2/ids/schemas/json-body.test.ts +++ b/src/routes/v2/ids/schemas/json-body.test.ts @@ -49,8 +49,7 @@ const badCases = [ [{ thetvdb: 1337 }, false], ] satisfies Cases -const mapToSingularArrayInput = (cases: Cases): Cases => - cases.map(([input, expected]) => [[input], expected]) +const mapToSingularArrayInput = (cases: Cases): Cases => cases.map(([input, expected]) => [[input], expected]) describe("schema", () => { const inputs = [ diff --git a/src/routes/v2/ids/schemas/json-body.ts b/src/routes/v2/ids/schemas/json-body.ts index e30ec6c7c..210c06cfa 100644 --- a/src/routes/v2/ids/schemas/json-body.ts +++ b/src/routes/v2/ids/schemas/json-body.ts @@ -1,12 +1,7 @@ import { JSONSchema7 } from "json-schema" import { Relation } from "@/db" -import { - imdbIdSchema, - makeNullable, - numberIdSchema, - stringIdSchema, -} from "@/shared-schemas" +import { imdbIdSchema, makeNullable, numberIdSchema, stringIdSchema } from "@/shared-schemas" // Does not include `thetvdb` due to the one-to-many issue type BodyItem = Omit diff --git a/src/routes/v2/ids/schemas/query-params.ts b/src/routes/v2/ids/schemas/query-params.ts index 24353acf1..a16d5ce97 100644 --- a/src/routes/v2/ids/schemas/query-params.ts +++ b/src/routes/v2/ids/schemas/query-params.ts @@ -1,11 +1,7 @@ import { JSONSchema7 } from "json-schema" import { Source } from "@/db" -import { - imdbSourceSchema, - numberIdSourceSchema, - stringIdSourceSchema, -} from "@/routes/v2/ids/schemas/common" +import { imdbSourceSchema, numberIdSourceSchema, stringIdSourceSchema } from "@/routes/v2/ids/schemas/common" import { imdbIdSchema, numberIdSchema, stringIdSchema } from "@/shared-schemas" export type QueryParamQuery = { diff --git a/src/routes/v2/ids/schemas/response.ts b/src/routes/v2/ids/schemas/response.ts index e72086a5e..7d17bd0f1 100644 --- a/src/routes/v2/ids/schemas/response.ts +++ b/src/routes/v2/ids/schemas/response.ts @@ -1,11 +1,6 @@ import { JSONSchema7 } from "json-schema" -import { - makeNullable, - numberIdSchema, - stringIdSchema, - imdbIdSchema, -} from "@/shared-schemas" +import { imdbIdSchema, makeNullable, numberIdSchema, stringIdSchema } from "@/shared-schemas" const nullableNumberIdSchema = makeNullable(numberIdSchema) const nullableLongStringIdSchema = makeNullable({ diff --git a/src/update.test.ts b/src/update.test.ts index 4d9c19708..a07350d71 100644 --- a/src/update.test.ts +++ b/src/update.test.ts @@ -3,12 +3,7 @@ import { groupBy } from "remeda" import { afterAll, afterEach, expect, it, vi } from "vitest" import { knex, Relation } from "@/db" -import { - AnimeListsSchema, - formatEntry, - removeDuplicates, - updateRelations, -} from "@/update" +import { AnimeListsSchema, formatEntry, removeDuplicates, updateRelations } from "@/update" // eslint-disable-next-line @typescript-eslint/no-explicit-any declare const fetch: (url: string) => Promise<{ json: () => Promise }> @@ -27,13 +22,15 @@ afterAll(async () => { const mockedFetch = vi.mocked($fetch) it("handles bad values", async () => { - mockedFetch.mockResolvedValue([ - { anidb_id: 1337, themoviedb_id: "unknown" }, - { anidb_id: 1338, thetvdb_id: "unknown" as never }, - { anidb_id: 1339, imdb_id: "tt1337,tt1338,tt1339" }, - { anidb_id: 1340, themoviedb_id: "unknown" }, - { anidb_id: 1341, themoviedb_id: 1341 }, - ] satisfies AnimeListsSchema) + mockedFetch.mockResolvedValue( + [ + { anidb_id: 1337, themoviedb_id: "unknown" }, + { anidb_id: 1338, thetvdb_id: "unknown" as never }, + { anidb_id: 1339, imdb_id: "tt1337,tt1338,tt1339" }, + { anidb_id: 1340, themoviedb_id: "unknown" }, + { anidb_id: 1341, themoviedb_id: 1341 }, + ] satisfies AnimeListsSchema, + ) await updateRelations() diff --git a/src/update.ts b/src/update.ts index e0bc2e1ba..ff488b252 100644 --- a/src/update.ts +++ b/src/update.ts @@ -7,8 +7,7 @@ import { logger } from "@/lib/logger" import { knex, Relation, Source } from "./db" import { updateBasedOnManualRules } from "./manual-rules" -const isFetchError = (response: T | FetchError): response is FetchError => - (response as FetchError).stack != null +const isFetchError = (response: T | FetchError): response is FetchError => (response as FetchError).stack != null export type AnimeListsSchema = Array<{ anidb_id?: number @@ -52,9 +51,9 @@ const handleBadValues = ( value: T | "unknown", ): T | undefined => { if ( - typeof value === "string" && + typeof value === "string" // eslint-disable-next-line @typescript-eslint/no-explicit-any - (badValues.includes(value as any) || value.includes(",")) + && (badValues.includes(value as any) || value.includes(",")) ) { return undefined } @@ -126,7 +125,7 @@ export const updateRelations = async () => { .transacting(trx) .then(async () => { await knex.batchInsert("relations", goodEntries, 100).transacting(trx) - }), + }) ) logger.info("Updated database.")