Skip to content

Commit

Permalink
Try out dprint instead of Prettier (#737)
Browse files Browse the repository at this point in the history
  • Loading branch information
beeequeue authored Sep 11, 2023
1 parent 0049f77 commit 6879296
Show file tree
Hide file tree
Showing 21 changed files with 57 additions and 91 deletions.
4 changes: 3 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ module.exports = {
"plugin:@beequeue/node",
"plugin:@beequeue/typescript",
],
rules: {},
rules: {
"prettier/prettier": "off",
},
}
2 changes: 2 additions & 0 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ jobs:

- run: pnpm lint --format compact

- uses: dprint/[email protected]

typecheck:
runs-on: ubuntu-latest

Expand Down
5 changes: 0 additions & 5 deletions .prettierrc

This file was deleted.

6 changes: 2 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:20-alpine as runtime_deps
FROM node:20-alpine AS runtime_deps

RUN corepack enable

Expand All @@ -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

Expand All @@ -31,7 +30,6 @@ RUN pnpm install --frozen-lockfile

RUN pnpm --silent run docs


FROM node:20-alpine

RUN corepack enable
Expand Down
20 changes: 20 additions & 0 deletions dprint.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
22 changes: 0 additions & 22 deletions jest.config.js

This file was deleted.

8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
"private": true,
"license": "AGPL-3.0-only",
"homepage": "https://arm.haglund.dev/docs",
"packageManager": "[email protected].4",
"packageManager": "[email protected].5",
"engines": {
"node": ">=20"
},
"lint-staged": {
"*.{js,ts,json}": [
"prettier --write"
"dprint fmt"
],
"Dockerfile": [
"dprint fmt"
]
},
"scripts": {
Expand Down Expand Up @@ -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"
Expand Down
3 changes: 0 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions src/lib/sentry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down
4 changes: 1 addition & 3 deletions src/manual-rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down
2 changes: 1 addition & 1 deletion src/routes/v1/ids/handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 1 addition & 5 deletions src/routes/v1/ids/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
3 changes: 1 addition & 2 deletions src/routes/v1/ids/schemas/json-body.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
2 changes: 1 addition & 1 deletion src/routes/v1/ids/schemas/json-body.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down
2 changes: 1 addition & 1 deletion src/routes/v2/ids/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down
3 changes: 1 addition & 2 deletions src/routes/v2/ids/schemas/json-body.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
7 changes: 1 addition & 6 deletions src/routes/v2/ids/schemas/json-body.ts
Original file line number Diff line number Diff line change
@@ -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<Relation, "thetvdb">
Expand Down
6 changes: 1 addition & 5 deletions src/routes/v2/ids/schemas/query-params.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down
7 changes: 1 addition & 6 deletions src/routes/v2/ids/schemas/response.ts
Original file line number Diff line number Diff line change
@@ -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({
Expand Down
23 changes: 10 additions & 13 deletions src/update.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any[]> }>
Expand All @@ -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()

Expand Down
9 changes: 4 additions & 5 deletions src/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import { logger } from "@/lib/logger"
import { knex, Relation, Source } from "./db"
import { updateBasedOnManualRules } from "./manual-rules"

const isFetchError = <T>(response: T | FetchError): response is FetchError =>
(response as FetchError).stack != null
const isFetchError = <T>(response: T | FetchError): response is FetchError => (response as FetchError).stack != null

export type AnimeListsSchema = Array<{
anidb_id?: number
Expand Down Expand Up @@ -52,9 +51,9 @@ const handleBadValues = <T extends string | number | undefined>(
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
}
Expand Down Expand Up @@ -126,7 +125,7 @@ export const updateRelations = async () => {
.transacting(trx)
.then(async () => {
await knex.batchInsert("relations", goodEntries, 100).transacting(trx)
}),
})
)
logger.info("Updated database.")

Expand Down

0 comments on commit 6879296

Please sign in to comment.