diff --git a/fastify.js b/fastify.js index 2ef6d28bf1..044ad5abf4 100644 --- a/fastify.js +++ b/fastify.js @@ -175,9 +175,9 @@ function fastify (options) { // Default router const router = buildRouting({ config: { - defaultRoute: defaultRoute, - onBadUrl: onBadUrl, - constraints: constraints, + defaultRoute, + onBadUrl, + constraints, ignoreTrailingSlash: options.ignoreTrailingSlash || defaultInitOptions.ignoreTrailingSlash, maxParamLength: options.maxParamLength || defaultInitOptions.maxParamLength, caseSensitive: options.caseSensitive, @@ -268,16 +268,16 @@ function fastify (options) { // expose logger instance log: logger, // hooks - addHook: addHook, + addHook, // schemas - addSchema: addSchema, + addSchema, getSchema: schemaController.getSchema.bind(schemaController), getSchemas: schemaController.getSchemas.bind(schemaController), - setValidatorCompiler: setValidatorCompiler, - setSerializerCompiler: setSerializerCompiler, - setSchemaController: setSchemaController, - setReplySerializer: setReplySerializer, - setSchemaErrorFormatter: setSchemaErrorFormatter, + setValidatorCompiler, + setSerializerCompiler, + setSchemaController, + setReplySerializer, + setSchemaErrorFormatter, // custom parsers addContentTypeParser: ContentTypeParser.helpers.addContentTypeParser, hasContentTypeParser: ContentTypeParser.helpers.hasContentTypeParser, @@ -293,8 +293,8 @@ function fastify (options) { close: null, printPlugins: null, // http server - listen: listen, - server: server, + listen, + server, // extend fastify objects decorate: decorator.add, hasDecorator: decorator.exist, @@ -303,12 +303,12 @@ function fastify (options) { hasRequestDecorator: decorator.existRequest, hasReplyDecorator: decorator.existReply, // fake http injection - inject: inject, + inject, // pretty print of the registered routes printRoutes, // custom error handling - setNotFoundHandler: setNotFoundHandler, - setErrorHandler: setErrorHandler, + setNotFoundHandler, + setErrorHandler, // Set fastify initial configuration options read-only object initialConfig } diff --git a/lib/decorate.js b/lib/decorate.js index 9d54010889..076d254aa0 100644 --- a/lib/decorate.js +++ b/lib/decorate.js @@ -134,6 +134,6 @@ module.exports = { existRequest: checkRequestExistence, existReply: checkReplyExistence, dependencies: checkDependencies, - decorateReply: decorateReply, - decorateRequest: decorateRequest + decorateReply, + decorateRequest } diff --git a/lib/reply.js b/lib/reply.js index 437df87dcc..f852ad60d2 100644 --- a/lib/reply.js +++ b/lib/reply.js @@ -579,11 +579,11 @@ function handleError (reply, error, cb) { const serializerFn = getSchemaSerializer(reply.context, statusCode) payload = (serializerFn === false) ? serializeError({ - error: statusCodes[statusCode + ''], - code: error.code, - message: error.message || '', - statusCode: statusCode - }) + error: statusCodes[statusCode + ''], + code: error.code, + message: error.message || '', + statusCode + }) : serializerFn(Object.create(error, { error: { value: statusCodes[statusCode + ''] }, message: { value: error.message || '' }, diff --git a/lib/schema-controller.js b/lib/schema-controller.js index 34821486b1..fa27610675 100644 --- a/lib/schema-controller.js +++ b/lib/schema-controller.js @@ -25,7 +25,7 @@ function buildSchemaController (parentSchemaCtrl, opts) { const option = { bucket: (opts && opts.bucket) || buildSchemas, - compilersFactory: compilersFactory + compilersFactory } return new SchemaController(undefined, option) diff --git a/lib/server.js b/lib/server.js index adcfd06dd3..490408f47c 100644 --- a/lib/server.js +++ b/lib/server.js @@ -52,7 +52,7 @@ function createServer (options, httpHandler) { } const cb = typeof args[args.length - 1] === 'function' ? args.pop() : undefined - const options = { cb: cb } + const options = { cb } const firstArg = args[0] const argsLength = args.length diff --git a/package.json b/package.json index 8678401068..27b0c913bf 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "license-checker": "license-checker --production --onlyAllow=\"MIT;ISC;BSD-3-Clause;BSD-2-Clause\"", "lint": "npm run lint:standard && npm run lint:typescript", "lint:fix": "standard --fix", - "lint:standard": "standard --verbose | snazzy", + "lint:standard": "standard | snazzy", "lint:typescript": "eslint -c types/.eslintrc.json types/**/*.d.ts test/types/**/*.test-d.ts", "prepublishOnly": "tap --no-check-coverage test/internals/version.test.js", "test": "npm run lint && npm run unit && npm run test:typescript", @@ -127,8 +127,8 @@ "@sinonjs/fake-timers": "^8.1.0", "@types/node": "^16.0.0", "@types/pino": "^6.0.1", - "@typescript-eslint/eslint-plugin": "^4.5.0", - "@typescript-eslint/parser": "^4.5.0", + "@typescript-eslint/eslint-plugin": "^5.0.0", + "@typescript-eslint/parser": "^5.0.0", "JSONStream": "^1.3.5", "ajv": "^6.0.0", "ajv-errors": "^1.0.1", @@ -140,13 +140,12 @@ "cors": "^2.8.5", "coveralls": "^3.1.0", "dns-prefetch-control": "^0.3.0", - "eslint": "^7.11.0", - "eslint-config-standard": "^16.0.1", + "eslint": "^8.0.1", + "eslint-config-standard": "^17.0.0-1", "eslint-import-resolver-node": "^0.3.2", - "eslint-plugin-import": "^2.20.2", - "eslint-plugin-node": "^11.1.0", - "eslint-plugin-promise": "^5.1.0", - "eslint-plugin-standard": "^5.0.0", + "eslint-plugin-import": "^2.25.4", + "eslint-plugin-n": "^14.0.0", + "eslint-plugin-promise": "^6.0.0", "fast-json-body": "^1.1.0", "fastify-plugin": "^3.0.0", "fluent-json-schema": "^3.0.0", @@ -167,7 +166,7 @@ "simple-get": "^4.0.0", "snazzy": "^9.0.0", "split2": "^4.1.0", - "standard": "^16.0.1", + "standard": "^17.0.0-2", "tap": "^15.1.1", "tap-mocha-reporter": "^5.0.1", "then-sleep": "^1.0.1", diff --git a/test/async-await.test.js b/test/async-await.test.js index 56552418f4..17beab0190 100644 --- a/test/async-await.test.js +++ b/test/async-await.test.js @@ -407,7 +407,7 @@ test('error is logged because promise was fulfilled with undefined', t => { try { fastify = Fastify({ logger: { - stream: stream, + stream, level: 'error' } }) @@ -447,7 +447,7 @@ test('error is not logged because promise was fulfilled with undefined but statu try { fastify = Fastify({ logger: { - stream: stream, + stream, level: 'error' } }) @@ -488,7 +488,7 @@ test('error is not logged because promise was fulfilled with undefined but respo try { fastify = Fastify({ logger: { - stream: stream, + stream, level: 'error' } }) diff --git a/test/close.test.js b/test/close.test.js index 2d38a93a00..38b407c1d1 100644 --- a/test/close.test.js +++ b/test/close.test.js @@ -215,7 +215,7 @@ t.test('Current opened connection should continue to work after closing and retu t.error(err) const port = fastify.server.address().port - const client = net.createConnection({ port: port }, () => { + const client = net.createConnection({ port }, () => { client.write('GET / HTTP/1.1\r\n\r\n') client.once('data', data => { diff --git a/test/context-config.test.js b/test/context-config.test.js index eda0e22f08..d60831e473 100644 --- a/test/context-config.test.js +++ b/test/context-config.test.js @@ -29,7 +29,7 @@ test('config', t => { method: 'GET', url: '/route', schema: schema.schema, - handler: handler, + handler, config: Object.assign({}, schema.config) }) @@ -37,7 +37,7 @@ test('config', t => { method: 'GET', url: '/no-config', schema: schema.schema, - handler: handler + handler }) fastify.inject({ @@ -81,7 +81,7 @@ test('config with exposeHeadRoutes', t => { method: 'GET', url: '/route', schema: schema.schema, - handler: handler, + handler, config: Object.assign({}, schema.config) }) @@ -89,7 +89,7 @@ test('config with exposeHeadRoutes', t => { method: 'GET', url: '/no-config', schema: schema.schema, - handler: handler + handler }) fastify.inject({ diff --git a/test/inject.test.js b/test/inject.test.js index b05ed4531c..34469d66b9 100644 --- a/test/inject.test.js +++ b/test/inject.test.js @@ -186,7 +186,7 @@ test('inject post request', t => { fastify.inject({ method: 'POST', url: '/', - payload: payload + payload }, (err, res) => { t.error(err) t.same(payload, JSON.parse(res.payload)) diff --git a/test/internals/all.test.js b/test/internals/all.test.js index f27c95ddde..7275648126 100644 --- a/test/internals/all.test.js +++ b/test/internals/all.test.js @@ -19,7 +19,7 @@ test('fastify.all should add all the methods to the same url', t => { function injectRequest (method) { const options = { url: '/', - method: method + method } if (method === 'POST' || method === 'PUT' || method === 'PATCH') { @@ -29,7 +29,7 @@ test('fastify.all should add all the methods to the same url', t => { fastify.inject(options, (err, res) => { t.error(err) const payload = JSON.parse(res.payload) - t.same(payload, { method: method }) + t.same(payload, { method }) }) } }) diff --git a/test/internals/contentTypeParser.test.js b/test/internals/contentTypeParser.test.js index 87e568ff42..a24f67e15f 100644 --- a/test/internals/contentTypeParser.test.js +++ b/test/internals/contentTypeParser.test.js @@ -32,8 +32,8 @@ test('rawBody function', t => { res.log = { error: () => { }, info: () => { } } const context = { - Reply: Reply, - Request: Request, + Reply, + Request, preHandler: [], onSend: [], _parserOptions: { @@ -85,8 +85,8 @@ test('Should support Webpack and faux modules', t => { res.log = { error: () => { }, info: () => { } } const context = { - Reply: Reply, - Request: Request, + Reply, + Request, preHandler: [], onSend: [], _parserOptions: { diff --git a/test/internals/handleRequest.test.js b/test/internals/handleRequest.test.js index 6ce710a109..67b1a71adf 100644 --- a/test/internals/handleRequest.test.js +++ b/test/internals/handleRequest.test.js @@ -62,8 +62,8 @@ test('handler function - invalid schema', t => { } }, handler: () => {}, - Reply: Reply, - Request: Request, + Reply, + Request, preValidation: [], preHandler: [], onSend: [], @@ -93,8 +93,8 @@ test('handler function - reply', t => { reply.code(204) reply.send(undefined) }, - Reply: Reply, - Request: Request, + Reply, + Request, preValidation: [], preHandler: [], onSend: [], @@ -123,8 +123,8 @@ test('handler function - preValidationCallback with finished response', t => { t.fail() reply.send(undefined) }, - Reply: Reply, - Request: Request, + Reply, + Request, preValidation: null, preHandler: [], onSend: [], @@ -150,8 +150,8 @@ test('handler function - preValidationCallback with finished response (< v12.9.0 t.fail() reply.send(undefined) }, - Reply: Reply, - Request: Request, + Reply, + Request, preValidation: null, preHandler: [], onSend: [], diff --git a/test/internals/logger.test.js b/test/internals/logger.test.js index 5688b97796..366ed97fc7 100644 --- a/test/internals/logger.test.js +++ b/test/internals/logger.test.js @@ -103,7 +103,7 @@ test('The logger should error if both stream and file destination are given', t Fastify({ logger: { level: 'info', - stream: stream, + stream, file: '/test' } }) diff --git a/test/logger.test.js b/test/logger.test.js index 81e675b111..8067511522 100644 --- a/test/logger.test.js +++ b/test/logger.test.js @@ -37,7 +37,7 @@ test('defaults to info level', t => { try { fastify = Fastify({ logger: { - stream: stream + stream } }) } catch (e) { @@ -85,7 +85,7 @@ test('test log stream', t => { try { fastify = Fastify({ logger: { - stream: stream, + stream, level: 'info' } }) @@ -132,7 +132,7 @@ test('test error log stream', t => { try { fastify = Fastify({ logger: { - stream: stream, + stream, level: 'info' } }) @@ -182,7 +182,7 @@ test('can use external logger instance', t => { const logger = require('pino')(splitStream) - const localFastify = Fastify({ logger: logger }) + const localFastify = Fastify({ logger }) localFastify.get('/foo', function (req, reply) { t.ok(req.log) @@ -226,7 +226,7 @@ test('can use external logger instance with custom serializer', t => { }, splitStream) const localFastify = Fastify({ - logger: logger + logger }) localFastify.get('/foo', function (req, reply) { @@ -253,7 +253,7 @@ test('expose the logger', t => { try { fastify = Fastify({ logger: { - stream: stream, + stream, level: 'info' } }) @@ -271,7 +271,7 @@ test('The request id header key can be customized', t => { const stream = split(JSON.parse) const fastify = Fastify({ - logger: { stream: stream, level: 'info' }, + logger: { stream, level: 'info' }, requestIdHeader: 'my-custom-request-id' }) t.teardown(() => fastify.close()) @@ -316,7 +316,7 @@ test('The request id header key can be customized along with a custom id generat const stream = split(JSON.parse) const fastify = Fastify({ - logger: { stream: stream, level: 'info' }, + logger: { stream, level: 'info' }, requestIdHeader: 'my-custom-request-id', genReqId (req) { return 'foo' @@ -379,7 +379,7 @@ test('The request id log label can be changed', t => { const stream = split(JSON.parse) const fastify = Fastify({ - logger: { stream: stream, level: 'info' }, + logger: { stream, level: 'info' }, requestIdHeader: 'my-custom-request-id', requestIdLogLabel: 'traceId' }) @@ -422,7 +422,7 @@ test('The logger should accept custom serializer', t => { const stream = split(JSON.parse) const fastify = Fastify({ logger: { - stream: stream, + stream, level: 'info', serializers: { req: function (req) { @@ -1151,7 +1151,7 @@ test('should serialize request and response', t => { const stream = split(JSON.parse) const fastify = Fastify({ logger: { - stream: stream, + stream, level: 'info' } }) @@ -1173,7 +1173,7 @@ test('Do not wrap IPv4 address', t => { const stream = split(JSON.parse) const fastify = Fastify({ logger: { - stream: stream, + stream, level: 'info' } }) @@ -1241,7 +1241,7 @@ test('should log the error if no error handler is defined', t => { const stream = split(JSON.parse) const fastify = Fastify({ logger: { - stream: stream, + stream, level: 'info' } }) @@ -1275,7 +1275,7 @@ test('should log as info if error status code >= 400 and < 500 if no error handl const stream = split(JSON.parse) const fastify = Fastify({ logger: { - stream: stream, + stream, level: 'info' } }) @@ -1313,7 +1313,7 @@ test('should log as error if error status code >= 500 if no error handler is def const stream = split(JSON.parse) const fastify = Fastify({ logger: { - stream: stream, + stream, level: 'info' } }) @@ -1347,7 +1347,7 @@ test('should not log the error if error handler is defined', t => { const stream = split(JSON.parse) const fastify = Fastify({ logger: { - stream: stream, + stream, level: 'info' } }) @@ -1381,7 +1381,7 @@ test('should not rely on raw request to log errors', t => { const stream = split(JSON.parse) const fastify = Fastify({ logger: { - stream: stream, + stream, level: 'info' } }) @@ -1412,7 +1412,7 @@ test('should redact the authorization header if so specified', t => { const stream = split(JSON.parse) const fastify = Fastify({ logger: { - stream: stream, + stream, redact: ['req.headers.authorization'], level: 'info', serializers: { diff --git a/test/maxRequestsPerSocket.test.js b/test/maxRequestsPerSocket.test.js index edd33e4d46..867ba0edae 100644 --- a/test/maxRequestsPerSocket.test.js +++ b/test/maxRequestsPerSocket.test.js @@ -21,7 +21,7 @@ test('maxRequestsPerSocket on node version >= 16.10.0', { skip }, t => { t.error(err) const port = fastify.server.address().port - const client = net.createConnection({ port: port }, () => { + const client = net.createConnection({ port }, () => { client.write('GET / HTTP/1.1\r\n\r\n') client.once('data', data => { @@ -61,7 +61,7 @@ test('maxRequestsPerSocket zero should behave same as null', { skip }, t => { t.error(err) const port = fastify.server.address().port - const client = net.createConnection({ port: port }, () => { + const client = net.createConnection({ port }, () => { client.write('GET / HTTP/1.1\r\n\r\n') client.once('data', data => { diff --git a/test/skip-reply-send.test.js b/test/skip-reply-send.test.js index 7e46ded52d..df78ce81c6 100644 --- a/test/skip-reply-send.test.js +++ b/test/skip-reply-send.test.js @@ -23,7 +23,7 @@ test('skip automatic reply.send() with reply.sent = true and a body', (t) => { const stream = split(JSON.parse) const app = Fastify({ logger: { - stream: stream + stream } }) @@ -52,7 +52,7 @@ test('skip automatic reply.send() with reply.sent = true and no body', (t) => { const stream = split(JSON.parse) const app = Fastify({ logger: { - stream: stream + stream } }) @@ -81,7 +81,7 @@ test('skip automatic reply.send() with reply.sent = true and an error', (t) => { const stream = split(JSON.parse) const app = Fastify({ logger: { - stream: stream + stream } }) @@ -125,7 +125,7 @@ function testHandlerOrBeforeHandlerHook (test, hookOrHandler) { const stream = split(JSON.parse) const app = Fastify({ logger: { - stream: stream + stream } }) @@ -170,7 +170,7 @@ function testHandlerOrBeforeHandlerHook (test, hookOrHandler) { const stream = split(JSON.parse) const app = Fastify({ logger: { - stream: stream + stream } }) t.teardown(() => app.close()) @@ -224,7 +224,7 @@ function testHandlerOrBeforeHandlerHook (test, hookOrHandler) { const stream = split(JSON.parse) const app = Fastify({ logger: { - stream: stream + stream } }) t.teardown(() => app.close()) @@ -274,7 +274,7 @@ function testHandlerOrBeforeHandlerHook (test, hookOrHandler) { const stream = split(JSON.parse) const app = Fastify({ logger: { - stream: stream + stream } }) diff --git a/test/trust-proxy.test.js b/test/trust-proxy.test.js index d84ad2b21e..9dc4030f86 100644 --- a/test/trust-proxy.test.js +++ b/test/trust-proxy.test.js @@ -16,7 +16,7 @@ const sgetForwardedRequest = (app, forHeader, path, protoHeader) => { } sget({ method: 'GET', - headers: headers, + headers, url: 'http://localhost:' + app.server.address().port + path }, () => {}) } diff --git a/test/types/instance.test-d.ts b/test/types/instance.test-d.ts index 7517c4d49a..11f1426def 100644 --- a/test/types/instance.test-d.ts +++ b/test/types/instance.test-d.ts @@ -54,7 +54,7 @@ function asyncNodeJSErrorHandler (error: NodeJS.ErrnoException) {} server.setErrorHandler(asyncNodeJSErrorHandler) class CustomError extends Error { - private __brand: any; + private __brand: any } interface ReplyPayload { Reply: { diff --git a/test/validation-error-handling.test.js b/test/validation-error-handling.test.js index be09789a5d..e9598034e2 100644 --- a/test/validation-error-handling.test.js +++ b/test/validation-error-handling.test.js @@ -140,7 +140,7 @@ test('error inside custom error handler should have validationContext if specifi return function (data) { const error = new Error('this failed') error.validationContext = 'customContext' - return { error: error } + return { error } } } }, function (req, reply) { diff --git a/test/versioned-routes.test.js b/test/versioned-routes.test.js index 3f92b164bb..13e30181db 100644 --- a/test/versioned-routes.test.js +++ b/test/versioned-routes.test.js @@ -433,7 +433,7 @@ test('test log stream', t => { const stream = split(JSON.parse) const fastify = Fastify({ logger: { - stream: stream, + stream, level: 'info' } }) diff --git a/types/.eslintrc.json b/types/.eslintrc.json index beec15b1ca..3677d6dd9f 100644 --- a/types/.eslintrc.json +++ b/types/.eslintrc.json @@ -31,7 +31,7 @@ "files": ["*.test-d.ts"], "rules": { "no-unused-vars": "off", - "node/handle-callback-err": "off", + "n/handle-callback-err": "off", "@typescript-eslint/no-empty-function": "off", "@typescript-eslint/explicit-function-return-type": "off", "@typescript-eslint/no-unused-vars": "off",