Skip to content

Commit

Permalink
Port to neostandard (#538)
Browse files Browse the repository at this point in the history
* Port to neostandard

Signed-off-by: Matteo Collina <[email protected]>

* update workflow

Signed-off-by: Matteo Collina <[email protected]>

---------

Signed-off-by: Matteo Collina <[email protected]>
  • Loading branch information
mcollina authored Jul 29, 2024
1 parent aeb987d commit 36553e9
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 61 deletions.
26 changes: 0 additions & 26 deletions .eslintrc.json

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ on:

jobs:
test:
uses: fastify/workflows/.github/workflows/plugins-ci.yml@v4.0.0
uses: fastify/workflows/.github/workflows/plugins-ci.yml@v5.0.0
with:
license-check: true
lint: true
lint: true
20 changes: 20 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict'

const neo = require('neostandard')

module.exports = [
...neo({
ts: true
}),
{
rules: {
'@stylistic/comma-dangle': ['error', {
arrays: 'never',
objects: 'never',
imports: 'never',
exports: 'never',
functions: 'never'
}]
}
}
]
16 changes: 4 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,25 @@
"@fastify/swagger": "^9.0.0-pre.fv5.1",
"@fastify/swagger-ui": "^5.0.0-pre.fv5.1",
"@types/node": "^20.11.6",
"@typescript-eslint/eslint-plugin": "^7.1.0",
"@typescript-eslint/parser": "^7.1.0",
"benchmark": "^2.1.4",
"climem": "^2.0.0",
"concat-stream": "^2.0.0",
"eslint": "^8.56.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-n": "^17.9.0",
"eslint-plugin-promise": "^6.1.1",
"eslint": "^9.8.0",
"fastify": "^5.0.0-alpha.3",
"form-data": "^4.0.0",
"h2url": "^0.2.0",
"neostandard": "^0.11.1",
"noop-stream": "^0.1.0",
"pump": "^3.0.0",
"readable-stream": "^4.5.2",
"snazzy": "^9.0.0",
"standard": "^17.1.0",
"tap": "^18.6.1",
"tsd": "^0.31.0"
},
"scripts": {
"coverage": "npm run test:unit -- --coverage-report=html",
"climem": "climem 8999 localhost",
"lint": "npm run lint:javascript && npm run lint:typescript",
"lint:javascript": "standard | snazzy",
"lint:fix": "standard --fix && npm run lint:typescript -- --fix",
"lint:typescript": "eslint -c .eslintrc.json types/**/*.d.ts types/**/*.test-d.ts",
"lint": "eslint",
"lint:fix": "eslint --fix",
"start": "CLIMEM=8999 node -r climem ./examples/example",
"test": "npm run test:unit && npm run test:typescript",
"test:typescript": "tsd",
Expand Down
10 changes: 0 additions & 10 deletions tsconfig.eslint.json

This file was deleted.

14 changes: 7 additions & 7 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ type FastifyMultipartPlugin = FastifyPluginCallback<
| fastifyMultipart.FastifyMultipartBaseOptions
| fastifyMultipart.FastifyMultipartOptions
| fastifyMultipart.FastifyMultipartAttachFieldsToBodyOptions
>;
>

type MultipartHandler = (
field: string,
file: BusboyFileStream,
filename: string,
encoding: string,
mimetype: string
) => void;
) => void

interface BodyEntry {
data: Buffer;
Expand All @@ -76,7 +76,7 @@ declare namespace fastifyMultipart {
filepath: string;
}

export type Multipart = MultipartFile | MultipartValue;
export type Multipart = MultipartFile | MultipartValue

export interface MultipartFile {
type: 'file';
Expand Down Expand Up @@ -204,13 +204,13 @@ declare namespace fastifyMultipart {
/**
* Adds a new type `isFile` to help @fastify/swagger generate the correct schema.
*/
export function ajvFilePlugin(ajv: any): void;
export function ajvFilePlugin (ajv: any): void

export const fastifyMultipart: FastifyMultipartPlugin
export { fastifyMultipart as default }
}
declare function fastifyMultipart(
declare function fastifyMultipart (
...params: Parameters<FastifyMultipartPlugin>
): ReturnType<FastifyMultipartPlugin>;
): ReturnType<FastifyMultipartPlugin>

export = fastifyMultipart;
export = fastifyMultipart
9 changes: 5 additions & 4 deletions types/index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable @typescript-eslint/no-unused-expressions */
import fastify from 'fastify'
import fastifyMultipart, { MultipartValue, MultipartFields, MultipartFile, FastifyMultipartBaseOptions } from '..'
import fastifyMultipart, { MultipartValue, MultipartFields, MultipartFile } from '..'
import * as util from 'util'
import { pipeline } from 'stream'
import * as fs from 'fs'
Expand Down Expand Up @@ -56,7 +57,7 @@ const runServer = async () => {
})

// Multiple fields including scalar values
app.post<{Body: {file: MultipartFile, foo: MultipartValue<string>}}>('/upload/stringvalue', async (req, reply) => {
app.post<{ Body: { file: MultipartFile, foo: MultipartValue<string> } }>('/upload/stringvalue', async (req, reply) => {
expectError(req.body.foo.file)
expectType<'field'>(req.body.foo.type)
expectType<string>(req.body.foo.value)
Expand All @@ -66,7 +67,7 @@ const runServer = async () => {
reply.send()
})

app.post<{Body: {file: MultipartFile, num: MultipartValue<number>}}>('/upload/stringvalue', async (req, reply) => {
app.post<{ Body: { file: MultipartFile, num: MultipartValue<number> } }>('/upload/stringvalue', async (req, reply) => {
expectType<number>(req.body.num.value)
reply.send()

Expand Down Expand Up @@ -129,7 +130,7 @@ const runServer = async () => {
app.post('/upload/raw/any', async function (req, reply) {
const data = await req.file()
if (!data) throw new Error('missing file')
const buffer = await data.toBuffer()
expectType<Buffer>(await data.toBuffer())
// upload to S3
reply.send()
})
Expand Down

0 comments on commit 36553e9

Please sign in to comment.