From 278db6f48ec06000aa4bd6222ca0f5cffa805240 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Pr=C3=A9vost?= <998369+prevostc@users.noreply.github.com> Date: Fri, 21 Jun 2024 16:20:26 +0200 Subject: [PATCH] Fix biome config --- biome.json | 83 ++++++++++++++++++++++++--------------- jest.config.js | 2 +- package.json | 2 +- src/index.ts | 24 +++++------ src/routes/v1/index.ts | 2 +- src/routes/v1/investor.ts | 6 +-- src/routes/v1/status.ts | 8 ++-- src/routes/v1/vault.ts | 22 +++++------ src/routes/v1/vaults.ts | 20 +++++----- 9 files changed, 94 insertions(+), 75 deletions(-) diff --git a/biome.json b/biome.json index 62e8cb2..2166dc5 100644 --- a/biome.json +++ b/biome.json @@ -1,34 +1,53 @@ { - "$schema": "https://biomejs.dev/schemas/1.8.2/schema.json", - "formatter": { - "enabled": true, - "formatWithErrors": false, - "indentStyle": "space", - "indentWidth": 2, - "lineEnding": "lf", - "lineWidth": 100, - "attributePosition": "auto", - "ignore": [ - "./.husky", - "./build", - "./node_modules", - "src/queries/codegen/sdk.ts", - "src/queries/codegen/schema.graphql" - ] - }, - "organizeImports": { "enabled": true }, - "linter": { "enabled": true, "rules": { "recommended": true } }, - "javascript": { - "formatter": { - "jsxQuoteStyle": "double", - "quoteProperties": "asNeeded", - "trailingCommas": "es5", - "semicolons": "always", - "arrowParentheses": "asNeeded", - "bracketSpacing": true, - "bracketSameLine": false, - "quoteStyle": "single", - "attributePosition": "auto" - } - } + "$schema": "https://biomejs.dev/schemas/1.8.2/schema.json", + "formatter": { + "enabled": true, + "formatWithErrors": false, + "indentStyle": "space", + "indentWidth": 2, + "lineEnding": "lf", + "lineWidth": 100, + "attributePosition": "auto", + "ignore": [ + "./.husky/**", + "./build/**", + "./node_modules/**", + "src/queries/codegen/sdk.ts", + "src/queries/codegen/schema.graphql" + ] + }, + "organizeImports": { + "enabled": true, + "ignore": [ + "./.husky/**", + "./build/**", + "./node_modules/**", + "src/queries/codegen/sdk.ts", + "src/queries/codegen/schema.graphql" + ] + }, + "linter": { + "enabled": true, + "ignore": [ + "./.husky/**", + "./build/**", + "./node_modules/**", + "src/queries/codegen/sdk.ts", + "src/queries/codegen/schema.graphql" + ], + "rules": { "recommended": true } + }, + "javascript": { + "formatter": { + "jsxQuoteStyle": "double", + "quoteProperties": "asNeeded", + "trailingCommas": "es5", + "semicolons": "always", + "arrowParentheses": "asNeeded", + "bracketSpacing": true, + "bracketSameLine": false, + "quoteStyle": "single", + "attributePosition": "auto" + } + } } diff --git a/jest.config.js b/jest.config.js index b413e10..3745fc2 100644 --- a/jest.config.js +++ b/jest.config.js @@ -2,4 +2,4 @@ module.exports = { preset: 'ts-jest', testEnvironment: 'node', -}; \ No newline at end of file +}; diff --git a/package.json b/package.json index ef71031..87e4cfd 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "test": "npm run test:ts && npm run test:unit && npm run test:lint", "test:unit": "jest", "test:ts": "tsc --noEmit", - "test:lint": "npm run prettier:check", + "test:lint": "biome ci", "package:check": "ncu", "package:fix": "ncu -u && npm install", "postinstall": "npm --silent run codegen", diff --git a/src/index.ts b/src/index.ts index b27d6ae..a1c9a4a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,15 +1,15 @@ -import Fastify from 'fastify'; +import FastifyCors from '@fastify/cors'; +import FastifyEtag from '@fastify/etag'; import FastifyHelmet from '@fastify/helmet'; import FastifyRateLimit from '@fastify/rate-limit'; import FastifyUnderPressure from '@fastify/under-pressure'; -import FastifyEtag from '@fastify/etag'; -import FastifyCors from '@fastify/cors'; -import { defaultLogger } from './utils/log'; -import routes from './routes/index'; -import { API_CORS_ORIGIN, API_ENV, API_PORT, API_RATE_LIMIT } from './config/env'; -import { FriendlyError } from './utils/error'; import Decimal from 'decimal.js'; +import Fastify from 'fastify'; +import { API_CORS_ORIGIN, API_ENV, API_PORT, API_RATE_LIMIT } from './config/env'; +import routes from './routes/index'; import { allowedToBypassRateLimit } from './utils/auth'; +import { FriendlyError } from './utils/error'; +import { defaultLogger } from './utils/log'; Decimal.set({ // make sure we have enough precision @@ -35,7 +35,7 @@ server.register(async (instance, _opts, done) => { continueExceeding: true, skipOnError: false, enableDraftSpec: true, - allowList: request => allowedToBypassRateLimit(request.headers['authorization']), + allowList: request => allowedToBypassRateLimit(request.headers.authorization), errorResponseBuilder: (_request, context) => ({ statusCode: 429, name: 'RateLimitExceededError', @@ -48,11 +48,11 @@ server.register(async (instance, _opts, done) => { methods: ['GET'], origin: API_ENV === 'production' ? API_CORS_ORIGIN : true, }) - .setReplySerializer(function (payload) { - return JSON.stringify(payload, (_key, value) => + .setReplySerializer(payload => + JSON.stringify(payload, (_key, value) => typeof value === 'bigint' ? value.toString() : value - ); - }) + ) + ) .addHook('onSend', async (_req, reply) => { if (reply.raw.statusCode !== 200) { reply.header('cache-control', 'no-cache, no-store, must-revalidate'); diff --git a/src/routes/v1/index.ts b/src/routes/v1/index.ts index 771dfc3..35c1d01 100644 --- a/src/routes/v1/index.ts +++ b/src/routes/v1/index.ts @@ -1,6 +1,6 @@ import type { FastifyInstance, FastifyPluginOptions } from 'fastify'; -import status from './status'; import investor from './investor'; +import status from './status'; import vault from './vault'; import vaults from './vaults'; diff --git a/src/routes/v1/investor.ts b/src/routes/v1/investor.ts index 0bd51ca..6e783b7 100644 --- a/src/routes/v1/investor.ts +++ b/src/routes/v1/investor.ts @@ -1,11 +1,11 @@ -import { FastifyInstance, FastifyPluginOptions, FastifySchema } from 'fastify'; +import type { FastifyInstance, FastifyPluginOptions, FastifySchema } from 'fastify'; import S from 'fluent-json-schema'; import { addressSchema } from '../../schema/address'; import { getAsyncCache } from '../../utils/async-lock'; +import type { Address } from '../../utils/scalar-types'; import { getClmTimeline } from '../../utils/timeline'; -import { TimelineClmInteraction } from '../../utils/timeline-types'; -import { Address } from '../../utils/scalar-types'; +import type { TimelineClmInteraction } from '../../utils/timeline-types'; export default async function ( instance: FastifyInstance, diff --git a/src/routes/v1/status.ts b/src/routes/v1/status.ts index 71cc9b2..3eb58dd 100644 --- a/src/routes/v1/status.ts +++ b/src/routes/v1/status.ts @@ -1,8 +1,8 @@ -import { FastifyInstance, FastifyPluginOptions, FastifySchema } from 'fastify'; +import type { FastifyInstance, FastifyPluginOptions, FastifySchema } from 'fastify'; import S from 'fluent-json-schema'; +import type { ChainId } from '../../config/chains'; import { getAsyncCache } from '../../utils/async-lock'; -import { getAllSdks, SdkContext } from '../../utils/sdk'; -import { ChainId } from '../../config/chains'; +import { type SdkContext, getAllSdks } from '../../utils/sdk'; export default async function ( instance: FastifyInstance, @@ -23,7 +23,7 @@ export default async function ( }; instance.get('/', { schema }, async (_, reply) => { - const res = await asyncCache.wrap(`status`, 60 * 1000, async () => { + const res = await asyncCache.wrap('status', 60 * 1000, async () => { return await getStatus(); }); reply.send(res); diff --git a/src/routes/v1/vault.ts b/src/routes/v1/vault.ts index 5ed0456..bdcd8dd 100644 --- a/src/routes/v1/vault.ts +++ b/src/routes/v1/vault.ts @@ -1,15 +1,15 @@ -import { FastifyInstance, FastifyPluginOptions, FastifySchema } from 'fastify'; +import type { FastifyInstance, FastifyPluginOptions, FastifySchema } from 'fastify'; import S from 'fluent-json-schema'; -import { ChainId } from '../../config/chains'; +import type { ChainId } from '../../config/chains'; +import type { HarvestDataFragment, Token } from '../../queries/codegen/sdk'; import { addressSchema } from '../../schema/address'; -import { getSdksForChain, paginateSdkCalls } from '../../utils/sdk'; -import { getPeriodSeconds, Period, periodSchema } from '../../schema/period'; -import { chainSchema } from '../../schema/chain'; import { bigintSchema } from '../../schema/bigint'; -import { interpretAsDecimal } from '../../utils/decimal'; +import { chainSchema } from '../../schema/chain'; +import { type Period, getPeriodSeconds, periodSchema } from '../../schema/period'; import { getAsyncCache } from '../../utils/async-lock'; -import { HarvestDataFragment, Token } from '../../queries/codegen/sdk'; -import { Address } from '../../utils/scalar-types'; +import { interpretAsDecimal } from '../../utils/decimal'; +import type { Address } from '../../utils/scalar-types'; +import { getSdksForChain, paginateSdkCalls } from '../../utils/sdk'; export default async function ( instance: FastifyInstance, @@ -345,7 +345,7 @@ const getVaultHistoricPrices = async ( const token1 = vault.underlyingToken1; return vault.snapshots.map(snapshot => ({ - t: parseInt(snapshot.roundedTimestamp), + t: Number.parseInt(snapshot.roundedTimestamp), min: interpretAsDecimal(snapshot.priceRangeMin1, token1.decimals), v: interpretAsDecimal(snapshot.priceOfToken0InToken1, token1.decimals), max: interpretAsDecimal(snapshot.priceRangeMax1, token1.decimals), @@ -372,8 +372,8 @@ const getVaultHistoricPricesRange = async ( } return { - min: parseInt(vault.minSnapshot?.[0]?.roundedTimestamp || '0'), - max: parseInt(vault.maxSnapshot?.[0]?.roundedTimestamp || '0'), + min: Number.parseInt(vault.minSnapshot?.[0]?.roundedTimestamp || '0'), + max: Number.parseInt(vault.maxSnapshot?.[0]?.roundedTimestamp || '0'), }; }; diff --git a/src/routes/v1/vaults.ts b/src/routes/v1/vaults.ts index 6b2288f..baaf834 100644 --- a/src/routes/v1/vaults.ts +++ b/src/routes/v1/vaults.ts @@ -1,18 +1,18 @@ -import { FastifyInstance, FastifyPluginOptions, FastifySchema } from 'fastify'; +import type { FastifyInstance, FastifyPluginOptions, FastifySchema } from 'fastify'; import S from 'fluent-json-schema'; -import { ChainId } from '../../config/chains'; -import { getSdksForChain, paginateSdkCalls } from '../../utils/sdk'; +import { max, sortedUniq } from 'lodash'; +import type { ChainId } from '../../config/chains'; +import type { VaultsQuery } from '../../queries/codegen/sdk'; +import { addressSchema } from '../../schema/address'; import { chainSchema } from '../../schema/chain'; -import { getPeriodSeconds, Period, periodSchema } from '../../schema/period'; +import { type Period, getPeriodSeconds, periodSchema } from '../../schema/period'; import { calculateLastApr, prepareAprState } from '../../utils/apr'; -import { interpretAsDecimal } from '../../utils/decimal'; -import { PreparedVaultHarvest, prepareVaultHarvests } from './vault'; -import { addressSchema } from '../../schema/address'; import { getAsyncCache } from '../../utils/async-lock'; -import { VaultsQuery } from '../../queries/codegen/sdk'; -import { max, sortedUniq } from 'lodash'; -import { Address } from '../../utils/scalar-types'; import { fromUnixTime, getUnixTime } from '../../utils/date'; +import { interpretAsDecimal } from '../../utils/decimal'; +import type { Address } from '../../utils/scalar-types'; +import { getSdksForChain, paginateSdkCalls } from '../../utils/sdk'; +import { type PreparedVaultHarvest, prepareVaultHarvests } from './vault'; export default async function ( instance: FastifyInstance,