Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: move to biome to align with parent project #191

Merged
merged 1 commit into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 0 additions & 56 deletions .eslintrc

This file was deleted.

3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["biomejs.biome"]
}
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"editor.defaultFormatter": "biomejs.biome"
}
87 changes: 87 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
{
"$schema": "https://biomejs.dev/schemas/1.8.3/schema.json",
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"correctness": {
"noUnsafeOptionalChaining": "off",
"useExhaustiveDependencies": "off",
"noUnusedImports": "warn",
"useJsxKeyInIterable": "off"
},
"complexity": {
"noBannedTypes": "off",
"noUselessConstructor": "off",
"useOptionalChain": "warn",
"noStaticOnlyClass": "off",
"noForEach": "off"
},
"style": {
"noNonNullAssertion": "off",
"noInferrableTypes": "off",
"noUnusedTemplateLiteral": "off",
"useSingleVarDeclarator": "off",
"noUselessElse": "off",
"useNodejsImportProtocol": "off"
},
"suspicious": {
"noExplicitAny": "off",
"noExtraNonNullAssertion": "off",
"noRedeclare": "off",
"noPrototypeBuiltins": "off",
"noConfusingVoidType": "off",
"noArrayIndexKey": "off",
"noThenProperty": "off",
"noExportsInTest": "off"
},
"performance": {
"noAccumulatingSpread": "off",
"noDelete": "off"
}
},
"ignore": [
"node_modules",
"jest.config.js",
"dist",
"build",
"CHANGELOG.md",
"package.json",
"tsconfig.json"
]
},
"organizeImports": {
"enabled": true
},
"formatter": {
"indentStyle": "space",
"ignore": [
"node_modules",
"jest.config.js",
"dist",
"build",
"CHANGELOG.md",
"package.json",
"tsconfig.json"
],
"indentWidth": 4
},
"javascript": {
"formatter": {
"semicolons": "always",
"quoteStyle": "single",
"jsxQuoteStyle": "single",
"indentWidth": 4
}
},
"json": {
"formatter": {
"indentWidth": 2
}
},
"vcs": {
"enabled": true,
"defaultBranch": "main",
"clientKind": "git"
}
}
2 changes: 1 addition & 1 deletion example.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const app = createApp({
'demo-app:default.1d0fd3109556631d8e9469c75090f46f2ec269d094543890c9a81c4a',
clientKeys: ['proxy-secret', 'another-proxy-secret', 's1'],
refreshInterval: 1000,
logLevel: 'trace',
//logLevel: 'trace',
enableOAS: true,
expServerSideSdkConfig: {
tokens: ['server'],
Expand Down
61 changes: 20 additions & 41 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
"scripts": {
"build": "tsc --pretty",
"example": "yarn run build && node example",
"lint": "eslint ./src",
"lint": "biome lint --write ./src",
"test": "jest",
"updateSnapshots": "jest -u",
"prepare": "npm run build",
"dev": "ENABLE_OAS=true ts-node-dev src/start.ts",
"fmt": "prettier src --write --loglevel warn",
"fmt:check": "prettier src --check"
"fmt": "biome format ./src --write",
"fmt:check": "biome format ./src",
"biome:ci": "biome ci ./src"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -41,54 +42,32 @@
"@unleash/express-openapi": "^0.3.0",
"compression": "^1.7.4",
"cors": "^2.8.5",
"express": "^4.18.2",
"json-schema-to-ts": "^2.3.0",
"openapi-types": "^11.0.0",
"express": "^4.19.2",
"json-schema-to-ts": "^3.1.0",
"openapi-types": "^12.1.3",
"prom-client": "^15.1.3",
"qs": "^6.9.7",
"qs": "^6.12.3",
"type-is": "^1.6.18",
"unleash-client": "^6.1.1"
},
"devDependencies": {
"@apidevtools/swagger-parser": "10.1.0",
"@babel/core": "^7.24.4",
"@types/compression": "^1.7.2",
"@types/cors": "^2.8.12",
"@types/express": "^4.17.13",
"@babel/core": "^7.25.2",
"@biomejs/biome": "^1.8.3",
"@types/compression": "^1.7.5",
"@types/cors": "^2.8.17",
"@types/express": "^4.17.21",
"@types/jest": "^29.5.12",
"@types/node": "18.7.14",
"@types/supertest": "^2.0.12",
"@types/type-is": "^1.6.3",
"@typescript-eslint/eslint-plugin": "^5.22.0",
"@typescript-eslint/parser": "^5.22.0",
"babel-jest": "^28.0.3",
"eslint": "^8.14.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-airbnb-typescript": "^17.0.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-prettier": "^4.0.0",
"@types/node": "20.14.8",
"@types/supertest": "^6.0.2",
"@types/type-is": "^1.6.6",
"babel-jest": "^29.7.0",
"jest": "^29.7.0",
"prettier": "^2.6.2",
"semver": "^7.3.7",
"supertest": "^6.2.3",
"semver": "^7.6.3",
"supertest": "^7.0.0",
"ts-jest": "^29.2.4",
"ts-node-dev": "^2.0.0",
"typescript": "^4.6.4"
},
"prettier": {
"proseWrap": "never",
"singleQuote": true,
"tabWidth": 4,
"trailingComma": "all",
"overrides": [
{
"files": "*.{json,yaml,yml,md}",
"options": {
"tabWidth": 2
}
}
]
"typescript": "^5.5.4"
},
"resolutions": {
"wrap-ansi": "7.0.0",
Expand Down
13 changes: 7 additions & 6 deletions src/app.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import compression from 'compression';
import express, { Application } from 'express';
import cors from 'cors';
import { IClient } from './client';
import { createProxyConfig, IProxyOption } from './config';
import express, { type Application } from 'express';
import type { IClient } from './client';
import { type IProxyOption, createProxyConfig } from './config';

import UnleashProxy from './unleash-proxy';
import { OpenApiService } from './openapi/openapi-service';
import requireContentType from './content-type-checker';
import { createSingletonClient, createNewClient } from './create-client';
import { createNewClient, createSingletonClient } from './create-client';
import { OpenApiService } from './openapi/openapi-service';
import UnleashProxy from './unleash-proxy';

export function createApp(
options: IProxyOption,
Expand Down Expand Up @@ -48,6 +48,7 @@ export function createApp(
const corsOptions = config.cors;
app.use(cors(corsOptions));

// @ts-expect-error Express struggles with its types here, compression seems to be too old
app.use(compression());

app.use(
Expand Down
15 changes: 10 additions & 5 deletions src/client.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import EventEmitter from 'events';
import { Context, Unleash, UnleashEvents, Variant } from 'unleash-client';
import { FeatureInterface } from 'unleash-client/lib/feature';
import Metrics from 'unleash-client/lib/metrics';
import {
type Context,
type Unleash,
UnleashEvents,
type Variant,
} from 'unleash-client';
import type { FeatureInterface } from 'unleash-client/lib/feature';
import type Metrics from 'unleash-client/lib/metrics';
import { getDefaultVariant } from 'unleash-client/lib/variant';
import { IProxyConfig } from './config';
import { Logger } from './logger';
import type { IProxyConfig } from './config';
import type { Logger } from './logger';
import { lastMetricsFetch, lastMetricsUpdate } from './prom-metrics';

export type FeatureToggleStatus = {
Expand Down
22 changes: 13 additions & 9 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { CorsOptions } from 'cors';
import { Application } from 'express';
import { ClientFeaturesResponse, Strategy, TagFilter } from 'unleash-client';
import { BootstrapOptions } from 'unleash-client/lib/repository/bootstrap-provider';
import { Logger, LogLevel, SimpleLogger } from './logger';
import type { CorsOptions } from 'cors';
import type { Application } from 'express';
import type {
ClientFeaturesResponse,
Strategy,
TagFilter,
} from 'unleash-client';
import type { HttpOptions } from 'unleash-client/lib/http-options';
import type { BootstrapOptions } from 'unleash-client/lib/repository/bootstrap-provider';
import type { StorageProvider } from 'unleash-client/lib/repository/storage-provider';
import type { ContextEnricher } from './enrich-context';
import { type LogLevel, type Logger, SimpleLogger } from './logger';
import { generateInstanceId } from './util';
import { HttpOptions } from 'unleash-client/lib/http-options';
import { StorageProvider } from 'unleash-client/lib/repository/storage-provider';
import { ContextEnricher } from './enrich-context';

export interface ServerSideSdkConfig {
tokens: string[];
Expand Down Expand Up @@ -310,7 +314,7 @@ export function createProxyConfig(option: IProxyOption): IProxyConfig {
process.env.UNLEASH_INSTANCE_ID ||
generateInstanceId();

let proxyBasePath = sanitizeBasePath(
const proxyBasePath = sanitizeBasePath(
option.proxyBasePath || process.env.PROXY_BASE_PATH,
);
return {
Expand Down
2 changes: 1 addition & 1 deletion src/content-type-checker.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RequestHandler } from 'express';
import type { RequestHandler } from 'express';
import { hasBody, is } from 'type-is';

const DEFAULT_ACCEPTED_CONTENT_TYPE = 'application/json';
Expand Down
4 changes: 2 additions & 2 deletions src/context-middleware.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NextFunction, Request, Response } from 'express';
import type { NextFunction, Request, Response } from 'express';
import { createContext } from './create-context';
import { ContextEnricher, enrichContext } from './enrich-context';
import { type ContextEnricher, enrichContext } from './enrich-context';

const POST = 'POST';
const GET = 'GET';
Expand Down
14 changes: 7 additions & 7 deletions src/create-client.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { IProxyConfig } from './config';
import Client from './client';
import { initialize, Unleash } from 'unleash-client';
import { Unleash, initialize } from 'unleash-client';
import Metrics from 'unleash-client/lib/metrics';
import { defaultStrategies } from 'unleash-client/lib/strategy';
import Client from './client';
import type { IProxyConfig } from './config';

export const createSingletonClient = (config: IProxyConfig): Client => {
const customHeadersFunction = async () => ({
Expand All @@ -23,7 +23,7 @@ export const createSingletonClient = (config: IProxyConfig): Client => {
customHeadersFunction,
bootstrap: config.bootstrap,
storageProvider: config.storageProvider,
...(!!config.httpOptions ? { httpOptions: config.httpOptions } : {}),
...(config.httpOptions ? { httpOptions: config.httpOptions } : {}),
});

const metrics = new Metrics({
Expand All @@ -35,7 +35,7 @@ export const createSingletonClient = (config: IProxyConfig): Client => {
metricsJitter: config.metricsJitter,
url: config.unleashUrl,
customHeadersFunction,
...(!!config.httpOptions ? { httpOptions: config.httpOptions } : {}),
...(config.httpOptions ? { httpOptions: config.httpOptions } : {}),
});

return new Client(config, unleash, metrics);
Expand All @@ -60,7 +60,7 @@ export const createNewClient = (config: IProxyConfig): Client => {
customHeadersFunction,
bootstrap: config.bootstrap,
storageProvider: config.storageProvider,
...(!!config.httpOptions ? { httpOptions: config.httpOptions } : {}),
...(config.httpOptions ? { httpOptions: config.httpOptions } : {}),
});

const metrics = new Metrics({
Expand All @@ -72,7 +72,7 @@ export const createNewClient = (config: IProxyConfig): Client => {
metricsJitter: config.metricsJitter,
url: config.unleashUrl,
customHeadersFunction,
...(!!config.httpOptions ? { httpOptions: config.httpOptions } : {}),
...(config.httpOptions ? { httpOptions: config.httpOptions } : {}),
});

return new Client(config, unleash, metrics);
Expand Down
Loading
Loading