Skip to content

Commit

Permalink
style: linting
Browse files Browse the repository at this point in the history
  • Loading branch information
climba03003 committed Jul 20, 2023
1 parent e5af48b commit 9e0fdf4
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 23 deletions.
6 changes: 3 additions & 3 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FastifyPluginAsync, FastifyRequest } from 'fastify'
import { type FastifyPluginAsync, type FastifyRequest } from 'fastify'
import FastifyPlugin from 'fastify-plugin'
import type { Fields, File, Files, Options } from 'formidable'
// Since, formidable is CommonJS module
Expand All @@ -7,7 +7,7 @@ import type { Fields, File, Files, Options } from 'formidable'
import FormidableNamespace from 'formidable'
import type Formidable from 'formidable/Formidable'
import * as fs from 'fs'
import { IncomingMessage } from 'http'
import { type IncomingMessage } from 'http'
export const kIsMultipart = Symbol.for('[FastifyMultipart.isMultipart]')
export const kIsMultipartParsed = Symbol.for('[FastifyMultipart.isMultipartParsed]')
export const kFileSavedPaths = Symbol.for('[FastifyMultipart.fileSavedPaths]')
Expand All @@ -30,7 +30,7 @@ export interface FastifyFormidableOptions {
formidable?: Formidable | Options
}

function promisify (func: Function): (request: IncomingMessage) => Promise<{ fields: Fields, files: Files }> {
function promisify (func: (request: IncomingMessage, callback: (err: any, fields: Fields, files: Files) => void) => void): (request: IncomingMessage) => Promise<{ fields: Fields, files: Files }> {
return async function (request: IncomingMessage): Promise<{ fields: Fields, files: Files }> {
return await new Promise(function (resolve, reject) {
func(request, function (err: any, fields: Fields, files: Files) {
Expand Down
2 changes: 1 addition & 1 deletion test/addContentTypeParser.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as fs from 'fs'
import { AddressInfo } from 'net'
import { type AddressInfo } from 'net'
import * as path from 'path'
import t from 'tap'
import { createFastify } from './createFastify'
Expand Down
2 changes: 1 addition & 1 deletion test/addHooks.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as fs from 'fs'
import { AddressInfo } from 'net'
import { type AddressInfo } from 'net'
import * as path from 'path'
import t from 'tap'
import { createFastify } from './createFastify'
Expand Down
10 changes: 5 additions & 5 deletions test/createFastify.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fastifySwagger from '@fastify/swagger'
import Fastify, { FastifyInstance } from 'fastify'
import { Options } from 'formidable'
import FastifyFormidable, { ajvBinaryFormat, FastifyFormidableOptions } from '../lib'
import Fastify, { type FastifyInstance } from 'fastify'
import { type Options } from 'formidable'
import FastifyFormidable, { ajvBinaryFormat, type FastifyFormidableOptions } from '../lib'

// reduce keep alive to prevent `undici` keep the socket open
export const fastifyOptions = { keepAliveTimeout: 100 }
Expand All @@ -11,7 +11,7 @@ export async function createFastify (t: Tap.Test, options: FastifyFormidableOpti

await fastify.register(FastifyFormidable, options)

fastify.post<{ Body: { foo: String, file: string } }>('/', async function (request, reply) {
fastify.post<{ Body: { foo: string, file: string } }>('/', async function (request, reply) {
if (inline === true) await request.parseMultipart()
if (typeof inline === 'object') await request.parseMultipart(inline)
return await reply.code(200).send({
Expand All @@ -38,7 +38,7 @@ export async function createIntegrationFastify (t: Tap.Test, options: FastifyFor
await fastify.register(FastifyFormidable, options)
await fastify.register(fastifySwagger)

fastify.post<{ Body: { foo: String, file: string } }>('/', {
fastify.post<{ Body: { foo: string, file: string } }>('/', {
schema
}, async function (request, reply) {
if (inline) await request.parseMultipart()
Expand Down
7 changes: 3 additions & 4 deletions test/error.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Fastify from 'fastify'
import { IncomingForm } from 'formidable'
import * as fs from 'fs'
import { AddressInfo } from 'net'
import { type AddressInfo } from 'net'
import * as path from 'path'
import t from 'tap'
import FastifyFormidable from '../lib'
Expand Down Expand Up @@ -36,16 +36,15 @@ t.test('error', function (t) {
t.teardown(fastify.close)

const formidable = new IncomingForm()
// @ts-expect-error
formidable.parse = function (_, callback: Function) {
formidable.parse = function (_, callback: (err: any) => void) {
callback(new Error('parse error'))
}

await fastify.register(FastifyFormidable, {
formidable
})

fastify.post<{ Body: { foo: String, file: string } }>('/', async function (request, reply) {
fastify.post<{ Body: { foo: string, file: string } }>('/', async function (request, reply) {
const body = await request.parseMultipart()
return await reply.code(200).send({
body,
Expand Down
2 changes: 1 addition & 1 deletion test/integration.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as fs from 'fs'
import { AddressInfo } from 'net'
import { type AddressInfo } from 'net'
import * as path from 'path'
import t from 'tap'
import { createIntegrationFastify } from './createFastify'
Expand Down
2 changes: 1 addition & 1 deletion test/parseMultipart.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as fs from 'fs'
import { AddressInfo } from 'net'
import { type AddressInfo } from 'net'
import * as path from 'path'
import t from 'tap'
import { createFastify } from './createFastify'
Expand Down
10 changes: 5 additions & 5 deletions test/removeFilesFromBody.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Fastify from 'fastify'
import * as fs from 'fs'
import { AddressInfo } from 'net'
import { type AddressInfo } from 'net'
import * as path from 'path'
import t from 'tap'
import FastifyFormidable from '../lib'
Expand All @@ -26,7 +26,7 @@ t.test('removeFilesFromBody', function (t) {
removeFilesFromBody: true
})

fastify.post<{ Body: { foo: String, file: string } }>('/', async function (request, reply) {
fastify.post<{ Body: { foo: string, file: string } }>('/', async function (request, reply) {
return await reply.code(200).send({
body: request.body,
files: request.files
Expand Down Expand Up @@ -63,7 +63,7 @@ t.test('removeFilesFromBody', function (t) {
removeFilesFromBody: true
})

fastify.post<{ Body: { foo: String, file: string } }>('/', async function (request, reply) {
fastify.post<{ Body: { foo: string, file: string } }>('/', async function (request, reply) {
return await reply.code(200).send({
body: request.body,
files: request.files
Expand Down Expand Up @@ -99,7 +99,7 @@ t.test('removeFilesFromBody', function (t) {
removeFilesFromBody: true
})

fastify.post<{ Body: { foo: String, file: string } }>('/', async function (request, reply) {
fastify.post<{ Body: { foo: string, file: string } }>('/', async function (request, reply) {
const body = await request.parseMultipart()
return await reply.code(200).send({
body,
Expand Down Expand Up @@ -137,7 +137,7 @@ t.test('removeFilesFromBody', function (t) {
removeFilesFromBody: true
})

fastify.post<{ Body: { foo: String, file: string } }>('/', async function (request, reply) {
fastify.post<{ Body: { foo: string, file: string } }>('/', async function (request, reply) {
return await reply.code(200).send({
body: request.body,
files: request.files
Expand Down
4 changes: 2 additions & 2 deletions test/warning.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Fastify from 'fastify'
import * as fs from 'fs'
import { AddressInfo } from 'net'
import { type AddressInfo } from 'net'
import * as path from 'path'
import t from 'tap'
import FastifyFormidable from '../lib'
Expand All @@ -26,7 +26,7 @@ t.test('warning', function (t) {
removeFilesFromBody: true
})

fastify.post<{ Body: { foo: String, file: string } }>('/', {
fastify.post<{ Body: { foo: string, file: string } }>('/', {
onRequest (request, _, done) {
request.log = {
warn (msg: string) {
Expand Down

0 comments on commit 9e0fdf4

Please sign in to comment.