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

fix linting #168

Merged
merged 1 commit into from
Oct 8, 2023
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"test:unit": "npm run test:jest && npm run test:tap",
"test:typescript": "tsd",
"lint": "eslint \"test/**/*.js\" \"test-tap/**/*.js\" index.js",
"prettier": "prettier --write \"{lib,test,test-tap}/**/*.js\" index.js index.d.ts"
"prettier": "prettier --write \"{lib,test,test-tap}/**/*.js\" index.js \"types/**/*.ts\""
},
"dependencies": {
"fastify-plugin": "^4.0.0"
Expand Down
4 changes: 2 additions & 2 deletions test/internal/testService.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ class TestService {
const testValueFromLib = requestContext.get('testKey')
if (testValueFromApp !== `testValue${requestId}`) {
throw new Error(
`Wrong value retrieved from app context for request ${requestId}: ${testValueFromApp}`
`Wrong value retrieved from app context for request ${requestId}: ${testValueFromApp}`,
)
}

if (testValueFromLib !== `testValue${requestId}`) {
throw new Error(
`Wrong value retrieved from lib context for request ${requestId}: ${testValueFromLib}`
`Wrong value retrieved from lib context for request ${requestId}: ${testValueFromLib}`,
)
}
})
Expand Down
7 changes: 5 additions & 2 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { FastifyPluginCallback, FastifyRequest } from 'fastify'

type FastifyRequestContext = FastifyPluginCallback<fastifyRequestContext.FastifyRequestContextOptions>
type FastifyRequestContext =
FastifyPluginCallback<fastifyRequestContext.FastifyRequestContextOptions>

declare module 'fastify' {
interface FastifyRequest {
Expand Down Expand Up @@ -60,5 +61,7 @@ declare namespace fastifyRequestContext {
export { fastifyRequestContext as default }
}

declare function fastifyRequestContext(...params: Parameters<FastifyRequestContext>): ReturnType<FastifyRequestContext>
declare function fastifyRequestContext(
...params: Parameters<FastifyRequestContext>
): ReturnType<FastifyRequestContext>
export = fastifyRequestContext
22 changes: 11 additions & 11 deletions types/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ app.register(fastifyRequestContext)

declare module './index' {
interface RequestContextData {
a?: string,
a?: string
log?: FastifyBaseLogger
}
}
Expand All @@ -30,8 +30,8 @@ expectAssignable<FastifyRequestContextOptions>({
})
expectAssignable<FastifyRequestContextOptions>({
defaultStoreValues: () => ({
a: 'dummy'
})
a: 'dummy',
}),
})

expectError<FastifyRequestContextOptions>({
Expand All @@ -43,21 +43,21 @@ expectError<FastifyRequestContextOptions>({
})

expectAssignable<RequestContextDataFactory>(() => ({
a: 'dummy'
a: 'dummy',
}))

expectAssignable<FastifyRequestContextOptions>({
defaultStoreValues: req => ({
log: req.log.child({ childLog: true })
})
defaultStoreValues: (req) => ({
log: req.log.child({ childLog: true }),
}),
})

expectAssignable<RequestContextDataFactory>(req => ({
log: req.log.child({ childLog: true })
expectAssignable<RequestContextDataFactory>((req) => ({
log: req.log.child({ childLog: true }),
}))

expectError<RequestContextDataFactory>(req => ({ bar: 'dummy' }))
expectError<RequestContextDataFactory>(req => ({ log: 'dummy' }))
expectError<RequestContextDataFactory>((req) => ({ bar: 'dummy' }))
expectError<RequestContextDataFactory>((req) => ({ log: 'dummy' }))

expectType<RequestContext>(app.requestContext)
expectType<RequestContext>(requestContext)
Expand Down
Loading