Skip to content

Commit

Permalink
chore: fix linting (#168)
Browse files Browse the repository at this point in the history
  • Loading branch information
Uzlopak authored Oct 8, 2023
1 parent 7631349 commit 9048df4
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
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

0 comments on commit 9048df4

Please sign in to comment.