From 9784fdf529dd53b4bb5f78c886f1ba8f171825c8 Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Sun, 8 Dec 2024 10:45:11 +0000 Subject: [PATCH 1/7] build(deps-dev): replace standard with neostandard --- README.md | 2 +- lib/httpError.d.ts | 8 ++++---- package.json | 6 +++--- types/index.d.ts | 4 ++-- types/index.test-d.ts | 21 ++++++++++----------- 5 files changed, 20 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 43a6517..20f4462 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![CI](https://github.com/fastify/fastify-sensible/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/fastify/fastify-sensible/actions/workflows/ci.yml) [![NPM version](https://img.shields.io/npm/v/@fastify/sensible.svg?style=flat)](https://www.npmjs.com/package/@fastify/sensible) -[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/) +[![neostandard javascript style](https://img.shields.io/badge/code_style-neostandard-brightgreen?style=flat)](https://github.com/neostandard/neostandard) Defaults for Fastify that everyone can agree on™.
This plugin adds some useful utilities to your Fastify instance, see the API section to learn more. diff --git a/lib/httpError.d.ts b/lib/httpError.d.ts index 08649e4..f754dbc 100644 --- a/lib/httpError.d.ts +++ b/lib/httpError.d.ts @@ -8,7 +8,7 @@ export declare class HttpError extends Error { [key: string]: any; } -type UnknownError = Error | string | number | { [key: string]: any }; +type UnknownError = Error | string | number | { [key: string]: any } export type HttpErrorCodes = 400 | '400' // BadRequest | 401 | '401' // Unauthorized @@ -92,13 +92,13 @@ export type HttpErrorNames = 'badRequest' | 'loopDetected' | 'bandwidthLimitExceeded' | 'notExtended' - | 'networkAuthenticationRequired'; + | 'networkAuthenticationRequired' export type HttpErrors = { HttpError: typeof HttpError; getHttpError: (code: HttpErrorCodes, message?: string) => HttpError; createError: (...args: UnknownError[]) => HttpError; -} & Record HttpError>; +} & Record HttpError> declare const HttpErrors: HttpErrors -export default HttpErrors; +export default HttpErrors diff --git a/package.json b/package.json index 7c8d7ca..1480c6e 100644 --- a/package.json +++ b/package.json @@ -6,8 +6,8 @@ "type": "commonjs", "types": "types/index.d.ts", "scripts": { - "lint": "standard", - "lint:fix": "standard --fix", + "lint": "eslint", + "lint:fix": "eslint --fix", "test": "npm run test:unit && npm run test:typescript", "test:typescript": "tsd", "test:unit": "tap" @@ -32,7 +32,7 @@ "@fastify/pre-commit": "^2.1.0", "@types/node": "^22.0.0", "fastify": "^5.0.0", - "standard": "^17.1.0", + "neostandard": "^0.11.9", "tap": "^18.7.1", "tsd": "^0.31.0" }, diff --git a/types/index.d.ts b/types/index.d.ts index b4861d9..ff5cfe8 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -24,7 +24,7 @@ type staleTypes = 'while-revalidate' | 'if-error' declare module 'fastify' { namespace SensibleTypes { - type ToType = [Error, T]; + type ToType = [Error, T] } interface Assert { @@ -105,5 +105,5 @@ declare namespace fastifySensible { export { fastifySensible as default } } -declare function fastifySensible(...params: Parameters): ReturnType +declare function fastifySensible (...params: Parameters): ReturnType export = fastifySensible diff --git a/types/index.test-d.ts b/types/index.test-d.ts index b572d62..6d129ea 100644 --- a/types/index.test-d.ts +++ b/types/index.test-d.ts @@ -6,9 +6,9 @@ const app = fastify() app.register(fastifySensible) -expectAssignable({}); -expectAssignable({ sharedSchemaId: 'HttpError' }); -expectNotAssignable({ notSharedSchemaId: 'HttpError' }); +expectAssignable({}) +expectAssignable({ sharedSchemaId: 'HttpError' }) +expectNotAssignable({ notSharedSchemaId: 'HttpError' }) app.get('/', (req, reply) => { expectAssignable(reply.badRequest()) @@ -60,13 +60,12 @@ app.get('/', (req, reply) => { expectAssignable(app.httpErrors.createError(405, 'Method Not Allowed')) }) -app.get("/", (req, reply) => { +app.get('/', (req, reply) => { expectAssignable( - app.httpErrors.createError(405, "Method Not Allowed"), - ); - expectAssignable(app.httpErrors.badRequest()); -}); - + app.httpErrors.createError(405, 'Method Not Allowed') + ) + expectAssignable(app.httpErrors.badRequest()) +}) app.get('/', async (req, reply) => { expectAssignable(app.httpErrors.badRequest()) @@ -158,5 +157,5 @@ app.get('/', async (req, reply) => { expectType(req.is('foo', 'bar')) }) -httpErrors.forbidden('This type should be also available'); -httpErrors.createError('MyError'); +httpErrors.forbidden('This type should be also available') +httpErrors.createError('MyError') From 83d31e2343d5d5e34ba3cc30d30c7b6a2283ff84 Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Sun, 8 Dec 2024 10:54:05 +0000 Subject: [PATCH 2/7] chore: add eslint.config.js --- eslint.config.js | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 eslint.config.js diff --git a/eslint.config.js b/eslint.config.js new file mode 100644 index 0000000..89fd678 --- /dev/null +++ b/eslint.config.js @@ -0,0 +1,6 @@ +'use strict' + +module.exports = require('neostandard')({ + ignores: require('neostandard').resolveIgnoresFromGitignore(), + ts: true +}) From b61dc34d0577334ac3f1e6fc78381e78c49bfa11 Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Sun, 15 Dec 2024 20:01:31 +0000 Subject: [PATCH 3/7] chore:rebase --- lib/httpError.d.ts | 7 ++++--- package.json | 2 +- types/index.d.ts | 12 ++++++------ 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/httpError.d.ts b/lib/httpError.d.ts index f754dbc..aa06921 100644 --- a/lib/httpError.d.ts +++ b/lib/httpError.d.ts @@ -1,10 +1,11 @@ export declare class HttpError extends Error { - status: N; - statusCode: N; - expose: boolean; + status: N + statusCode: N + expose: boolean headers?: { [key: string]: string; }; + [key: string]: any; } diff --git a/package.json b/package.json index 1480c6e..7ef4753 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "@fastify/pre-commit": "^2.1.0", "@types/node": "^22.0.0", "fastify": "^5.0.0", - "neostandard": "^0.11.9", + "neostandard": "^0.12.0", "tap": "^18.7.1", "tsd": "^0.31.0" }, diff --git a/types/index.d.ts b/types/index.d.ts index ff5cfe8..a656865 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -1,5 +1,5 @@ -import { FastifyPluginCallback, FastifyReply } from 'fastify' -import { HttpErrors, HttpError } from "../lib/httpError" +import { FastifyPluginCallback, FastifyReply } from 'fastify' +import { HttpErrors, HttpError } from '../lib/httpError' import * as Errors from '../lib/httpError' type FastifySensible = FastifyPluginCallback @@ -89,11 +89,11 @@ declare namespace fastifySensible { sharedSchemaId?: string; } - export { HttpError }; + export { HttpError } - export type HttpErrors = Errors.HttpErrors; - export type HttpErrorCodes = Errors.HttpErrorCodes; - export type HttpErrorNames = Errors.HttpErrorNames; + export type HttpErrors = Errors.HttpErrors + export type HttpErrorCodes = Errors.HttpErrorCodes + export type HttpErrorNames = Errors.HttpErrorNames export const httpErrors: typeof Errors.default From e41091595671c3c1216b7ba5586ab478d80b9846 Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Mon, 16 Dec 2024 20:19:24 +0000 Subject: [PATCH 4/7] Update package.json Signed-off-by: Frazer Smith --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 7ef4753..6e29cf8 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ "devDependencies": { "@fastify/pre-commit": "^2.1.0", "@types/node": "^22.0.0", + "eslint": "^9.17.0", "fastify": "^5.0.0", "neostandard": "^0.12.0", "tap": "^18.7.1", From e94e2c12af6a451d208e1555fea962335744904f Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Tue, 17 Dec 2024 07:55:55 +0000 Subject: [PATCH 5/7] Update lib/httpError.d.ts Co-authored-by: Arthur Fiorette <47537704+arthurfiorette@users.noreply.github.com> Signed-off-by: Frazer Smith --- lib/httpError.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/httpError.d.ts b/lib/httpError.d.ts index aa06921..917e37a 100644 --- a/lib/httpError.d.ts +++ b/lib/httpError.d.ts @@ -101,5 +101,5 @@ export type HttpErrors = { createError: (...args: UnknownError[]) => HttpError; } & Record HttpError> -declare const HttpErrors: HttpErrors +declare const HttpErrors: httpErrors export default HttpErrors From b28e2071d48171b471649b8e9c6e1774160ddb9e Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Tue, 17 Dec 2024 07:56:01 +0000 Subject: [PATCH 6/7] Update lib/httpError.d.ts Co-authored-by: Arthur Fiorette <47537704+arthurfiorette@users.noreply.github.com> Signed-off-by: Frazer Smith --- lib/httpError.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/httpError.d.ts b/lib/httpError.d.ts index 917e37a..7564ecc 100644 --- a/lib/httpError.d.ts +++ b/lib/httpError.d.ts @@ -102,4 +102,4 @@ export type HttpErrors = { } & Record HttpError> declare const HttpErrors: httpErrors -export default HttpErrors +export default httpErrors From a2158cba7d9f15232ee8cd0e920ab35ee34b184a Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Tue, 17 Dec 2024 08:05:51 +0000 Subject: [PATCH 7/7] chore: ignore --- lib/httpError.d.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/httpError.d.ts b/lib/httpError.d.ts index 7564ecc..a66a966 100644 --- a/lib/httpError.d.ts +++ b/lib/httpError.d.ts @@ -101,5 +101,6 @@ export type HttpErrors = { createError: (...args: UnknownError[]) => HttpError; } & Record HttpError> -declare const HttpErrors: httpErrors -export default httpErrors +// eslint-disable-next-line @typescript-eslint/no-redeclare +declare const HttpErrors: HttpErrors +export default HttpErrors